📄 ogr_srs_xml.cpp
字号:
/****************************************************************************** * $Id: ogr_srs_xml.cpp,v 1.10 2006/07/27 19:03:23 fwarmerdam 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.10 2006/07/27 19:03:23 fwarmerdam * Modified to place code in xml:href instead of element value per * email from Sean Forde. * * Revision 1.9 2006/07/27 13:40:47 fwarmerdam * Handle method/parameter values encoded directly in the urn. * Allow usesValue as well as usesParameterValue. * * Revision 1.8 2006/02/26 05:29:12 fwarmerdam * added LCC1SP * * Revision 1.7 2005/05/11 14:37:25 fwarmerdam * add id on projectedcrs * * Revision 1.6 2005/01/17 17:04:24 fwarmerdam * major overhaul to more-or-less GML 3 CRS support * * 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"/************************************************************************//* parseURN() *//* *//* Parses requested sections out of URN. The passed in URN *//* *is* altered but the returned values point into the *//* original string. *//************************************************************************/static int parseURN( char *pszURN, char **ppszObjectType, char **ppszAuthority, char **ppszCode, char **ppszVersion = NULL ){ int i; if( ppszObjectType != NULL ) *ppszObjectType = ""; if( ppszAuthority != NULL ) *ppszAuthority = ""; if( ppszCode != NULL ) *ppszCode = ""; if( ppszVersion != NULL ) *ppszVersion = "";/* -------------------------------------------------------------------- *//* Verify prefix. *//* -------------------------------------------------------------------- */ if( !EQUALN(pszURN,"urn:ogc:def:",12) ) return FALSE;/* -------------------------------------------------------------------- *//* Extract object type *//* -------------------------------------------------------------------- */ if( ppszObjectType != NULL ) *ppszObjectType = (char *) pszURN + 12; i = 12; while( pszURN[i] != ':' && pszURN[i] != '\0' ) i++; if( pszURN[i] == '\0' ) return FALSE; pszURN[i] = '\0'; i++;/* -------------------------------------------------------------------- *//* Extract authority *//* -------------------------------------------------------------------- */ if( ppszAuthority != NULL ) *ppszAuthority = (char *) pszURN + i; while( pszURN[i] != ':' && pszURN[i] != '\0' ) i++; if( pszURN[i] == '\0' ) return FALSE; pszURN[i] = '\0'; i++;/* -------------------------------------------------------------------- *//* Extract version *//* -------------------------------------------------------------------- */ if( ppszVersion != NULL ) *ppszVersion = (char *) pszURN + i; while( pszURN[i] != ':' && pszURN[i] != '\0' ) i++; if( pszURN[i] == '\0' ) return FALSE; pszURN[i] = '\0'; i++;/* -------------------------------------------------------------------- *//* Extract code. *//* -------------------------------------------------------------------- */ if( ppszCode != NULL ) *ppszCode = (char *) pszURN + i; return TRUE;}/************************************************************************//* addURN() *//************************************************************************/static void addURN( CPLXMLNode *psTarget, const char *pszAuthority, const char *pszObjectType, int nCode, const char *pszVersion = "" ){ char szURN[200]; if( pszVersion == NULL ) pszVersion = ""; CPLAssert( strlen(pszAuthority)+strlen(pszObjectType) < sizeof(szURN)-30 ); sprintf( szURN, "urn:ogc:def:%s:%s:%s:", pszObjectType, pszAuthority, pszVersion ); if( nCode != 0 ) sprintf( szURN + strlen(szURN), "%d", nCode ); CPLCreateXMLNode( CPLCreateXMLNode( psTarget, CXT_Attribute, "xlink:href" ), CXT_Text, szURN );}/************************************************************************//* AddValueIDWithURN() *//* *//* Adds element of the form <ElementName *//* xlink:href="urn_without_id">id</ElementName>" *//************************************************************************/static CPLXMLNode *AddValueIDWithURN( CPLXMLNode *psTarget, const char *pszElement, const char *pszAuthority, const char *pszObjectType, int nCode, const char *pszVersion = "" ) { CPLXMLNode *psElement; psElement = CPLCreateXMLNode( psTarget, CXT_Element, pszElement ); addURN( psElement, pszAuthority, pszObjectType, nCode, pszVersion ); return psElement;}/************************************************************************//* addAuthorityIDBlock() *//* *//* Creates a structure like: *//* <srsId> *//* <name codeSpace="urn">code</name> *//* </srsId> *//************************************************************************/static CPLXMLNode *addAuthorityIDBlock( CPLXMLNode *psTarget, const char *pszElement, const char *pszAuthority, const char *pszObjectType, int nCode, const char *pszVersion = "" ){ char szURN[200];/* -------------------------------------------------------------------- *//* Prepare partial URN without the actual code. *//* -------------------------------------------------------------------- */ if( pszVersion == NULL ) pszVersion = ""; CPLAssert( strlen(pszAuthority)+strlen(pszObjectType) < sizeof(szURN)-30 ); sprintf( szURN, "urn:ogc:def:%s:%s:%s:", pszObjectType, pszAuthority, pszVersion ); /* -------------------------------------------------------------------- *//* Prepare the base name, eg. <srsID>. *//* -------------------------------------------------------------------- */ CPLXMLNode *psElement = CPLCreateXMLNode( psTarget, CXT_Element, pszElement );/* -------------------------------------------------------------------- *//* Prepare the name element. *//* -------------------------------------------------------------------- */ CPLXMLNode * psName = CPLCreateXMLNode( psElement, CXT_Element, "gml:name" );/* -------------------------------------------------------------------- *//* Prepare the codespace attribute. *//* -------------------------------------------------------------------- */ CPLCreateXMLNode( CPLCreateXMLNode( psName, CXT_Attribute, "gml:codeSpace" ), CXT_Text, szURN );/* -------------------------------------------------------------------- *//* Attach code value to name node. *//* -------------------------------------------------------------------- */ char szCode[32]; sprintf( szCode, "%d", nCode ); CPLCreateXMLNode( psName, CXT_Text, szCode ); return psElement;} /************************************************************************//* 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 );}/************************************************************************//* exportAuthorityToXML() *//************************************************************************/static CPLXMLNode *exportAuthorityToXML( const OGR_SRSNode *poAuthParent, const char *pszTagName, CPLXMLNode *psXMLParent, const char *pszObjectType, int bUseSubName = TRUE ){ 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; if( bUseSubName ) return addAuthorityIDBlock( psXMLParent, pszTagName, pszCodeSpace, pszObjectType, atoi(pszCode), pszEdition ); else return AddValueIDWithURN( psXMLParent, pszTagName, pszCodeSpace, pszObjectType, atoi(pszCode), pszEdition ); }/************************************************************************//* addProjArg() *//************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -