⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogrspatialreference.cpp

📁 在linux环境下
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    if( GetAttrNode( "GEOGCS" ) != NULL )    {        OGR_SRSNode *poPROJCS;        if( EQUAL(GetRoot()->GetValue(),"GEOGCS") )            Clear();        else if( (poPROJCS = GetAttrNode( "PROJCS" )) != NULL                 && poPROJCS->FindChild( "GEOGCS" ) != -1 )            poPROJCS->DestroyChild( poPROJCS->FindChild( "GEOGCS" ) );        else            return OGRERR_FAILURE;    }/* -------------------------------------------------------------------- *//*      Set defaults for various parameters.                            *//* -------------------------------------------------------------------- */    if( pszGeogName == NULL )        pszGeogName = "unnamed";    if( pszPMName == NULL )        pszPMName = SRS_PM_GREENWICH;    if( pszDatumName == NULL )        pszDatumName = "unknown";    if( pszSpheroidName == NULL )        pszSpheroidName = "unnamed";    if( pszAngularUnits == NULL )    {        pszAngularUnits = SRS_UA_DEGREE;        dfConvertToRadians = atof(SRS_UA_DEGREE_CONV);    }/* -------------------------------------------------------------------- *//*      Build the GEOGCS object.                                        *//* -------------------------------------------------------------------- */    char                szValue[128];    OGR_SRSNode         *poGeogCS, *poSpheroid, *poDatum, *poPM, *poUnits;    poGeogCS = new OGR_SRSNode( "GEOGCS" );    poGeogCS->AddChild( new OGR_SRSNode( pszGeogName ) );    /* -------------------------------------------------------------------- *//*      Setup the spheroid.                                             *//* -------------------------------------------------------------------- */    poSpheroid = new OGR_SRSNode( "SPHEROID" );    poSpheroid->AddChild( new OGR_SRSNode( pszSpheroidName ) );    OGRPrintDouble( szValue, dfSemiMajor );    poSpheroid->AddChild( new OGR_SRSNode(szValue) );    OGRPrintDouble( szValue, dfInvFlattening );    poSpheroid->AddChild( new OGR_SRSNode(szValue) );/* -------------------------------------------------------------------- *//*      Setup the Datum.                                                *//* -------------------------------------------------------------------- */    poDatum = new OGR_SRSNode( "DATUM" );    poDatum->AddChild( new OGR_SRSNode(pszDatumName) );    poDatum->AddChild( poSpheroid );/* -------------------------------------------------------------------- *//*      Setup the prime meridian.                                       *//* -------------------------------------------------------------------- */    if( dfPMOffset == 0.0 )        strcpy( szValue, "0" );    else        OGRPrintDouble( szValue, dfPMOffset );        poPM = new OGR_SRSNode( "PRIMEM" );    poPM->AddChild( new OGR_SRSNode( pszPMName ) );    poPM->AddChild( new OGR_SRSNode( szValue ) );/* -------------------------------------------------------------------- *//*      Setup the rotational units.                                     *//* -------------------------------------------------------------------- */    OGRPrintDouble( szValue, dfConvertToRadians );        poUnits = new OGR_SRSNode( "UNIT" );    poUnits->AddChild( new OGR_SRSNode(pszAngularUnits) );    poUnits->AddChild( new OGR_SRSNode(szValue) );    /* -------------------------------------------------------------------- *//*      Complete the GeogCS                                             *//* -------------------------------------------------------------------- */    poGeogCS->AddChild( poDatum );    poGeogCS->AddChild( poPM );    poGeogCS->AddChild( poUnits );/* -------------------------------------------------------------------- *//*      Attach below the PROJCS if there is one, or make this the root. *//* -------------------------------------------------------------------- */    if( GetRoot() != NULL && EQUAL(GetRoot()->GetValue(),"PROJCS") )        poRoot->InsertChild( poGeogCS, 1 );    else        SetRoot( poGeogCS );    return OGRERR_NONE;}/************************************************************************//*                            OSRSetGeogCS()                            *//************************************************************************/OGRErr OSRSetGeogCS( OGRSpatialReferenceH hSRS,                     const char * pszGeogName,                     const char * pszDatumName,                     const char * pszSpheroidName,                     double dfSemiMajor, double dfInvFlattening,                     const char * pszPMName, double dfPMOffset,                     const char * pszAngularUnits,                     double dfConvertToRadians ){    return ((OGRSpatialReference *) hSRS)->SetGeogCS(         pszGeogName, pszDatumName,         pszSpheroidName, dfSemiMajor, dfInvFlattening,         pszPMName, dfPMOffset, pszAngularUnits, dfConvertToRadians );                                                      }/************************************************************************//*                         SetWellKnownGeogCS()                         *//************************************************************************//** * Set a GeogCS based on well known name. * * This may be called on an empty OGRSpatialReference to make a geographic * coordinate system, or on something with an existing PROJCS node to  * set the underlying geographic coordinate system of a projected coordinate * system.  * * The following well known text values are currently supported: * <ul> * <li> "WGS84": same as "EPSG:4326" but has no dependence on EPSG data files. * <li> "WGS72": same as "EPSG:4322" but has no dependence on EPSG data files. * <li> "NAD27": same as "EPSG:4267" but has no dependence on EPSG data files. * <li> "NAD83": same as "EPSG:4269" but has no dependence on EPSG data files. * <li> "EPSG:n": same as doing an ImportFromEPSG(n). * </ul> *  * @param pszName name of well known geographic coordinate system. * @return OGRERR_NONE on success, or OGRERR_FAILURE if the name isn't * recognised, the target object is already initialized, or an EPSG value * can't be successfully looked up. */ OGRErr OGRSpatialReference::SetWellKnownGeogCS( const char * pszName ){    OGRSpatialReference   oSRS2;    OGRErr eErr;/* -------------------------------------------------------------------- *//*      Check for EPSG authority numbers.                               *//* -------------------------------------------------------------------- */    if( EQUALN(pszName, "EPSG:",5) )    {        eErr = oSRS2.importFromEPSG( atoi(pszName+5) );        if( eErr != OGRERR_NONE )            return eErr;        if( !oSRS2.IsGeographic() )            return OGRERR_FAILURE;        return CopyGeogCSFrom( &oSRS2 );    }/* -------------------------------------------------------------------- *//*      Check for simple names.                                         *//* -------------------------------------------------------------------- */    char         *pszWKT = NULL;    if( EQUAL(pszName, "WGS84") )        pszWKT = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]";    else if( EQUAL(pszName, "WGS72") )        pszWKT = "GEOGCS[\"WGS 72\",DATUM[\"WGS_1972\",SPHEROID[\"WGS 72\",6378135,298.26,AUTHORITY[\"EPSG\",\"7043\"]],TOWGS84[0,0,4.5,0,0,0.554,0.2263],AUTHORITY[\"EPSG\",\"6322\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",\"4322\"]]";    else if( EQUAL(pszName, "NAD27") )        pszWKT = "GEOGCS[\"NAD27\",DATUM[\"North_American_Datum_1927\",SPHEROID[\"Clarke 1866\",6378206.4,294.978698213898,AUTHORITY[\"EPSG\",\"7008\"]],TOWGS84[-3,142,183,0,0,0,0],AUTHORITY[\"EPSG\",\"6267\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",\"4267\"]]";            else if( EQUAL(pszName, "NAD83") )        pszWKT = "GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6269\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",\"4269\"]]";    else        return OGRERR_FAILURE;/* -------------------------------------------------------------------- *//*      Import the WKT                                                  *//* -------------------------------------------------------------------- */    eErr = oSRS2.importFromWkt( &pszWKT );    if( eErr != OGRERR_NONE )        return eErr;/* -------------------------------------------------------------------- *//*      Copy over.                                                      *//* -------------------------------------------------------------------- */    return CopyGeogCSFrom( &oSRS2 );}/************************************************************************//*                       OSRSetWellKnownGeogCS()                        *//************************************************************************/OGRErr OSRSetWellKnownGeogCS( OGRSpatialReferenceH hSRS, const char *pszName ){    return ((OGRSpatialReference *) hSRS)->SetWellKnownGeogCS( pszName );}/************************************************************************//*                           CopyGeogCSFrom()                           *//************************************************************************//** * Copy GEOGCS from another OGRSpatialReference. * * The GEOGCS information is copied into this OGRSpatialReference from another. * If this object has a PROJCS root already, the GEOGCS is installed within * it, otherwise it is installed as the root. *  * @param poSrcSRS the spatial reference to copy the GEOGCS information from. *  * @return OGRERR_NONE on success or an error code. */OGRErr OGRSpatialReference::CopyGeogCSFrom(     const OGRSpatialReference * poSrcSRS ){    const OGR_SRSNode  *poGeogCS = NULL;    bNormInfoSet = FALSE;/* -------------------------------------------------------------------- *//*      Do we already have a GEOGCS?  If so, blow it away so it can     *//*      be properly replaced.                                           *//* -------------------------------------------------------------------- */    if( GetAttrNode( "GEOGCS" ) != NULL )    {        OGR_SRSNode *poPROJCS;        if( EQUAL(GetRoot()->GetValue(),"GEOGCS") )            Clear();        else if( (poPROJCS = GetAttrNode( "PROJCS" )) != NULL                 && poPROJCS->FindChild( "GEOGCS" ) != -1 )            poPROJCS->DestroyChild( poPROJCS->FindChild( "GEOGCS" ) );        else            return OGRERR_FAILURE;    }/* -------------------------------------------------------------------- *//*      Find the GEOGCS node on the source.                             *//* -------------------------------------------------------------------- */    poGeogCS = poSrcSRS->GetAttrNode( "GEOGCS" );    if( poGeogCS == NULL )        return OGRERR_FAILURE;/* -------------------------------------------------------------------- *//*      Attach below the PROJCS if there is one, or make this the root. *//* -------------------------------------------------------------------- */    if( GetRoot() != NULL && EQUAL(GetRoot()->GetValue(),"PROJCS") )        poRoot->InsertChild( poGeogCS->Clone(), 1 );    else        SetRoot( poGeogCS->Clone() );    return OGRERR_NONE;}/************************************************************************//*                         OSRCopyGeogCSFrom()                          *//************************************************************************/OGRErr OSRCopyGeogCSFrom( OGRSpatialReferenceH hSRS,                           OGRSpatialReferenceH hSrcSRS ){    return ((OGRSpatialReference *) hSRS)->CopyGeogCSFrom(         (const OGRSpatialReference *) hSrcSRS );}/************************************************************************//*                          SetFromUserInput()                          *//************************************************************************//** * Set spatial reference from various text formats. * * This method will examine the provided input, and try to deduce the * format, and then use it to initialize the spatial reference system.  It * may take the following forms: * * <ol> * <li> Well Known Text definition - passed on to importFromWkt(). * <li> "EPSG:n" - number passed on to importFromEPSG().  * <li> PROJ.4 definitions - passed on to importFromProj4(). * <li> filename - file read for WKT, XML or PROJ.4 definition. * <li> well known name accepted by SetWellKnownGeogCS(), such as NAD27, NAD83, * WGS84 or WGS72.  * </ol> * * It is expected that this method will be extended in the future to support * XML and perhaps a simplified "minilanguage" for indicating common UTM and * State Plane definitions.  * * This method is intended to be flexible, but by it's nature it is  * imprecise as it must guess information about the format intended.  When * possible applications should call the specific method appropriate if the * input is known to be in a particular format.  * * This method does the same thing as the OSRSetFromUserInput() function. *  * @param pszDefinition text definition to try to deduce SRS from. * * @return OGRERR_NONE on success, or an error code if the name isn't * recognised, the definition is corrupt, or an EPSG value can't be  * successfully looked up. */ OGRErr OGRSpatialReference::SetFromUserInput( const char * pszDefinition ){    int     bESRI = FALSE;    OGRErr  err;    if( EQUALN(pszDefinition,"ESRI::",6) )    {        bESRI = TRUE;        pszDefinition += 6;    }/* -------------------------------------------------------------------- *//*      Is it a recognised syntax?                                      *//* -------------------------------------------------------------------- */    if( EQUALN(pszDefinition,"PROJCS",6)        || EQUALN(pszDefinition,"GEOGCS",6)        || EQUALN(pszDefinition,"LOCAL_CS",8) )    {        err = importFromWkt( (char **) &pszDefinition );        if( err == OGRERR_NONE && bESRI )            err = morphFromESRI();        return err;    }    if( EQUALN(pszDefinition,"EPSG:",5) )    {        return importFromEPSG( atoi(pszDefinition+5) );    }    if( EQUAL(pszDefinition,"NAD27")         || EQUAL(pszDefinition,"NAD83")         || EQUAL(pszDefinition,"WGS84")         || EQUAL(pszDefinition,"WGS72") )    {        Clear();        return SetWellKnownGeogCS( pszDefinition );    }    if( strstr(pszDefinition,"+proj") != NULL              || strstr(pszDefinition,"+init") != NULL )        return importFromProj4( pszDefinition );/* -------------------------------------------------------------------- *//*      Try to open it as a file.                                       *//* -------------------------------------------------------------------- */    FILE        *fp;    int         nBufMax = 100000;    char        *pszBufPtr, *pszBuffer;    int         nBytes;    fp = VSIFOpen( pszDefinition, "rt" );    if( fp == NULL )        return OGRERR_CORRUPT_DATA;    pszBuffer = (char *) CPLMalloc(nBufMax);    nBytes = VSIFRead( pszBuffer, 1, nBufMax-1, fp );    VSIFClose( fp );    if( nBytes == nBufMax-1 )    {

⌨️ 快捷键说明

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