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

📄 ogr_srs_xml.cpp

📁 用于读取TAB、MIF、SHP文件的类
💻 CPP
📖 第 1 页 / 共 4 页
字号:
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:ogc:def:uom:EPSG::9102";    else        pszUOMValue = "urn:ogc:def:uom:EPSG::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.                                       *//* -------------------------------------------------------------------- */    AddValueIDWithURN( psNode, "gml:valueOfParameter", "EPSG", "parameter",                        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:ogc:def:uom:EPSG::9102" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:name",                                     "Geodetic latitude" );        addAuthorityIDBlock( psAxisXML, "gml:axisID", "EPSG", "axis", 9901 );        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:ogc:def:uom:EPSG::9102" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:name",                                     "Geodetic longitude" );        addAuthorityIDBlock( psAxisXML, "gml:axisID", "EPSG", "axis", 9902 );        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:ogc:def:uom:EPSG::9001" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:name", "Easting" );        addAuthorityIDBlock( psAxisXML, "gml:axisID", "EPSG", "axis", 9906 );        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:ogc:def:uom:EPSG::9001" );        CPLCreateXMLElementAndValue( psAxisXML, "gml:name", "Northing" );        addAuthorityIDBlock( psAxisXML, "gml:axisID", "EPSG", "axis", 9907 );        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, "crs" );/* -------------------------------------------------------------------- *//*      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" );    addGMLId( psECS  );    CPLCreateXMLElementAndValue( psECS, "gml:csName", "ellipsoidal" );    addAuthorityIDBlock( psECS, "gml:csID", "EPSG", "cs", 6402 );    addAxis( psECS, "Lat", NULL );    addAxis( psECS, "Long", NULL );/* -------------------------------------------------------------------- *//*      Start with the datum.                                           *//* -------------------------------------------------------------------- */    const OGR_SRSNode    *poDatum = poGeogCS->GetNode( "DATUM" );    CPLXMLNode     *psDatumXML;    if( poDatum == NULL )    {        CPLDestroyXMLNode( psGCS_XML );        return NULL;    }    psDatumXML = CPLCreateXMLNode(         CPLCreateXMLNode( psGCS_XML, CXT_Element, "gml:usesGeodeticDatum" ),        CXT_Element, "gml:GeodeticDatum" );        addGMLId( psDatumXML );/* -------------------------------------------------------------------- *//*      Set the datumName.                                              *//* -------------------------------------------------------------------- */    CPLCreateXMLElementAndValue( psDatumXML, "gml:datumName",                                  poDatum->GetChild(0)->GetValue() );/* -------------------------------------------------------------------- *//*      Set authority id info if available.                             *//* -------------------------------------------------------------------- */    exportAuthorityToXML( poDatum, "gml:datumID", psDatumXML, "datum" );/* -------------------------------------------------------------------- *//*      Setup prime meridian information.                               *//* -------------------------------------------------------------------- */    const OGR_SRSNode *poPMNode = poGeogCS->GetNode( "PRIMEM" );    CPLXMLNode *psPM;    char *pszPMName = "Greenwich";    double dfPMOffset = poSRS->GetPrimeMeridian( &pszPMName );    psPM = CPLCreateXMLNode(         CPLCreateXMLNode( psDatumXML, CXT_Element, "gml:usesPrimeMeridian" ),        CXT_Element, "gml:PrimeMeridian" );    addGMLId( psPM );    CPLCreateXMLElementAndValue( psPM, "gml:meridianName", pszPMName );    if( poPMNode )        exportAuthorityToXML( poPMNode, "gml:meridianID", psPM, "meridian" );    CPLXMLNode *psAngle;    psAngle =         CPLCreateXMLNode(             CPLCreateXMLNode( psPM, CXT_Element, "gml:greenwichLongitude" ),            CXT_Element, "gml:angle" );        CPLCreateXMLNode( CPLCreateXMLNode( psAngle, CXT_Attribute, "gml:uom" ),                      CXT_Text, "urn:ogc:def:uom:EPSG::9102" );    CPLCreateXMLNode( psAngle, CXT_Text, CPLSPrintf( "%.16g", dfPMOffset ) );/* -------------------------------------------------------------------- *//*      Translate the ellipsoid.                                        *//* -------------------------------------------------------------------- */    const OGR_SRSNode *poEllipsoid = poDatum->GetNode( "SPHEROID" );    if( poEllipsoid != NULL )    {        CPLXMLNode *psEllipseXML;        psEllipseXML =             CPLCreateXMLNode(                 CPLCreateXMLNode(psDatumXML,CXT_Element,"gml:usesEllipsoid" ),                CXT_Element, "gml:Ellipsoid" );        addGMLId( psEllipseXML );        CPLCreateXMLElementAndValue( psEllipseXML, "gml:ellipsoidName",                                      poEllipsoid->GetChild(0)->GetValue() );        exportAuthorityToXML( poEllipsoid, "gml:ellipsoidID", psEllipseXML,                              "ellipsoid");                CPLXMLNode *psParmXML;        psParmXML = CPLCreateXMLNode( psEllipseXML, CXT_Element,                                       "gml:semiMajorAxis" );        CPLCreateXMLNode( CPLCreateXMLNode(psParmXML,CXT_Attribute,"gml:uom"),                          CXT_Text, "urn:ogc:def:uom:EPSG::9001" );        CPLCreateXMLNode( psParmXML, CXT_Text,                           poEllipsoid->GetChild(1)->GetValue() );        psParmXML =             CPLCreateXMLNode(                 CPLCreateXMLNode( psEllipseXML, CXT_Element,                                   "gml:secondDefiningParameter" ),                CXT_Element, "gml:inverseFlattening" );                CPLCreateXMLNode( CPLCreateXMLNode(psParmXML,CXT_Attribute,"gml:uom"),                          CXT_Text, "urn:ogc:def:uom:EPSG::9201" );        CPLCreateXMLNode( psParmXML, CXT_Text,                           poEllipsoid->GetChild(2)->GetValue() );    }    return psGCS_XML;}/************************************************************************//*                         exportProjCSToXML()                          *//************************************************************************/static CPLXMLNode *exportProjCSToXML( const OGRSpatialReference *poSRS ){    const OGR_SRSNode *poProjCS = poSRS->GetAttrNode( "PROJCS" );    if( poProjCS == NULL )        return NULL;    /* -------------------------------------------------------------------- *//*      Establish initial infrastructure.                               *//* -------------------------------------------------------------------- */    CPLXMLNode   *psCRS_XML;    psCRS_XML = CPLCreateXMLNode( NULL, CXT_Element, "gml:ProjectedCRS" );    addGMLId( psCRS_XML );    /* -------------------------------------------------------------------- *//*      Attach symbolic name (a name in a nameset).                     *//* -------------------------------------------------------------------- */    CPLCreateXMLElementAndValue( psCRS_XML, "gml:srsName",                                  poProjCS->GetChild(0)->GetValue() );/* -------------------------------------------------------------------- *//*      Add authority info if we have it.                               *//* -------------------------------------------------------------------- */    exportAuthorityToXML( poProjCS, "gml:srsID", psCRS_XML, "crs" );/* -------------------------------------------------------------------- *//*      Use the GEOGCS as a <baseCRS>                                   *//* -------------------------------------------------------------------- */    CPLXMLNode *psBaseCRSXML =        CPLCreateXMLNode( psCRS_XML, CXT_Element, "gml:baseCRS" );    CPLAddXMLChild( psBaseCRSXML, exportGeogCSToXML( poSRS ) );/* -------------------------------------------------------------------- *//*      Our projected coordinate system is "defined by Conversion".     *//* -------------------------------------------------------------------- */    CPLXMLNode *psDefinedBy;    psDefinedBy = CPLCreateXMLNode( psCRS_XML, CXT_Element,                                     "gml:definedByConversion" );    /* -------------------------------------------------------------------- *//*      Projections are handled as ParameterizedTransformations.        *//* -------------------------------------------------------------------- */    const char *pszProjection = poSRS->GetAttrValue("PROJECTION");    CPLXMLNode *psConv;    psConv = CPLCreateXMLNode( psDefinedBy, CXT_Element, "gml:Conversion");    addGMLId( psConv );

⌨️ 快捷键说明

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