| 13268 | */ |
| 13269 | |
| 13270 | int OGRSpatialReference::GetEPSGGeogCS() const |
| 13271 | |
| 13272 | { |
| 13273 | TAKE_OPTIONAL_LOCK(); |
| 13274 | |
| 13275 | /* -------------------------------------------------------------------- */ |
| 13276 | /* Check axis order. */ |
| 13277 | /* -------------------------------------------------------------------- */ |
| 13278 | auto poGeogCRS = std::unique_ptr<OGRSpatialReference>(CloneGeogCS()); |
| 13279 | if (!poGeogCRS) |
| 13280 | return -1; |
| 13281 | |
| 13282 | bool ret = false; |
| 13283 | poGeogCRS->d->demoteFromBoundCRS(); |
| 13284 | auto cs = proj_crs_get_coordinate_system(d->getPROJContext(), |
| 13285 | poGeogCRS->d->m_pj_crs); |
| 13286 | poGeogCRS->d->undoDemoteFromBoundCRS(); |
| 13287 | if (cs) |
| 13288 | { |
| 13289 | const char *pszDirection = nullptr; |
| 13290 | if (proj_cs_get_axis_info(d->getPROJContext(), cs, 0, nullptr, nullptr, |
| 13291 | &pszDirection, nullptr, nullptr, nullptr, |
| 13292 | nullptr)) |
| 13293 | { |
| 13294 | if (EQUAL(pszDirection, "north")) |
| 13295 | { |
| 13296 | ret = true; |
| 13297 | } |
| 13298 | } |
| 13299 | |
| 13300 | proj_destroy(cs); |
| 13301 | } |
| 13302 | if (!ret) |
| 13303 | return -1; |
| 13304 | |
| 13305 | /* -------------------------------------------------------------------- */ |
| 13306 | /* Do we already have it? */ |
| 13307 | /* -------------------------------------------------------------------- */ |
| 13308 | const char *pszAuthName = GetAuthorityName("GEOGCS"); |
| 13309 | if (pszAuthName != nullptr && EQUAL(pszAuthName, "epsg")) |
| 13310 | return atoi(GetAuthorityCode("GEOGCS")); |
| 13311 | |
| 13312 | /* -------------------------------------------------------------------- */ |
| 13313 | /* Get the datum and geogcs names. */ |
| 13314 | /* -------------------------------------------------------------------- */ |
| 13315 | |
| 13316 | const char *pszGEOGCS = GetAttrValue("GEOGCS"); |
| 13317 | const char *pszDatum = GetAttrValue("DATUM"); |
| 13318 | |
| 13319 | // We can only operate on coordinate systems with a geogcs. |
| 13320 | OGRSpatialReference oSRSTmp; |
| 13321 | if (pszGEOGCS == nullptr || pszDatum == nullptr) |
| 13322 | { |
| 13323 | // Calling GetAttrValue("GEOGCS") will fail on a CRS that can't be |
| 13324 | // export to WKT1, so try to extract the geographic CRS through PROJ |
| 13325 | // API with CopyGeogCSFrom() and get the nodes' values from it. |
| 13326 | oSRSTmp.CopyGeogCSFrom(this); |
| 13327 | pszGEOGCS = oSRSTmp.GetAttrValue("GEOGCS"); |