📄 ogrspatialreference.cpp
字号:
/* 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]; 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 );}/************************************************************************//* 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. * * This method does the same as the C function OSRSetGeogCS(). * * @param pszGeogName user visible name for the geographic coordinate system * (not to serve as a key). * * @param pszDatumName key name for this datum. The OpenGIS specification * lists some known values, and otherwise EPSG datum names with a standard * transformation are considered legal keys. * * @param pszSpheroidName user visible spheroid name (not to serve as a key) * * @param dfSemiMajor the semi major axis of the spheroid. * * @param dfInvFlattening the inverse flattening for the spheroid. * This can be computed from the semi minor axis as * 1/f = 1.0 / (1.0 - semiminor/semimajor). * * @param pszPMName the name of the prime merdidian (not to serve as a key) * If this is NULL a default value of "Greenwich" will be used. * * @param dfPMOffset the longitude of greenwich relative to this prime * meridian. * * @param pszAngularUnits the angular units name (see ogr_srs_api.h for some * standard names). If NULL a value of "degrees" will be assumed. * * @param dfConvertToRadians value to multiply angular units by to transform * them to radians. A value of SRS_UL_DEGREE_CONV will be used if * pszAngularUnits is NULL. * * @return OGRERR_NONE on success. */OGRErrOGRSpatialReference::SetGeogCS( const char * pszGeogName, const char * pszDatumName, const char * pszSpheroidName, double dfSemiMajor, double dfInvFlattening, const char * pszPMName, double dfPMOffset, const char * pszAngularUnits, double dfConvertToRadians ){ bNormInfoSet = FALSE;/* -------------------------------------------------------------------- *//* Do we already have a GEOGCS? If so, blow it away so it can *//* be properly replaced. *//* -------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -