?? ogrspatialreference.cpp
字號:
bNormInfoSet = FALSE;
poCS = GetAttrNode( "GEOGCS" );
if( poCS == NULL )
return OGRERR_FAILURE;
OGRPrintDouble( szValue, dfInRadians );
if( poCS->FindChild( "UNIT" ) >= 0 )
{
poUnits = poCS->GetChild( poCS->FindChild( "UNIT" ) );
poUnits->GetChild(0)->SetValue( pszUnitsName );
poUnits->GetChild(1)->SetValue( szValue );
}
else
{
poUnits = new OGR_SRSNode( "UNIT" );
poUnits->AddChild( new OGR_SRSNode( pszUnitsName ) );
poUnits->AddChild( new OGR_SRSNode( szValue ) );
poCS->AddChild( poUnits );
}
return OGRERR_NONE;
}
/************************************************************************/
/* OSRSetAngularUnits() */
/************************************************************************/
OGRErr OSRSetAngularUnits( OGRSpatialReferenceH hSRS,
const char * pszUnits, double dfInRadians )
{
return ((OGRSpatialReference *) hSRS)->SetAngularUnits( pszUnits,
dfInRadians );
}
/************************************************************************/
/* GetAngularUnits() */
/************************************************************************/
/**
* Fetch angular geographic coordinate system units.
*
* If no units are available, a value of "degree" and SRS_UA_DEGREE_CONV
* will be assumed. This method only checks directly under the GEOGCS node
* for units.
*
* This method does the same thing as the C function OSRGetAngularUnits().
*
* @param ppszName a pointer to be updated with the pointer to the
* units name. The returned value remains internal to the OGRSpatialReference
* and shouldn't be freed, or modified. It may be invalidated on the next
* OGRSpatialReference call.
*
* @return the value to multiply by angular distances to transform them to
* radians.
*/
double OGRSpatialReference::GetAngularUnits( char ** ppszName ) const
{
const OGR_SRSNode *poCS = GetAttrNode( "GEOGCS" );
if( ppszName != NULL )
*ppszName = "degree";
if( poCS == NULL )
return atof(SRS_UA_DEGREE_CONV);
for( int iChild = 0; iChild < poCS->GetChildCount(); iChild++ )
{
const OGR_SRSNode *poChild = poCS->GetChild(iChild);
if( EQUAL(poChild->GetValue(),"UNIT")
&& poChild->GetChildCount() >= 2 )
{
if( ppszName != NULL )
*ppszName = (char *) poChild->GetChild(0)->GetValue();
return atof( poChild->GetChild(1)->GetValue() );
}
}
return 1.0;
}
/************************************************************************/
/* OSRGetAngularUnits() */
/************************************************************************/
double OSRGetAngularUnits( OGRSpatialReferenceH hSRS, char ** ppszName )
{
return ((OGRSpatialReference *) hSRS)->GetAngularUnits( ppszName );
}
/************************************************************************/
/* SetLinearUnitsAndUpdateParameters() */
/************************************************************************/
/**
* Set the linear units for the projection.
*
* This method creates a UNITS subnode with the specified values as a
* child of the PROJCS or LOCAL_CS node. It works the same as the
* SetLinearUnits() method, but it also updates all existing linear
* projection parameter values from the old units to the new units.
*
* @param pszUnitsName the units name to be used. Some preferred units
* names can be found in ogr_srs_api.h such as SRS_UL_METER, SRS_UL_FOOT
* and SRS_UL_US_FOOT.
*
* @param dfInMeters the value to multiple by a length in the indicated
* units to transform to meters. Some standard conversion factors can
* be found in ogr_srs_api.h.
*
* @return OGRERR_NONE on success.
*/
OGRErr OGRSpatialReference::SetLinearUnitsAndUpdateParameters(
const char *pszName, double dfInMeters )
{
double dfOldInMeters = GetLinearUnits();
OGR_SRSNode *poPROJCS = GetAttrNode( "PROJCS" );
if( dfInMeters == 0.0 )
return OGRERR_FAILURE;
if( dfInMeters == dfOldInMeters || poPROJCS == NULL )
return SetLinearUnits( pszName, dfInMeters );
for( int iChild = 0; iChild < poPROJCS->GetChildCount(); iChild++ )
{
const OGR_SRSNode *poChild = poPROJCS->GetChild(iChild);
if( EQUAL(poChild->GetValue(),"PARAMETER")
&& poChild->GetChildCount() > 1 )
{
char *pszParmName = CPLStrdup(poChild->GetChild(0)->GetValue());
if( IsLinearParameter( pszParmName ) )
{
double dfOldValue = GetProjParm( pszParmName );
SetProjParm( pszParmName,
dfOldValue * dfOldInMeters / dfInMeters );
}
CPLFree( pszParmName );
}
}
return SetLinearUnits( pszName, dfInMeters );
}
/************************************************************************/
/* SetLinearUnits() */
/************************************************************************/
/**
* Set the linear units for the projection.
*
* This method creates a UNITS subnode with the specified values as a
* child of the PROJCS or LOCAL_CS node.
*
* This method does the same as the C function OSRSetLinearUnits().
*
* @param pszUnitsName the units name to be used. Some preferred units
* names can be found in ogr_srs_api.h such as SRS_UL_METER, SRS_UL_FOOT
* and SRS_UL_US_FOOT.
*
* @param dfInMeters the value to multiple by a length in the indicated
* units to transform to meters. Some standard conversion factors can
* be found in ogr_srs_api.h.
*
* @return OGRERR_NONE on success.
*/
OGRErr OGRSpatialReference::SetLinearUnits( const char * pszUnitsName,
double dfInMeters )
{
OGR_SRSNode *poCS;
OGR_SRSNode *poUnits;
char szValue[128];
bNormInfoSet = FALSE;
poCS = GetAttrNode( "PROJCS" );
if( poCS == NULL )
poCS = GetAttrNode( "LOCAL_CS" );
if( poCS == NULL )
return OGRERR_FAILURE;
if( dfInMeters == (int) dfInMeters )
sprintf( szValue, "%d", (int) dfInMeters );
else
//notdef: sprintf( szValue, "%.16g", dfInMeters );
OGRPrintDouble( szValue, dfInMeters );
if( poCS->FindChild( "UNIT" ) >= 0 )
{
poUnits = poCS->GetChild( poCS->FindChild( "UNIT" ) );
poUnits->GetChild(0)->SetValue( pszUnitsName );
poUnits->GetChild(1)->SetValue( szValue );
if( poUnits->FindChild( "AUTHORITY" ) != -1 )
poUnits->DestroyChild( poUnits->FindChild( "AUTHORITY" ) );
}
else
{
poUnits = new OGR_SRSNode( "UNIT" );
poUnits->AddChild( new OGR_SRSNode( pszUnitsName ) );
poUnits->AddChild( new OGR_SRSNode( szValue ) );
poCS->AddChild( poUnits );
}
return OGRERR_NONE;
}
/************************************************************************/
/* OSRSetLinearUnits() */
/************************************************************************/
OGRErr OSRSetLinearUnits( OGRSpatialReferenceH hSRS,
const char * pszUnits, double dfInMeters )
{
return ((OGRSpatialReference *) hSRS)->SetLinearUnits( pszUnits,
dfInMeters );
}
/************************************************************************/
/* GetLinearUnits() */
/************************************************************************/
/**
* Fetch linear projection units.
*
* If no units are available, a value of "Meters" and 1.0 will be assumed.
* This method only checks directly under the PROJCS or LOCAL_CS node for
* units.
*
* This method does the same thing as the C function OSRGetLinearUnits()/
*
* @param ppszName a pointer to be updated with the pointer to the
* units name. The returned value remains internal to the OGRSpatialReference
* and shouldn't be freed, or modified. It may be invalidated on the next
* OGRSpatialReference call.
*
* @return the value to multiply by linear distances to transform them to
* meters.
*/
double OGRSpatialReference::GetLinearUnits( char ** ppszName ) const
{
const OGR_SRSNode *poCS = GetAttrNode( "PROJCS" );
if( poCS == NULL )
poCS = GetAttrNode( "LOCAL_CS" );
if( ppszName != NULL )
*ppszName = "unknown";
if( poCS == NULL )
return 1.0;
for( int iChild = 0; iChild < poCS->GetChildCount(); iChild++ )
{
const OGR_SRSNode *poChild = poCS->GetChild(iChild);
if( EQUAL(poChild->GetValue(),"UNIT")
&& poChild->GetChildCount() >= 2 )
{
if( ppszName != NULL )
*ppszName = (char *) poChild->GetChild(0)->GetValue();
return atof( poChild->GetChild(1)->GetValue() );
}
}
return 1.0;
}
/************************************************************************/
/* OSRGetLinearUnits() */
/************************************************************************/
double OSRGetLinearUnits( OGRSpatialReferenceH hSRS, char ** ppszName )
{
return ((OGRSpatialReference *) hSRS)->GetLinearUnits( ppszName );
}
/************************************************************************/
/* GetPrimeMeridian() */
/************************************************************************/
/**
* Fetch prime meridian info.
*
* Returns the offset of the prime meridian from greenwich in degrees,
* and the prime meridian name (if requested). If no PRIMEM value exists
* in the coordinate system definition a value of "Greenwich" and an
* offset of 0.0 is assumed.
*
* If the prime meridian name is returned, the pointer is to an internal
* copy of the name. It should not be freed, altered or depended on after
* the next OGR call.
*
* This method is the same as the C function OSRGetPrimeMeridian().
*
* @param ppszName return location for prime meridian name. If NULL, name
* is not returned.
*
* @return the offset to the GEOGCS prime meridian from greenwich in decimal
* degrees.
*/
double OGRSpatialReference::GetPrimeMeridian( char **ppszName ) const
{
const OGR_SRSNode *poPRIMEM = GetAttrNode( "PRIMEM" );
if( poPRIMEM != NULL && poPRIMEM->GetChildCount() >= 2
&& atof(poPRIMEM->GetChild(1)->GetValue()) != 0.0 )
{
if( ppszName != NULL )
*ppszName = (char *) poPRIMEM->GetChild(0)->GetValue();
return atof(poPRIMEM->GetChild(1)->GetValue());
}
if( ppszName != NULL )
*ppszName = SRS_PM_GREENWICH;
return 0.0;
}
/************************************************************************/
/* OSRGetPrimeMeridian() */
/************************************************************************/
double OSRGetPrimeMeridian( OGRSpatialReferenceH hSRS, char **ppszName )
{
return ((OGRSpatialReference *) hSRS)->GetPrimeMeridian( ppszName );
}
/************************************************************************/
/* SetGeogCS() */
/************************************************************************/
/**
* Set geographic coordinate system.
*
* This method is used to set the datum, ellipsoid, prime meridian and
* angular units for a geographic coordinate system. It can be used on it's
* own to establish a geographic spatial reference, or applied to a
* projected coordinate system to establish the underlying geographic
* coordinate system.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -