📄 ogrspatialreference.cpp
字号:
&& 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. *//* -------------------------------------------------------------------- */ if( GetAttrNode( "GEOGCS" ) != NULL ) { OGR_SRSNode *poPROJCS; if( EQUAL(GetRoot()->GetValue(),"GEOGCS") ) Clear(); else if( (poPROJCS = GetAttrNode( "PROJCS" )) != NULL && poPROJCS->FindChild( "GEOGCS" ) != -1 ) poPROJCS->DestroyChild( poPROJCS->FindChild( "GEOGCS" ) ); else return OGRERR_FAILURE; }/* -------------------------------------------------------------------- *//* Set defaults for various parameters. *//* -------------------------------------------------------------------- */ if( pszGeogName == NULL ) pszGeogName = "unnamed"; if( pszPMName == NULL ) pszPMName = SRS_PM_GREENWICH; if( pszDatumName == NULL ) pszDatumName = "unknown"; if( pszSpheroidName == NULL ) pszSpheroidName = "unnamed"; if( pszAngularUnits == NULL ) { pszAngularUnits = SRS_UA_DEGREE; dfConvertToRadians = atof(SRS_UA_DEGREE_CONV); }/* -------------------------------------------------------------------- *//* Build the GEOGCS object. *//* -------------------------------------------------------------------- */ char szValue[128]; OGR_SRSNode *poGeogCS, *poSpheroid, *poDatum, *poPM, *poUnits; poGeogCS = new OGR_SRSNode( "GEOGCS" ); poGeogCS->AddChild( new OGR_SRSNode( pszGeogName ) ); /* -------------------------------------------------------------------- *//* Setup the spheroid. *//* -------------------------------------------------------------------- */ poSpheroid = new OGR_SRSNode( "SPHEROID" ); poSpheroid->AddChild( new OGR_SRSNode( pszSpheroidName ) ); OGRPrintDouble( szValue, dfSemiMajor ); poSpheroid->AddChild( new OGR_SRSNode(szValue) ); OGRPrintDouble( szValue, dfInvFlattening ); poSpheroid->AddChild( new OGR_SRSNode(szValue) );/* -------------------------------------------------------------------- *//* Setup the Datum. *//* -------------------------------------------------------------------- */ poDatum = new OGR_SRSNode( "DATUM" ); poDatum->AddChild( new OGR_SRSNode(pszDatumName) ); poDatum->AddChild( poSpheroid );/* -------------------------------------------------------------------- *//* Setup the prime meridian. *//* -------------------------------------------------------------------- */ if( dfPMOffset == 0.0 ) strcpy( szValue, "0" ); else OGRPrintDouble( szValue, dfPMOffset ); poPM = new OGR_SRSNode( "PRIMEM" ); poPM->AddChild( new OGR_SRSNode( pszPMName ) ); poPM->AddChild( new OGR_SRSNode( szValue ) );/* -------------------------------------------------------------------- *//* Setup the rotational units. *//* -------------------------------------------------------------------- */ OGRPrintDouble( szValue, dfConvertToRadians ); poUnits = new OGR_SRSNode( "UNIT" ); poUnits->AddChild( new OGR_SRSNode(pszAngularUnits) ); poUnits->AddChild( new OGR_SRSNode(szValue) ); /* -------------------------------------------------------------------- *//* Complete the GeogCS *//* -------------------------------------------------------------------- */ poGeogCS->AddChild( poDatum ); poGeogCS->AddChild( poPM ); poGeogCS->AddChild( poUnits );/* -------------------------------------------------------------------- *//* Attach below the PROJCS if there is one, or make this the root. *//* -------------------------------------------------------------------- */ if( GetRoot() != NULL && EQUAL(GetRoot()->GetValue(),"PROJCS") ) poRoot->InsertChild( poGeogCS, 1 ); else SetRoot( poGeogCS ); return OGRERR_NONE;}/************************************************************************//* OSRSetGeogCS() *//************************************************************************/OGRErr OSRSetGeogCS( OGRSpatialReferenceH hSRS, const char * pszGeogName, const char * pszDatumName, const char * pszSpheroidName, double dfSemiMajor, double dfInvFlattening, const char * pszPMName, double dfPMOffset, const char * pszAngularUnits, double dfConvertToRadians ){ return ((OGRSpatialReference *) hSRS)->SetGeogCS( pszGeogName, pszDatumName, pszSpheroidName, dfSemiMajor, dfInvFlattening, pszPMName, dfPMOffset, pszAngularUnits, dfConvertToRadians ); }/************************************************************************//* SetWellKnownGeogCS() *//************************************************************************//** * Set a GeogCS based on well known name. * * This may be called on an empty OGRSpatialReference to make a geographic * coordinate system, or on something with an existing PROJCS node to * set the underlying geographic coordinate system of a projected coordinate * system. * * The following well known text values are currently supported: * <ul> * <li> "WGS84": same as "EPSG:4326" but has no dependence on EPSG data files. * <li> "WGS72": same as "EPSG:4322" but has no dependence on EPSG data files. * <li> "NAD27": same as "EPSG:4267" but has no dependence on EPSG data files. * <li> "NAD83": same as "EPSG:4269" but has no dependence on EPSG data files. * <li> "EPSG:n": same as doing an ImportFromEPSG(n). * </ul> * * @param pszName name of well known geographic coordinate system. * @return OGRERR_NONE on success, or OGRERR_FAILURE if the name isn't * recognised, the target object is already initialized, or an EPSG value * can't be successfully looked up. */ OGRErr OGRSpatialReference::SetWellKnownGeogCS( const char * pszName ){ OGRSpatialReference oSRS2; OGRErr eErr;/* -------------------------------------------------------------------- *//* Check for EPSG authority numbers. *//* -------------------------------------------------------------------- */ if( EQUALN(pszName, "EPSG:",5) ) { eErr = oSRS2.importFromEPSG( atoi(pszName+5) ); if( eErr != OGRERR_NONE ) return eErr; if( !oSRS2.IsGeographic() ) return OGRERR_FAILURE; return CopyGeogCSFrom( &oSRS2 ); }/* -------------------------------------------------------------------- *//* Check for simple names. *//* -------------------------------------------------------------------- */ char *pszWKT = NULL; if( EQUAL(pszName, "WGS84") || EQUAL(pszName,"CRS84") ) pszWKT = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]"; else if( EQUAL(pszName, "WGS72") ) pszWKT = "GEOGCS[\"WGS 72\",DATUM[\"WGS_1972\",SPHEROID[\"WGS 72\",6378135,298.26,AUTHORITY[\"EPSG\",\"7043\"]],TOWGS84[0,0,4.5,0,0,0.554,0.2263],AUTHORITY[\"EPSG\",\"6322\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",\"4322\"]]"; else if( EQUAL(pszName, "NAD27") || EQUAL(pszName, "CRS27") ) pszWKT = "GEOGCS[\"NAD27\",DATUM[\"North_American_Datum_1927\",SPHEROID[\"Clarke 1866\",6378206.4,294.978698213898,AUTHORITY[\"EPSG\",\"7008\"]],TOWGS84[-3,142,183,0,0,0,0],AUTHORITY[\"EPSG\",\"6267\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",\"4267\"]]"; else if( EQUAL(pszName, "NAD83") || EQUAL(pszName,"CRS83") ) pszWKT = "GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6269\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",\"4269\"]]"; else return OGRERR_FAILURE;/* -------------------------------------------------------------------- *//* Import the WKT *//* -------------------------------------------------------------------- */ eErr = oSRS2.importFromWkt( &pszWKT ); if( eErr != OGRERR_NONE ) return eErr;/* -------------------------------------------------------------------- *//* Copy over. *//* -------------------------------------------------------------------- */ return CopyGeogCSFrom( &oSRS2 );}/************************************************************************//* OSRSetWellKnownGeogCS() *//************************************************************************/OGRErr OSRSetWellKnownGeogCS( OGRSpatialReferenceH hSRS, const char *pszName ){ return ((OGRSpatialReference *) hSRS)->SetWellKnownGeogCS( pszName );}/************************************************************************//* CopyGeogCSFrom() *//************************************************************************//** * Copy GEOGCS from another OGRSpatialReference. * * The GEOGCS information is copied into this OGRSpatialReference from another. * If this object has a PROJCS root already, the GEOGCS is installed within * it, otherwise it is installed as the root. * * @param poSrcSRS the spatial reference to copy the GEOGCS information from. * * @return OGRERR_NONE on success or an error code. */OGRErr OGRSpatialReference::CopyGeogCSFrom( const OGRSpatialReference * poSrcSRS ){ const OGR_SRSNode *poGeogCS = NULL; bNormInfoSet = FALSE;/* -------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -