ogr_fromepsg.cpp

来自「用于读取TAB、MIF、SHP文件的类」· C++ 代码 · 共 1,725 行 · 第 1/5 页

CPP
1,725
字号
      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;      case 9822: /* Albers (Conic) Equal Area */        poSRS->SetACEA( OGR_FP( StdParallel1Lat ),                         OGR_FP( StdParallel2Lat ),                         OGR_FP( FalseOriginLat ),                        OGR_FP( FalseOriginLong ),                        OGR_FP( FalseOriginEasting ),                        OGR_FP( FalseOriginNorthing ) );        break;      case 9823: /* Equidistant Cylindrical / Plate Carre / Equirectangular */        poSRS->SetEquirectangular( OGR_FP( NatOriginLat ),                                   OGR_FP( NatOriginLong ),                                    0.0, 0.0 );        break;      case 9829: /* Polar Stereographic (Variant B) */          poSRS->SetPS( OGR_FP( PolarLatStdParallel ), OGR_FP(PolarLongOrigin),                        1.0,                        OGR_FP( FalseEasting ), OGR_FP( FalseNorthing ) );          break;      default:        CPLDebug( "EPSG", "No WKT support for projection method %d.",                  nProjMethod );        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 we get it as an unsupported code, try looking it up in       *//*      the epsg.wkt coordinate system dictionary.                      *//* -------------------------------------------------------------------- */    if( eErr == OGRERR_UNSUPPORTED_SRS )    {        char szCode[32];        sprintf( szCode, "%d", nCode );        eErr = importFromDict( "epsg.wkt", szCode );    }/* -------------------------------------------------------------------- *//*      If we get it as an unsupported code, try looking it up in       *//*      the PROJ.4 support file(s).                                     *//* -------------------------------------------------------------------- */    static int bLoopingToProj4 = FALSE;    if( eErr == OGRERR_UNSUPPORTED_SRS && !bLoopingToProj4 )    {        char szWrkDefn[100];        sprintf( szWrkDefn, "+init=epsg:%d", nCode );        bLoopingToProj4 = TRUE;        CPLPushErrorHandler( CPLQuietErrorHandler );        eErr = SetFromUserInput( szWrkDefn );        CPLPopErrorHandler();        bLoopingToProj4 = FALSE;        if( eErr != OGRERR_NONE )            eErr = OGRERR_UNSUPPORTED_SRS;        else        {            if( IsProjected() )                SetAuthority( "PROJCS", "EPSG", nCode );            else if( IsGeographic() )                SetAuthority( "GEOGCS", "EPSG", 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 CPL_STDCALL 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 );}/************************************************************************//*                          AutoIdentifyEPSG()                          *//************************************************************************//** * Set EPSG authority info if possible. * * This method inspects a WKT definition, and adds EPSG authority nodes * where an aspect of the coordinate system can be easily and safely  * corresponded with an EPSG identifier.  In practice, this method will  * evolve over time.  In theory it can add authority nodes for any object * 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?