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

📄 ogr_srs_xml.cpp

📁 在linux环境下
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************** * $Id: ogr_srs_xml.cpp,v 1.5 2003/05/21 04:49:17 warmerda Exp $ * * Project:  OpenGIS Simple Features Reference Implementation * Purpose:  OGRSpatialReference interface to OGC XML (014r4). * Author:   Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 2001, Frank Warmerdam (warmerdam@pobox.com) * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************** * * $Log: ogr_srs_xml.cpp,v $ * Revision 1.5  2003/05/21 04:49:17  warmerda * avoid warnings * * Revision 1.4  2003/03/28 17:43:52  warmerda * rewrote to use new URN and projections proposal * * Revision 1.3  2003/03/21 22:14:43  warmerda * first pass re-implementation using GML 3 schemas * * Revision 1.2  2002/04/18 14:22:45  warmerda * made OGRSpatialReference and co 'const correct' * * Revision 1.1  2001/12/06 18:16:17  warmerda * new * */#include "ogr_spatialref.h"#include "ogr_p.h"#include "cpl_minixml.h"/************************************************************************//*                               addURN()                               *//************************************************************************/static void addURN( CPLXMLNode *psTarget,                     const char *pszType,                     int nCode ){    char szURN[128];    sprintf( szURN, "urn:EPSG::%s:%d", pszType, nCode );        CPLCreateXMLNode(        CPLCreateXMLNode( psTarget, CXT_Attribute, "xlink:href" ),        CXT_Text, szURN );}/************************************************************************//*                              addGMLId()                              *//************************************************************************/static void addGMLId( CPLXMLNode *psParent ){    CPLXMLNode *psId;    static int nNextGMLId = 1;    char   szIdText[40];    sprintf( szIdText, "ogrcrs%d", nNextGMLId++ );        psId =         CPLCreateXMLNode(             CPLCreateXMLNode( psParent, CXT_Attribute, "gml:id" ),            CXT_Text, szIdText );}/************************************************************************//*                               addID()                                *//************************************************************************/static CPLXMLNode *addID( CPLXMLNode *psParent,                           const char *pszTagName,                          const char *pszCode,                           const char *pszCodeSpace,                           const char *pszEdition = NULL ){    CPLXMLNode *psIdentifier;    if( !EQUALN(pszTagName,"gml:",4) )    {        char *pszQTagName;        pszQTagName = (char *) CPLMalloc(strlen(pszTagName)+10);        sprintf( pszQTagName, "gml:%s", pszTagName );        psIdentifier = CPLCreateXMLNode( psParent, CXT_Element, pszQTagName );        CPLFree( pszQTagName );    }    else        psIdentifier = CPLCreateXMLNode( psParent, CXT_Element, pszTagName );    CPLCreateXMLElementAndValue( psIdentifier, "gml:code", pszCode );    CPLCreateXMLElementAndValue( psIdentifier, "gml:codeSpace", pszCodeSpace );    if( pszEdition != NULL )        CPLCreateXMLElementAndValue( psIdentifier, "gml:version", pszEdition );    return psIdentifier;}/************************************************************************//*                        exportAuthorityToXML()                        *//************************************************************************/static CPLXMLNode *exportAuthorityToXML( const OGR_SRSNode *poAuthParent,                                         const char *pszTagName,                                         CPLXMLNode *psXMLParent ){    const OGR_SRSNode *poAuthority;/* -------------------------------------------------------------------- *//*      Get authority node from parent.                                 *//* -------------------------------------------------------------------- */    if( poAuthParent->FindChild( "AUTHORITY" ) == -1 )        return NULL;    poAuthority = poAuthParent->GetChild(         poAuthParent->FindChild( "AUTHORITY" ));/* -------------------------------------------------------------------- *//*      Create identification.                                          *//* -------------------------------------------------------------------- */    const char *pszCode, *pszCodeSpace, *pszEdition;    pszCode = poAuthority->GetChild(1)->GetValue();    pszCodeSpace = poAuthority->GetChild(0)->GetValue();    pszEdition = NULL;    return addID( psXMLParent, pszTagName, pszCode, pszCodeSpace, pszEdition );}/************************************************************************//*                             addProjArg()                             *//************************************************************************/static void addProjArg( const OGRSpatialReference *poSRS, CPLXMLNode *psBase,                         const char *pszMeasureType, double dfDefault,                        int nParameterID, const char *pszWKTName ){    CPLXMLNode *psNode, *psValue;    psNode = CPLCreateXMLNode( psBase, CXT_Element, "gml:usesParameterValue" );/* -------------------------------------------------------------------- *//*      Handle the UOM.                                                 *//* -------------------------------------------------------------------- */    const char *pszUOMValue;    if( EQUAL(pszMeasureType,"Angular") )        pszUOMValue = "urn:EPSG::unitID:9102";    else        pszUOMValue = "urn:EPSG::unitID:9001";    psValue = CPLCreateXMLNode( psNode, CXT_Element, "gml:value" );    CPLCreateXMLNode(         CPLCreateXMLNode( psValue, CXT_Attribute, "gml:uom" ),        CXT_Text, pszUOMValue );    /* -------------------------------------------------------------------- *//*      Add the parameter value itself.                                 *//* -------------------------------------------------------------------- */    double dfParmValue        = poSRS->GetNormProjParm( pszWKTName, dfDefault, NULL );            CPLCreateXMLNode( psValue, CXT_Text,                       CPLSPrintf( "%.16g", dfParmValue ) );/* -------------------------------------------------------------------- *//*      Add the valueOfParameter.                                       *//* -------------------------------------------------------------------- */    addURN( CPLCreateXMLNode( psNode, CXT_Element, "gml:valueOfParameter" ),            "parameterID", nParameterID );}/************************************************************************//*                              addAxis()                               *//*                                                                      *//*      Added the <usesAxis> element and down.                          *//************************************************************************/static CPLXMLNode *addAxis( CPLXMLNode *psXMLParent,                             const char *pszAxis, // "Lat", "Long", "E" or "N"                            const OGR_SRSNode * /* poUnitsSrc */ ){    CPLXMLNode *psAxisXML;    psAxisXML =         CPLCreateXMLNode(             CPLCreateXMLNode( psXMLParent, CXT_Element, "gml:usesAxis" ),            CXT_Element, "gml:CoordinateSystemAxis" );    addGMLId( psAxisXML );    if( EQUAL(pszAxis,"Lat") )    {        CPLCreateXMLNode(             CPLCreateXMLNode( psAxisXML, CXT_Attribute, "gml:uom" ),            CXT_Text, "urn:EPSG::unitID:9102" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:axisName",                                     "Geodetic latitude" );        addID( psAxisXML, "axisID", "9901", "EPSG", "6.0" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:axisAbbrev", "Lat" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:axisDirection", "north" );    }    else if( EQUAL(pszAxis,"Long") )    {        CPLCreateXMLNode(             CPLCreateXMLNode( psAxisXML, CXT_Attribute, "gml:uom" ),            CXT_Text, "urn:EPSG::unitID:9102" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:axisName",                                     "Geodetic longitude" );        addID( psAxisXML, "axisID", "9902", "EPSG", "6.0" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:axisAbbrev", "Lon" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:axisDirection", "east" );    }    else if( EQUAL(pszAxis,"E") )    {        CPLCreateXMLNode(             CPLCreateXMLNode( psAxisXML, CXT_Attribute, "gml:uom" ),            CXT_Text, "urn:EPSG::unitID:9001" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:axisName", "Easting" );        addID( psAxisXML, "axisID", "9906", "EPSG", "6.0" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:axisAbbrev", "E" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:axisDirection", "east" );    }    else if( EQUAL(pszAxis,"N") )    {        CPLCreateXMLNode(             CPLCreateXMLNode( psAxisXML, CXT_Attribute, "gml:uom" ),            CXT_Text, "urn:EPSG::unitID:9001" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:axisName", "Northing" );        addID( psAxisXML, "axisID", "9907", "EPSG", "6.0" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:axisAbbrev", "N" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:axisDirection", "north" );    }    else    {        CPLAssert( FALSE );    }    return psAxisXML;}/************************************************************************//*                         exportGeogCSToXML()                          *//************************************************************************/static CPLXMLNode *exportGeogCSToXML( const OGRSpatialReference *poSRS ){    CPLXMLNode  *psGCS_XML;    const OGR_SRSNode *poGeogCS = poSRS->GetAttrNode( "GEOGCS" );    if( poGeogCS == NULL )        return NULL;    /* -------------------------------------------------------------------- *//*      Establish initial infrastructure.                               *//* -------------------------------------------------------------------- */    psGCS_XML = CPLCreateXMLNode( NULL, CXT_Element, "gml:GeographicCRS" );    addGMLId( psGCS_XML );    /* -------------------------------------------------------------------- *//*      Attach symbolic name (srsName).                                 *//* -------------------------------------------------------------------- */    CPLCreateXMLElementAndValue( psGCS_XML, "gml:srsName",                                  poGeogCS->GetChild(0)->GetValue() );/* -------------------------------------------------------------------- *//*      Does the overall coordinate system have an authority?  If so    *//*      attach as an identification section.                            *//* -------------------------------------------------------------------- */    exportAuthorityToXML( poGeogCS, "gml:srsID", psGCS_XML );/* -------------------------------------------------------------------- *//*      Insert a big whack of fixed stuff defining the                  *//*      ellipsoidalCS.  Basically this defines the axes and their       *//*      units.                                                          *//* -------------------------------------------------------------------- */    CPLXMLNode *psECS;    psECS = CPLCreateXMLNode(         CPLCreateXMLNode( psGCS_XML, CXT_Element, "gml:usesEllipsoidalCS" ),        CXT_Element, "gml:EllipsoidalCS" );

⌨️ 快捷键说明

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