MCPcopy Create free account
hub / github.com/OSGeo/gdal / GetEPSGGeogCS

Method GetEPSGGeogCS

ogr/ogrspatialreference.cpp:13270–13409  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13268 */
13269
13270int 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");

Callers 3

TEST_FFunction · 0.80
WriteProjectionMethod · 0.80
WritePeStringIfNeededFunction · 0.80

Calls 10

GetPrimeMeridianFunction · 0.85
demoteFromBoundCRSMethod · 0.80
getPROJContextMethod · 0.80
CopyGeogCSFromMethod · 0.80
GetAttrValueMethod · 0.80
GetAuthorityNameMethod · 0.80
GetAuthorityCodeMethod · 0.80
EQUALFunction · 0.50
IsEmptyMethod · 0.45

Tested by 1

TEST_FFunction · 0.64