📄 ogrspatialreference.cpp
字号:
{ return ((OGRSpatialReference *) hSRS)->Dereference();}/************************************************************************//* GetReferenceCount() *//************************************************************************//** * \fn int OGRSpatialReference::GetReferenceCount() const; * * Fetch current reference count. * * @return the current reference count. *//************************************************************************//* Release() *//************************************************************************//** * Decrements the reference count by one, and destroy if zero. * * The method does the same thing as the C function OSRRelease(). */void OGRSpatialReference::Release(){ if( this && Dereference() == 0 ) delete this;}/************************************************************************//* OSRRelease() *//************************************************************************/void OSRRelease( OGRSpatialReferenceH hSRS ){ ((OGRSpatialReference *) hSRS)->Release();}/************************************************************************//* SetRoot() *//************************************************************************//** * Set the root SRS node. * * If the object has an existing tree of OGR_SRSNodes, they are destroyed * as part of assigning the new root. Ownership of the passed OGR_SRSNode is * is assumed by the OGRSpatialReference. * * @param poNewRoot object to assign as root. */void OGRSpatialReference::SetRoot( OGR_SRSNode * poNewRoot ){ if( poRoot != NULL ) delete poRoot; poRoot = poNewRoot;}/************************************************************************//* GetAttrNode() *//************************************************************************//** * Find named node in tree. * * This method does a pre-order traversal of the node tree searching for * a node with this exact value (case insensitive), and returns it. Leaf * nodes are not considered, under the assumption that they are just * attribute value nodes. * * If a node appears more than once in the tree (such as UNIT for instance), * the first encountered will be returned. Use GetNode() on a subtree to be * more specific. * * @param pszNodePath the name of the node to search for. May contain multiple * components such as "GEOGCS|UNITS". * * @return a pointer to the node found, or NULL if none. */OGR_SRSNode *OGRSpatialReference::GetAttrNode( const char * pszNodePath ){ char **papszPathTokens; OGR_SRSNode *poNode; papszPathTokens = CSLTokenizeStringComplex(pszNodePath, "|", TRUE, FALSE); if( CSLCount( papszPathTokens ) < 1 ) return NULL; poNode = GetRoot(); for( int i = 0; poNode != NULL && papszPathTokens[i] != NULL; i++ ) { poNode = poNode->GetNode( papszPathTokens[i] ); } CSLDestroy( papszPathTokens ); return poNode;}const OGR_SRSNode *OGRSpatialReference::GetAttrNode( const char * pszNodePath ) const{ OGR_SRSNode *poNode; poNode = ((OGRSpatialReference *) this)->GetAttrNode(pszNodePath); return poNode;}/************************************************************************//* GetAttrValue() *//************************************************************************//** * Fetch indicated attribute of named node. * * This method uses GetAttrNode() to find the named node, and then extracts * the value of the indicated child. Thus a call to GetAttrValue("UNIT",1) * would return the second child of the UNIT node, which is normally the * length of the linear unit in meters. * * This method does the same thing as the C function OSRGetAttrValue(). * * @param pszNodeName the tree node to look for (case insensitive). * @param iAttr the child of the node to fetch (zero based). * * @return the requested value, or NULL if it fails for any reason. */const char *OGRSpatialReference::GetAttrValue( const char * pszNodeName, int iAttr ) const{ const OGR_SRSNode *poNode; poNode = GetAttrNode( pszNodeName ); if( poNode == NULL ) return NULL; if( iAttr < 0 || iAttr >= poNode->GetChildCount() ) return NULL; return poNode->GetChild(iAttr)->GetValue();}/************************************************************************//* OSRGetAttrValue() *//************************************************************************/const char * CPL_STDCALL OSRGetAttrValue( OGRSpatialReferenceH hSRS, const char * pszKey, int iChild ){ return ((OGRSpatialReference *) hSRS)->GetAttrValue( pszKey, iChild );}/************************************************************************//* Clone() *//************************************************************************//** * Make a duplicate of this OGRSpatialReference. * * This method is the same as the C function OSRClone(). * * @return a new SRS, which becomes the responsibility of the caller. */OGRSpatialReference *OGRSpatialReference::Clone() const{ OGRSpatialReference *poNewRef; poNewRef = new OGRSpatialReference(); if( poRoot != NULL ) poNewRef->poRoot = poRoot->Clone(); return poNewRef;}/************************************************************************//* OSRClone() *//************************************************************************/OGRSpatialReferenceH CPL_STDCALL OSRClone( OGRSpatialReferenceH hSRS ){ return (OGRSpatialReferenceH) ((OGRSpatialReference *) hSRS)->Clone();}/************************************************************************//* exportToPrettyWkt() *//* *//* Translate into a nicely formatted string for display to a *//* person. *//************************************************************************/OGRErr OGRSpatialReference::exportToPrettyWkt( char ** ppszResult, int bSimplify ) const{ if( poRoot == NULL ) { *ppszResult = CPLStrdup(""); return OGRERR_NONE; } if( bSimplify ) { OGRSpatialReference *poSimpleClone = Clone(); OGRErr eErr; poSimpleClone->GetRoot()->StripNodes( "AXIS" ); poSimpleClone->GetRoot()->StripNodes( "AUTHORITY" ); poSimpleClone->GetRoot()->StripNodes( "EXTENSION" ); eErr = poSimpleClone->GetRoot()->exportToPrettyWkt( ppszResult, 1 ); delete poSimpleClone; return eErr; } else return poRoot->exportToPrettyWkt( ppszResult, 1 );}/************************************************************************//* OSRExportToPrettyWkt() *//************************************************************************/OGRErr CPL_STDCALL OSRExportToPrettyWkt( OGRSpatialReferenceH hSRS, char ** ppszReturn, int bSimplify){ *ppszReturn = NULL; return ((OGRSpatialReference *) hSRS)->exportToPrettyWkt( ppszReturn, bSimplify );}/************************************************************************//* exportToWkt() *//************************************************************************//** * Convert this SRS into WKT format. * * Note that the returned WKT string should be freed with OGRFree() or * CPLFree() when no longer needed. It is the responsibility of the caller. * * This method is the same as the C function OSRExportToWkt(). * * @param ppszResult the resulting string is returned in this pointer. * * @return currently OGRERR_NONE is always returned, but the future it * is possible error conditions will develop. */ OGRErr OGRSpatialReference::exportToWkt( char ** ppszResult ) const{ if( poRoot == NULL ) { *ppszResult = CPLStrdup(""); return OGRERR_NONE; } else { return poRoot->exportToWkt(ppszResult); }}/************************************************************************//* OSRExportToWkt() *//************************************************************************/OGRErr CPL_STDCALL OSRExportToWkt( OGRSpatialReferenceH hSRS, char ** ppszReturn ){ *ppszReturn = NULL; return ((OGRSpatialReference *) hSRS)->exportToWkt( ppszReturn );}/************************************************************************//* importFromWkt() *//************************************************************************//** * Import from WKT string. * * This method will wipe the existing SRS definition, and * reassign it based on the contents of the passed WKT string. Only as * much of the input string as needed to construct this SRS is consumed from * the input string, and the input string pointer * is then updated to point to the remaining (unused) input. * * This method is the same as the C function OSRImportFromWkt(). * * @param ppszInput Pointer to pointer to input. The pointer is updated to * point to remaining unused input text. * * @return OGRERR_NONE if import succeeds, or OGRERR_CORRUPT_DATA if it * fails for any reason. */OGRErr OGRSpatialReference::importFromWkt( char ** ppszInput ){ if( poRoot != NULL ) delete poRoot; bNormInfoSet = FALSE; poRoot = new OGR_SRSNode(); return poRoot->importFromWkt( ppszInput );}/************************************************************************//* OSRImportFromWkt() *//************************************************************************/OGRErr OSRImportFromWkt( OGRSpatialReferenceH hSRS, char **ppszInput ){ return ((OGRSpatialReference *) hSRS)->importFromWkt( ppszInput );}/************************************************************************//* SetNode() *//************************************************************************//** * Set attribute value in spatial reference. * * Missing intermediate nodes in the path will be created if not already * in existance. If the attribute has no children one will be created and * assigned the value otherwise the zeroth child will be assigned the value. * * This method does the same as the C function OSRSetAttrValue(). * * @param pszNodePath full path to attribute to be set. For instance * "PROJCS|GEOGCS|UNITS". * * @param pszNewNodeValue value to be assigned to node, such as "meter". * This may be NULL if you just want to force creation of the intermediate * path. * * @return OGRERR_NONE on success. */OGRErr OGRSpatialReference::SetNode( const char * pszNodePath, const char * pszNewNodeValue ){ char **papszPathTokens; int i; OGR_SRSNode *poNode; papszPathTokens = CSLTokenizeStringComplex(pszNodePath, "|", TRUE, FALSE); if( CSLCount( papszPathTokens ) < 1 ) return OGRERR_FAILURE; if( GetRoot() == NULL || !EQUAL(papszPathTokens[0],GetRoot()->GetValue()) ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -