📄 ogr_srs_xml.cpp
字号:
addGMLId( psECS ); CPLCreateXMLElementAndValue( psECS, "gml:csName", "ellipsoidal" ); addID( psECS, "csID", "6402", "EPSG", "6.0" ); 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 );/* -------------------------------------------------------------------- *//* 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 ); CPLXMLNode *psAngle; psAngle = CPLCreateXMLNode( CPLCreateXMLNode( psPM, CXT_Element, "gml:greenwichLongitude" ), CXT_Element, "gml:angle" ); CPLCreateXMLNode( CPLCreateXMLNode( psAngle, CXT_Attribute, "gml:uom" ), CXT_Text, "urn:EPSG::unitID: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 ); CPLXMLNode *psParmXML; psParmXML = CPLCreateXMLNode( psEllipseXML, CXT_Element, "gml:semiMajorAxis" ); CPLCreateXMLNode( CPLCreateXMLNode(psParmXML,CXT_Attribute,"gml:uom"), CXT_Text, "urn:EPSG::unitID: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:EPSG::unitID: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" ); /* -------------------------------------------------------------------- *//* 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 );/* -------------------------------------------------------------------- *//* 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 );/* -------------------------------------------------------------------- *//* Transverse Mercator *//* -------------------------------------------------------------------- */ if( EQUAL(pszProjection,SRS_PT_TRANSVERSE_MERCATOR) ) { addURN( CPLCreateXMLNode( psDefinedBy, CXT_Element, "gml:usesMethod" ), "methodID", 9807 ); addProjArg( poSRS, psConv, "Angular", 0.0, 8801, SRS_PP_LATITUDE_OF_ORIGIN ); addProjArg( poSRS, psConv, "Angular", 0.0, 8802, SRS_PP_CENTRAL_MERIDIAN ); addProjArg( poSRS, psConv, "Unitless", 1.0, 8805, SRS_PP_SCALE_FACTOR ); addProjArg( poSRS, psConv, "Linear", 0.0, 8806, SRS_PP_FALSE_EASTING ); addProjArg( poSRS, psConv, "Linear", 0.0, 8807, SRS_PP_FALSE_NORTHING ); }/* -------------------------------------------------------------------- *//* Define the cartesian coordinate system. *//* -------------------------------------------------------------------- */ CPLXMLNode *psCCS; psCCS = CPLCreateXMLNode( CPLCreateXMLNode( psCRS_XML, CXT_Element, "gml:usesCartesianCS" ), CXT_Element, "gml:CartesianCS" ); addGMLId( psCCS ); CPLCreateXMLElementAndValue( psCCS, "gml:csName", "Cartesian" ); addID( psCCS, "csID", "4400", "EPSG", "6.0" ); addAxis( psCCS, "E", NULL ); addAxis( psCCS, "N", NULL ); return psCRS_XML;}/************************************************************************//* exportToXML() *//************************************************************************/OGRErr OGRSpatialReference::exportToXML( char **ppszRawXML, const char * /*pszDialect*/ ) const{ CPLXMLNode *psXMLTree = NULL; if( IsGeographic() ) { psXMLTree = exportGeogCSToXML( this ); } else if( IsProjected() ) { psXMLTree = exportProjCSToXML( this ); } else return OGRERR_UNSUPPORTED_SRS; *ppszRawXML = CPLSerializeXMLTree( psXMLTree ); return OGRERR_NONE;}/************************************************************************//* OSRExportToXML() *//************************************************************************/OGRErr OSRExportToXML( OGRSpatialReferenceH hSRS, char **ppszRawXML, const char *pszDialect ){ return ((OGRSpatialReference *) hSRS)->exportToXML( ppszRawXML, pszDialect );}#ifdef notdef/************************************************************************//* importXMLUnits() *//************************************************************************/static void importXMLUnits( CPLXMLNode *psSrcXML, const char *pszClass, OGRSpatialReference *poSRS, const char *pszTarget){ const char *pszUnitName, *pszUnitsPer; OGR_SRSNode *poNode = poSRS->GetAttrNode( pszTarget ); OGR_SRSNode *poUnits; CPLAssert( EQUAL(pszClass,"AngularUnit") || EQUAL(pszClass,"LinearUnit") ); psSrcXML = CPLGetXMLNode( psSrcXML, pszClass ); if( psSrcXML == NULL ) goto DefaultTarget; pszUnitName = CPLGetXMLValue( psSrcXML, "NameSet.name", "unnamed" ); if( EQUAL(pszClass,"AngularUnit") ) pszUnitsPer = CPLGetXMLValue( psSrcXML, "radiansPerUnit", NULL ); else pszUnitsPer = CPLGetXMLValue( psSrcXML, "metresPerUnit", NULL ); if( pszUnitsPer == NULL ) { CPLDebug( "OGR_SRS_XML", "Missing PerUnit value for %s.", pszClass ); goto DefaultTarget; } if( poNode == NULL ) { CPLDebug( "OGR_SRS_XML", "Can't find %s in importXMLUnits.", pszTarget ); goto DefaultTarget; } if( poNode->FindChild("UNIT") != -1 ) { poUnits = poNode->GetChild( poNode->FindChild( "UNIT" ) ); poUnits->GetChild(0)->SetValue( pszUnitName ); poUnits->GetChild(1)->SetValue( pszUnitsPer ); } else { poUnits = new OGR_SRSNode( "UNIT" ); poUnits->AddChild( new OGR_SRSNode( pszUnitName ) ); poUnits->AddChild( new OGR_SRSNode( pszUnitsPer ) ); poNode->AddChild( poUnits ); } return; DefaultTarget: poUnits = new OGR_SRSNode( "UNIT" ); if( EQUAL(pszClass,"AngularUnit") ) { poUnits->AddChild( new OGR_SRSNode( SRS_UA_DEGREE ) );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -