📄 ogrspatialreference.cpp
字号:
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()) )
{
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 CPL_STDCALL 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 );
}
/************************************************************************/
/* SetAngularUnits() */
/************************************************************************/
/**
* Set the angular units for the geographic coordinate system.
*
* This method creates a UNITS subnode with the specified values as a
* child of the GEOGCS node.
*
* This method does the same as the C function OSRSetAngularUnits().
*
* @param pszUnitsName the units name to be used. Some preferred units
* names can be found in ogr_srs_api.h such as SRS_UA_DEGREE.
*
* @param dfInRadians the value to multiple by an angle in the indicated
* units to transform to radians. Some standard conversion factors can
* be found in ogr_srs_api.h.
*
* @return OGRERR_NONE on success.
*/
OGRErr OGRSpatialReference::SetAngularUnits( const char * pszUnitsName,
double dfInRadians )
{
OGR_SRSNode *poCS;
OGR_SRSNode *poUnits;
char szValue[128];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -