📄 ogrspatialreference.cpp
字号:
*/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 *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 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( bSimplify ) { OGRSpatialReference *poSimpleClone = Clone(); OGRErr eErr; poSimpleClone->GetRoot()->StripNodes( "AXIS" ); poSimpleClone->GetRoot()->StripNodes( "AUTHORITY" ); eErr = poSimpleClone->GetRoot()->exportToPrettyWkt( ppszResult, 1 ); delete poSimpleClone; return eErr; } else return poRoot->exportToPrettyWkt( ppszResult, 1 );}/************************************************************************//* OSRExportToPrettyWkt() *//************************************************************************/OGRErr 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 ){ if( poRoot == NULL ) { *ppszResult = CPLStrdup(""); return OGRERR_NONE; } else { return poRoot->exportToWkt(ppszResult); }}/************************************************************************//* OSRExportToWkt() *//************************************************************************/OGRErr 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()) ) { SetRoot( new OGR_SRSNode( papszPathTokens[0] ) ); } poNode = GetRoot(); for( i = 1; papszPathTokens[i] != NULL; i++ ) { int j; for( j = 0; j < poNode->GetChildCount(); j++ ) { if( EQUAL(poNode->GetChild( j )->GetValue(),papszPathTokens[i]) ) { poNode = poNode->GetChild(j); j = -1; break; } } if( j != -1 ) { OGR_SRSNode *poNewNode = new OGR_SRSNode( papszPathTokens[i] ); poNode->AddChild( poNewNode ); poNode = poNewNode; } } CSLDestroy( papszPathTokens ); if( pszNewNodeValue != NULL ) { if( poNode->GetChildCount() > 0 ) poNode->GetChild(0)->SetValue( pszNewNodeValue ); else poNode->AddChild( new OGR_SRSNode( pszNewNodeValue ) ); } return OGRERR_NONE;}/************************************************************************//* OSRSetAttrValue() *//************************************************************************/OGRErr OSRSetAttrValue( OGRSpatialReferenceH hSRS, const char * pszPath, const char * pszValue ){ return ((OGRSpatialReference *) hSRS)->SetNode( pszPath, pszValue );}/************************************************************************//* SetNode() *//************************************************************************/OGRErr OGRSpatialReference::SetNode( const char *pszNodePath, double dfValue ){ char szValue[64]; if( ABS(dfValue - (int) dfValue) == 0.0 ) sprintf( szValue, "%d", (int) dfValue ); else // notdef: sprintf( szValue, "%.16g", dfValue ); OGRPrintDouble( szValue, dfValue ); return SetNode( pszNodePath, szValue );}/************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -