📄 ogr_fromepsg.cpp
字号:
poSRS->SetNode( "PROJCS", pszPCSName ); /* -------------------------------------------------------------------- *//* Set GEOGCS. *//* -------------------------------------------------------------------- */ nErr = SetEPSGGeogCS( poSRS, nGCSCode ); if( nErr != OGRERR_NONE ) return nErr; dfFromGreenwich = poSRS->GetPrimeMeridian();/* -------------------------------------------------------------------- *//* Set linear units. *//* -------------------------------------------------------------------- */ if( !EPSGGetUOMLengthInfo( nUOMLength, &pszUOMLengthName, &dfInMeters ) ) return OGRERR_UNSUPPORTED_SRS; poSRS->SetLinearUnits( pszUOMLengthName, dfInMeters ); poSRS->SetAuthority( "PROJCS|UNIT", "EPSG", nUOMLength ); CPLFree( pszUOMLengthName ); CPLFree( pszPCSName );/* -------------------------------------------------------------------- *//* Set projection and parameters. *//* -------------------------------------------------------------------- */ if( !EPSGGetProjTRFInfo( nPCSCode, &nProjMethod, anParmIds, adfProjParms )) return OGRERR_UNSUPPORTED_SRS; switch( nProjMethod ) { case 9801: case 9817: /* really LCC near conformal */ poSRS->SetLCC1SP( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ), OGR_FP( NatOriginScaleFactor ), OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) ); break; case 9802: poSRS->SetLCC( OGR_FP( StdParallel1Lat ), OGR_FP( StdParallel2Lat ), OGR_FP( FalseOriginLat ), OGR_FP( FalseOriginLong ), OGR_FP( FalseOriginEasting ), OGR_FP( FalseOriginNorthing )); break; case 9803: poSRS->SetLCCB( OGR_FP( StdParallel1Lat ), OGR_FP( StdParallel2Lat ), OGR_FP( FalseOriginLat ), OGR_FP( FalseOriginLong ), OGR_FP( FalseOriginEasting ), OGR_FP( FalseOriginNorthing )); break; case 9804: case 9805: /* NOTE: treats 1SP and 2SP cases the same */ poSRS->SetMercator( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ), OGR_FP( NatOriginScaleFactor ), OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) ); break; case 9806: poSRS->SetCS( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ), OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) ); break; case 9807: poSRS->SetTM( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ), OGR_FP( NatOriginScaleFactor ), OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) ); break; case 9808: poSRS->SetTMSO( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ), OGR_FP( NatOriginScaleFactor ), OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) ); break; case 9809: poSRS->SetOS( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ), OGR_FP( NatOriginScaleFactor ), OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) ); break; case 9810: poSRS->SetPS( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ), OGR_FP( NatOriginScaleFactor ), OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) ); break; case 9811: poSRS->SetNZMG( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ), OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) ); break; case 9812: case 9813: case 9814: poSRS->SetHOM( OGR_FP( ProjCenterLat ), OGR_FP( ProjCenterLong ), OGR_FP( Azimuth ), OGR_FP( AngleRectifiedToSkewedGrid ), OGR_FP( InitialLineScaleFactor ), OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) ); poNode = poSRS->GetAttrNode( "PROJECTION" )->GetChild( 0 ); if( nProjMethod == 9813 ) poNode->SetValue( SRS_PT_LABORDE_OBLIQUE_MERCATOR ); break; case 9815: poSRS->SetHOM( OGR_FP( ProjCenterLat ), OGR_FP( ProjCenterLong ), OGR_FP( Azimuth ), OGR_FP( AngleRectifiedToSkewedGrid ), OGR_FP( InitialLineScaleFactor ), OGR_FP( ProjCenterEasting ), OGR_FP( ProjCenterNorthing ) ); break; case 9816: poSRS->SetTMG( OGR_FP( FalseOriginLat ), OGR_FP( FalseOriginLong ), OGR_FP( FalseOriginEasting ), OGR_FP( FalseOriginNorthing ) ); break; case 9818: poSRS->SetPolyconic( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ), OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) ); break; case 9819: poSRS->SetKrovak( OGR_FP( ProjCenterLat ), OGR_FP( ProjCenterLong ), OGR_FP( Azimuth ), OGR_FP( PseudoStdParallelLat ), OGR_FP( PseudoStdParallelScaleFactor ), OGR_FP( ProjCenterEasting ), OGR_FP( ProjCenterNorthing ) ); break; case 9820: poSRS->SetLAEA( OGR_FP( NatOriginLat ), OGR_FP( NatOriginLong ), OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) ); break; case 9821: /* this is the spherical form, and really needs different equations which give different results but PROJ.4 doesn't seem to support the spherical form. */ poSRS->SetLAEA( OGR_FP( SphericalOriginLat ), OGR_FP( SphericalOriginLong ), OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) ); break; default: return OGRERR_UNSUPPORTED_SRS; }/* -------------------------------------------------------------------- *//* Set overall PCS authority code. *//* -------------------------------------------------------------------- */ poSRS->SetAuthority( "PROJCS", "EPSG", nPCSCode ); return OGRERR_NONE;}/************************************************************************//* importFromEPSG() *//************************************************************************//** * Initialize SRS based on EPSG GCS or PCS code. * * This code uses the GeoTIFF cpl_csv services to access the EPSG CSV * data. If frmts/gtiff/libgeotiff isn't linked in, linking will fail. * If EPSG tables can't be found at runtime, the method will fail. * * This method is the same as the C function OSRImportFromEPSG(). * * @param nCode a GCS or PCS code from the horizontal coordinate system table. * * @return OGRERR_NONE on success, or an error code on failure. */OGRErr OGRSpatialReference::importFromEPSG( int nCode ){ OGRErr eErr; bNormInfoSet = FALSE;/* -------------------------------------------------------------------- *//* Clear any existing definition. *//* -------------------------------------------------------------------- */ if( GetRoot() != NULL ) { delete poRoot; poRoot = NULL; }/* -------------------------------------------------------------------- *//* Verify that we can find the required filename(s). *//* -------------------------------------------------------------------- */ if( CSVScanFileByName( CSVFilename( "gcs.csv" ), "COORD_REF_SYS_CODE", "4269", CC_Integer ) == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Unable to open EPSG support file %s.\n" "Try setting the GDAL_DATA environment variable to point to the\n" "directory containing EPSG csv files.", CSVFilename( "gcs.csv" ) ); return OGRERR_FAILURE; }/* -------------------------------------------------------------------- *//* Is this a GeogCS code? this is inadequate as a criteria *//* -------------------------------------------------------------------- */ if( EPSGGetGCSInfo( nCode, NULL, NULL, NULL, NULL, NULL, NULL ) ) eErr = SetEPSGGeogCS( this, nCode ); else eErr = SetEPSGProjCS( this, nCode ); if( eErr == OGRERR_UNSUPPORTED_SRS ) { CPLError( CE_Failure, CPLE_NotSupported, "EPSG PCS/GCS code %d not found in EPSG support files. Is this a valid\nEPSG coordinate system?", nCode ); }/* -------------------------------------------------------------------- *//* Make sure any peculiarities in the ordering are fixed up. *//* -------------------------------------------------------------------- */ if( eErr == OGRERR_NONE ) eErr = FixupOrdering(); return eErr;}/************************************************************************//* OSRImportFromEPSG() *//************************************************************************/OGRErr OSRImportFromEPSG( OGRSpatialReferenceH hSRS, int nCode ){ return ((OGRSpatialReference *) hSRS)->importFromEPSG( nCode );}/************************************************************************//* SetStatePlane() *//************************************************************************//** * Set State Plane projection definition. * * This will attempt to generate a complete definition of a state plane * zone based on generating the entire SRS from the EPSG tables. If the * EPSG tables are unavailable, it will produce a stubbed LOCAL_CS definition * and return OGRERR_FAILURE. * * This method is the same as the C function OSRSetStatePlaneWithUnits(). * * @param nZone State plane zone number, in the USGS numbering scheme (as * dinstinct from the Arc/Info and Erdas numbering scheme. * * @param bNAD83 TRUE if the NAD83 zone definition should be used or FALSE * if the NAD27 zone definition should be used. * * @param pszOverrideUnitName Linear unit name to apply overriding the * legal definition for this zone. * * @param dfOverrideUnit Linear unit conversion factor to apply overriding * the legal definition for this zone. * * @return OGRERR_NONE on success, or OGRERR_FAILURE on failure, mostly likely * due to the EPSG tables not being accessable. */OGRErr OGRSpatialReference::SetStatePlane( int nZone, int bNAD83, const char *pszOverrideUnitName, double dfOverrideUnit ){ int nAdjustedId; int nPCSCode; char szID[32];/* -------------------------------------------------------------------- *//* Get the index id from stateplane.csv. *//* -------------------------------------------------------------------- */ if( bNAD83 ) nAdjustedId = nZone; else nAdjustedId = nZone + 10000;/* -------------------------------------------------------------------- *//* Turn this into a PCS code. We assume there will only be one *//* PCS corresponding to each Proj_ code since the proj code *//* already effectively indicates NAD27 or NAD83. *//* -------------------------------------------------------------------- */ sprintf( szID, "%d", nAdjustedId ); nPCSCode = atoi( CSVGetField( CSVFilename( "stateplane.csv" ), "ID", szID, CC_Integer, "EPSG_PCS_CODE" ) ); if( nPCSCode < 1 ) { char szName[128]; static int bFailureReported = FALSE; if( !bFailureReported ) { bFailureReported = TRUE; CPLError( CE_Warning, CPLE_OpenFailed, "Unable to find state plane zone in stateplane.csv,\n" "likely because the GDAL data files cannot be found. Using\n" "incomplete definition of state plane zone.\n" ); } Clear(); if( bNAD83 ) { sprintf( szName, "State Plane Zone %d / NAD83", nZone ); SetLocalCS( szName ); SetLinearUnits( SRS_UL_METER, 1.0 ); } else { sprintf( szName, "State Plane Zone %d / NAD27", nZone ); SetLocalCS( szName ); SetLinearUnits( SRS_UL_US_FOOT, atof(SRS_UL_US_FOOT_CONV) ); } return OGRERR_FAILURE; }/* -------------------------------------------------------------------- *//* Define based on a full EPSG definition of the zone. *//* -------------------------------------------------------------------- */ OGRErr eErr = importFromEPSG( nPCSCode ); if( eErr != OGRERR_NONE ) return eErr;/* -------------------------------------------------------------------- *//* Apply units override if required. *//* *//* We will need to adjust the linear projection parameter to *//* match the provided units, and clear the authority code. *//* -------------------------------------------------------------------- */ if( dfOverrideUnit != 0.0 && fabs(dfOverrideUnit - GetLinearUnits()) > 0.0000000001 ) { double dfFalseEasting = GetNormProjParm( SRS_PP_FALSE_EASTING ); double dfFalseNorthing= GetNormProjParm( SRS_PP_FALSE_NORTHING); OGR_SRSNode *poPROJCS; SetLinearUnits( pszOverrideUnitName, dfOverrideUnit ); SetNormProjParm( SRS_PP_FALSE_EASTING, dfFalseEasting ); SetNormProjParm( SRS_PP_FALSE_NORTHING, dfFalseNorthing ); poPROJCS = GetAttrNode( "PROJCS" ); if( poPROJCS != NULL && poPROJCS->FindChild( "AUTHORITY" ) != -1 ) { poPROJCS->DestroyChild( poPROJCS->FindChild( "AUTHORITY" ) ); } } return OGRERR_NONE;}/************************************************************************//* OSRSetStatePlane() *//************************************************************************/OGRErr OSRSetStatePlane( OGRSpatialReferenceH hSRS, int nZone, int bNAD83 ){ return ((OGRSpatialReference *) hSRS)->SetStatePlane( nZone, bNAD83 );}/************************************************************************//* OSRSetStatePlaneWithUnits() *//************************************************************************/OGRErr OSRSetStatePlaneWithUnits( OGRSpatialReferenceH hSRS, int nZone, int bNAD83, const char *pszOverrideUnitName, double dfOverrideUnit ){ return ((OGRSpatialReference *) hSRS)->SetStatePlane( nZone, bNAD83, pszOverrideUnitName, dfOverrideUnit );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -