Index: gcore/gdaljp2metadata.cpp =================================================================== --- gcore/gdaljp2metadata.cpp (révision 23302) +++ gcore/gdaljp2metadata.cpp (copie de travail) @@ -731,12 +731,10 @@ && strstr(pszSRSName,":def:") != NULL && oSRS.importFromURN(pszSRSName) == OGRERR_NONE ) { - const char *pszCode = strrchr(pszSRSName,':') + 1; - oSRS.exportToWkt( &pszProjection ); // Per #2131 - if( atoi(pszCode) >= 4000 && atoi(pszCode) <= 4999 ) + if( oSRS.EPSGTreatsAsLatLong() || oSRS.EPSGTreatsAsNorthingEasting() ) { CPLDebug( "GMLJP2", "Request axis flip for SRS=%s", pszSRSName ); Index: ogr/ogr_srs_api.h =================================================================== --- ogr/ogr_srs_api.h (révision 23302) +++ ogr/ogr_srs_api.h (copie de travail) @@ -407,6 +407,7 @@ OGRErr CPL_DLL OSRAutoIdentifyEPSG( OGRSpatialReferenceH hSRS ); int CPL_DLL OSREPSGTreatsAsLatLong( OGRSpatialReferenceH hSRS ); +int CPL_DLL OSREPSGTreatsAsNorthingEasting( OGRSpatialReferenceH hSRS ); const char CPL_DLL *OSRGetAxis( OGRSpatialReferenceH hSRS, const char *pszTargetKey, int iAxis, OGRAxisOrientation *peOrientation ); Index: ogr/ogr_spatialref.h =================================================================== --- ogr/ogr_spatialref.h (révision 23302) +++ ogr/ogr_spatialref.h (copie de travail) @@ -207,6 +207,7 @@ OGRErr Fixup(); int EPSGTreatsAsLatLong(); + int EPSGTreatsAsNorthingEasting(); const char *GetAxis( const char *pszTargetKey, int iAxis, OGRAxisOrientation *peOrientation ) const; OGRErr SetAxes( const char *pszTargetKey, Index: ogr/ogr_fromepsg.cpp =================================================================== --- ogr/ogr_fromepsg.cpp (révision 23302) +++ ogr/ogr_fromepsg.cpp (copie de travail) @@ -2074,7 +2074,9 @@ * This method is similar to importFromEPSGA() except that EPSG preferred * axis ordering will *not* be applied for geographic coordinate systems. * EPSG normally defines geographic coordinate systems to use lat/long - * contrary to typical GIS use). + * contrary to typical GIS use). Since OGR 1.9.0, EPSG preferred + * axis ordering will also *not* be applied for projected coordinate systems + * that use northing/easting order. * * This method is the same as the C function OSRImportFromEPSG(). * @@ -2095,6 +2097,10 @@ if( poGEOGCS != NULL ) poGEOGCS->StripNodes( "AXIS" ); + + OGR_SRSNode *poPROJCS = GetAttrNode( "PROJCS" ); + if (poPROJCS != NULL && EPSGTreatsAsNorthingEasting()) + poPROJCS->StripNodes( "AXIS" ); } return eErr; @@ -2129,9 +2135,10 @@ * passed in EPSG GCS or PCS code. * * This method is similar to importFromEPSG() except that EPSG preferred - * axis ordering *will* be applied for geographic coordinate systems. - * EPSG normally defines geographic coordinate systems to use lat/long - * contrary to typical GIS use). See OGRSpatialReference::importFromEPSG() + * axis ordering *will* be applied for geographic and projected coordinate systems. + * EPSG normally defines geographic coordinate systems to use lat/long, and + * also there are also a few projected coordinate systems that use northing/easting + * order contrary to typical GIS use). See OGRSpatialReference::importFromEPSG() * for more details on operation of this method. * * This method is the same as the C function OSRImportFromEPSGA(). @@ -2690,3 +2697,68 @@ return ((OGRSpatialReference *) hSRS)->EPSGTreatsAsLatLong(); } +/************************************************************************/ +/* EPSGTreatsAsNorthingEasting() */ +/************************************************************************/ + +/** + * \brief This method returns TRUE if EPSG feels this projected coordinate + * system should be treated as having northing/easting coordinate ordering. + * + * Currently this returns TRUE for all projected coordinate systems + * with an EPSG code set, and AXIS values set defining it as northing, easting. + * + * FALSE will be returned for all coordinate systems that are not projected, + * or that do not have an EPSG code set. + * + * This method is the same as the C function EPSGTreatsAsNorthingEasting(). + * + * @return TRUE or FALSE. + * + * @since GDAL 1.9.0 + */ + +int OGRSpatialReference::EPSGTreatsAsNorthingEasting() + +{ + if( !IsProjected() ) + return FALSE; + + const char *pszAuth = GetAuthorityName( "PROJCS" ); + + if( pszAuth == NULL || !EQUAL(pszAuth,"EPSG") ) + return FALSE; + + OGR_SRSNode *poFirstAxis = GetAttrNode( "PROJCS|AXIS" ); + + if( poFirstAxis == NULL ) + return FALSE; + + if( poFirstAxis->GetChildCount() >= 2 + && EQUAL(poFirstAxis->GetChild(1)->GetValue(),"NORTH") ) + return TRUE; + + return FALSE; +} + +/************************************************************************/ +/* OSREPSGTreatsAsNorthingEasting() */ +/************************************************************************/ + +/** + * \brief This function returns TRUE if EPSG feels this geographic coordinate + * system should be treated as having northing/easting coordinate ordering. + * + * This function is the same as OGRSpatialReference::EPSGTreatsAsNorthingEasting(). + * + * @since GDAL 1.9.0 + */ + +int OSREPSGTreatsAsNorthingEasting( OGRSpatialReferenceH hSRS ) + +{ + VALIDATE_POINTER1( hSRS, "OSREPSGTreatsAsNorthingEasting", CE_Failure ); + + return ((OGRSpatialReference *) hSRS)->EPSGTreatsAsNorthingEasting(); +} + Index: ogr/ogr2gmlgeometry.cpp =================================================================== --- ogr/ogr2gmlgeometry.cpp (révision 23302) +++ ogr/ogr2gmlgeometry.cpp (copie de travail) @@ -595,12 +595,13 @@ pszAuthCode = poSRS->GetAuthorityCode( pszTarget ); if( NULL != pszAuthCode && strlen(pszAuthCode) < 10 ) { - if (bLongSRS && !((OGRSpatialReference*)poSRS)->EPSGTreatsAsLatLong()) + if (bLongSRS && !(((OGRSpatialReference*)poSRS)->EPSGTreatsAsLatLong() || + ((OGRSpatialReference*)poSRS)->EPSGTreatsAsNorthingEasting())) { OGRSpatialReference oSRS; if (oSRS.importFromEPSGA(atoi(pszAuthCode)) == OGRERR_NONE) { - if (oSRS.EPSGTreatsAsLatLong()) + if (oSRS.EPSGTreatsAsLatLong() || oSRS.EPSGTreatsAsNorthingEasting()) bCoordSwap = TRUE; } } Index: ogr/ogrsf_frmts/gml/gmlutils.cpp =================================================================== --- ogr/ogrsf_frmts/gml/gmlutils.cpp (révision 23302) +++ ogr/ogrsf_frmts/gml/gmlutils.cpp (copie de travail) @@ -94,7 +94,7 @@ OGRSpatialReference oSRS; if (oSRS.importFromURN(pszSRSName) == OGRERR_NONE) { - if (oSRS.EPSGTreatsAsLatLong()) + if (oSRS.EPSGTreatsAsLatLong() || oSRS.EPSGTreatsAsNorthingEasting()) return TRUE; } } @@ -270,12 +270,13 @@ pszAuthCode = poSRS->GetAuthorityCode( pszTarget ); if( NULL != pszAuthCode && strlen(pszAuthCode) < 10 ) { - if (bLongSRS && !((OGRSpatialReference*)poSRS)->EPSGTreatsAsLatLong()) + if (bLongSRS && !(((OGRSpatialReference*)poSRS)->EPSGTreatsAsLatLong() || + ((OGRSpatialReference*)poSRS)->EPSGTreatsAsNorthingEasting())) { OGRSpatialReference oSRS; if (oSRS.importFromEPSGA(atoi(pszAuthCode)) == OGRERR_NONE) { - if (oSRS.EPSGTreatsAsLatLong()) + if (oSRS.EPSGTreatsAsLatLong() || oSRS.EPSGTreatsAsNorthingEasting()) *pbCoordSwap = TRUE; } } Index: ogr/ogrsf_frmts/gml/gmlreader.cpp =================================================================== --- ogr/ogrsf_frmts/gml/gmlreader.cpp (révision 23302) +++ ogr/ogrsf_frmts/gml/gmlreader.cpp (copie de travail) @@ -1352,23 +1352,25 @@ { OGR_SRSNode *poGEOGCS = oSRS.GetAttrNode( "GEOGCS" ); if( poGEOGCS != NULL ) - { poGEOGCS->StripNodes( "AXIS" ); - char* pszWKT = NULL; - if (oSRS.exportToWkt(&pszWKT) == OGRERR_NONE) - poClass->SetSRSName(pszWKT); - CPLFree(pszWKT); + OGR_SRSNode *poPROJCS = oSRS.GetAttrNode( "PROJCS" ); + if (poPROJCS != NULL && oSRS.EPSGTreatsAsNorthingEasting()) + poPROJCS->StripNodes( "AXIS" ); - /* So when we have computed the extent, we didn't know yet */ - /* the SRS to use. Now we know it, we have to fix the extent */ - /* order */ - if (m_bCanUseGlobalSRSName) - { - double dfXMin, dfXMax, dfYMin, dfYMax; - if( poClass->GetExtents(&dfXMin, &dfXMax, &dfYMin, &dfYMax) ) - poClass->SetExtents( dfYMin, dfYMax, dfXMin, dfXMax ); - } + char* pszWKT = NULL; + if (oSRS.exportToWkt(&pszWKT) == OGRERR_NONE) + poClass->SetSRSName(pszWKT); + CPLFree(pszWKT); + + /* So when we have computed the extent, we didn't know yet */ + /* the SRS to use. Now we know it, we have to fix the extent */ + /* order */ + if (m_bCanUseGlobalSRSName) + { + double dfXMin, dfXMax, dfYMin, dfYMax; + if( poClass->GetExtents(&dfXMin, &dfXMax, &dfYMin, &dfYMax) ) + poClass->SetExtents( dfYMin, dfYMax, dfXMin, dfXMax ); } } } Index: ogr/ogrsf_frmts/gml/drv_gml.html =================================================================== --- ogr/ogrsf_frmts/gml/drv_gml.html (révision 23302) +++ ogr/ogrsf_frmts/gml/drv_gml.html (copie de travail) @@ -54,6 +54,8 @@ not consider the EPSG axis order and will report the coordinates in (latitude,longitude) order. However, if you set the configuration option GML_CONSIDER_EPSG_AS_URN to YES, the rules explained in the previous paragraph will be applied.
+Since OGR 1.9.0, the above also applied for projected coordinate systems whose EPSG +preferred axis order is (northing, easting).