1145
1136
/************************************************************************/
1137
/* SetTargetLinearUnits() */
1138
/************************************************************************/
1141
* \brief Set the linear units for the projection.
1143
* This method creates a UNIT subnode with the specified values as a
1144
* child of the target node.
1146
* This method does the same as the C function OSRSetTargetLinearUnits().
1148
* @param pszTargetKey the keyword to set the linear units for. ie. "PROJCS" or "VERT_CS"
1150
* @param pszUnitsName the units name to be used. Some preferred units
1151
* names can be found in ogr_srs_api.h such as SRS_UL_METER, SRS_UL_FOOT
1152
* and SRS_UL_US_FOOT.
1154
* @param dfInMeters the value to multiple by a length in the indicated
1155
* units to transform to meters. Some standard conversion factors can
1156
* be found in ogr_srs_api.h.
1158
* @return OGRERR_NONE on success.
1163
OGRErr OGRSpatialReference::SetTargetLinearUnits( const char *pszTargetKey,
1164
const char * pszUnitsName,
1169
OGR_SRSNode *poUnits;
1172
bNormInfoSet = FALSE;
1174
if( pszTargetKey == NULL )
1176
poCS = GetAttrNode( "PROJCS" );
1179
poCS = GetAttrNode( "LOCAL_CS" );
1181
poCS = GetAttrNode( "GEOCCS" );
1182
if( poCS == NULL && IsVertical() )
1183
poCS = GetAttrNode( "VERT_CS" );
1186
poCS = GetAttrNode( pszTargetKey );
1189
return OGRERR_FAILURE;
1191
if( dfInMeters == (int) dfInMeters )
1192
sprintf( szValue, "%d", (int) dfInMeters );
1194
OGRPrintDouble( szValue, dfInMeters );
1196
if( poCS->FindChild( "UNIT" ) >= 0 )
1198
poUnits = poCS->GetChild( poCS->FindChild( "UNIT" ) );
1199
if (poUnits->GetChildCount() < 2)
1200
return OGRERR_FAILURE;
1201
poUnits->GetChild(0)->SetValue( pszUnitsName );
1202
poUnits->GetChild(1)->SetValue( szValue );
1203
if( poUnits->FindChild( "AUTHORITY" ) != -1 )
1204
poUnits->DestroyChild( poUnits->FindChild( "AUTHORITY" ) );
1208
poUnits = new OGR_SRSNode( "UNIT" );
1209
poUnits->AddChild( new OGR_SRSNode( pszUnitsName ) );
1210
poUnits->AddChild( new OGR_SRSNode( szValue ) );
1212
poCS->AddChild( poUnits );
1218
/************************************************************************/
1219
/* OSRSetLinearUnits() */
1220
/************************************************************************/
1223
* \brief Set the linear units for the target node.
1225
* This function is the same as OGRSpatialReference::SetTargetLinearUnits()
1229
OGRErr OSRSetTargetLinearUnits( OGRSpatialReferenceH hSRS,
1230
const char *pszTargetKey,
1231
const char * pszUnits, double dfInMeters )
1234
VALIDATE_POINTER1( hSRS, "OSRSetTargetLinearUnits", CE_Failure );
1236
return ((OGRSpatialReference *) hSRS)->
1237
SetTargetLinearUnits( pszTargetKey, pszUnits, dfInMeters );
1240
/************************************************************************/
1146
1241
/* GetLinearUnits() */
1147
1242
/************************************************************************/
1215
1285
/************************************************************************/
1286
/* GetTargetLinearUnits() */
1287
/************************************************************************/
1290
* \brief Fetch linear units for target.
1292
* If no units are available, a value of "Meters" and 1.0 will be assumed.
1294
* This method does the same thing as the C function OSRGetTargetLinearUnits()/
1296
* @param pszTargetKey the key to look on. ie. "PROJCS" or "VERT_CS".
1297
* @param ppszName a pointer to be updated with the pointer to the
1298
* units name. The returned value remains internal to the OGRSpatialReference
1299
* and shouldn't be freed, or modified. It may be invalidated on the next
1300
* OGRSpatialReference call.
1302
* @return the value to multiply by linear distances to transform them to
1308
double OGRSpatialReference::GetTargetLinearUnits( const char *pszTargetKey,
1309
char ** ppszName ) const
1312
const OGR_SRSNode *poCS;
1314
if( pszTargetKey == NULL )
1316
poCS = GetAttrNode( "PROJCS" );
1319
poCS = GetAttrNode( "LOCAL_CS" );
1321
poCS = GetAttrNode( "GEOCCS" );
1322
if( poCS == NULL && IsVertical() )
1323
poCS = GetAttrNode( "VERT_CS" );
1326
poCS = GetAttrNode( pszTargetKey );
1328
if( ppszName != NULL )
1329
*ppszName = (char*) "unknown";
1334
for( int iChild = 0; iChild < poCS->GetChildCount(); iChild++ )
1336
const OGR_SRSNode *poChild = poCS->GetChild(iChild);
1338
if( EQUAL(poChild->GetValue(),"UNIT")
1339
&& poChild->GetChildCount() >= 2 )
1341
if( ppszName != NULL )
1342
*ppszName = (char *) poChild->GetChild(0)->GetValue();
1344
return CPLAtof( poChild->GetChild(1)->GetValue() );
1351
/************************************************************************/
1352
/* OSRGetTargetLinearUnits() */
1353
/************************************************************************/
1356
* \brief Fetch linear projection units.
1358
* This function is the same as OGRSpatialReference::GetTargetLinearUnits()
1362
double OSRGetTargetLinearUnits( OGRSpatialReferenceH hSRS,
1363
const char *pszTargetKey,
1367
VALIDATE_POINTER1( hSRS, "OSRGetTargetLinearUnits", 0 );
1369
return ((OGRSpatialReference *) hSRS)->GetTargetLinearUnits( pszTargetKey,
1373
/************************************************************************/
1216
1374
/* GetPrimeMeridian() */
1217
1375
/************************************************************************/
1532
1707
/* -------------------------------------------------------------------- */
1533
1708
char *pszWKT = NULL;
1535
if( EQUAL(pszName, "WGS84") || EQUAL(pszName,"CRS84") )
1710
if( EQUAL(pszName, "WGS84") || EQUAL(pszName,"CRS84") || EQUAL(pszName,"CRS:84") )
1536
1711
pszWKT = (char* ) SRS_WKT_WGS84;
1538
1713
else if( EQUAL(pszName, "WGS72") )
1539
1714
pszWKT = (char* ) "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\"]],AUTHORITY[\"EPSG\",\"4322\"]]";
1541
else if( EQUAL(pszName, "NAD27") || EQUAL(pszName, "CRS27") )
1542
pszWKT = (char* ) "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\"]],AUTHORITY[\"EPSG\",\"4267\"]]";
1716
else if( EQUAL(pszName, "NAD27") || EQUAL(pszName, "CRS27") || EQUAL(pszName,"CRS:27") )
1717
pszWKT = (char* ) "GEOGCS[\"NAD27\",DATUM[\"North_American_Datum_1927\",SPHEROID[\"Clarke 1866\",6378206.4,294.978698213898,AUTHORITY[\"EPSG\",\"7008\"]],AUTHORITY[\"EPSG\",\"6267\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AUTHORITY[\"EPSG\",\"4267\"]]";
1544
else if( EQUAL(pszName, "NAD83") || EQUAL(pszName,"CRS83") )
1719
else if( EQUAL(pszName, "NAD83") || EQUAL(pszName,"CRS83") || EQUAL(pszName,"CRS:83") )
1545
1720
pszWKT = (char* ) "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\"]],AUTHORITY[\"EPSG\",\"4269\"]]";
1730
if( EQUALN(pszDefinition,"EPSG:",5) )
1731
return importFromEPSG( atoi(pszDefinition+5) );
1733
if( EQUALN(pszDefinition,"EPSGA:",6) )
1734
return importFromEPSGA( atoi(pszDefinition+6) );
1736
if( EQUALN(pszDefinition,"urn:ogc:def:crs:",16)
1737
|| EQUALN(pszDefinition,"urn:x-ogc:def:crs:",18) )
1932
if( EQUALN(pszDefinition,"EPSG:",5)
1933
|| EQUALN(pszDefinition,"EPSGA:",6) )
1937
if( EQUALN(pszDefinition,"EPSG:",5) )
1938
eStatus = importFromEPSG( atoi(pszDefinition+5) );
1940
else /* if( EQUALN(pszDefinition,"EPSGA:",6) ) */
1941
eStatus = importFromEPSGA( atoi(pszDefinition+6) );
1943
// Do we want to turn this into a compound definition
1944
// with a vertical datum?
1945
if( eStatus == OGRERR_NONE && strchr( pszDefinition, '+' ) != NULL )
1947
OGRSpatialReference oVertSRS;
1949
eStatus = oVertSRS.importFromEPSG(
1950
atoi(strchr(pszDefinition,'+')+1) );
1951
if( eStatus == OGRERR_NONE )
1953
OGR_SRSNode *poHorizSRS = GetRoot()->Clone();
1957
CPLString osName = poHorizSRS->GetChild(0)->GetValue();
1959
osName += oVertSRS.GetRoot()->GetValue();
1961
SetNode( "COMPD_CS", osName );
1962
GetRoot()->AddChild( poHorizSRS );
1963
GetRoot()->AddChild( oVertSRS.GetRoot()->Clone() );
1972
if( EQUALN(pszDefinition,"urn:ogc:def:crs:",16)
1973
|| EQUALN(pszDefinition,"urn:ogc:def:crs,crs:",20)
1974
|| EQUALN(pszDefinition,"urn:x-ogc:def:crs:",18)
1975
|| EQUALN(pszDefinition,"urn:opengis:crs:",16)
1976
|| EQUALN(pszDefinition,"urn:opengis:def:crs:",20))
1738
1977
return importFromURN( pszDefinition );
1740
1979
if( EQUALN(pszDefinition,"AUTO:",5) )
1963
2222
/************************************************************************/
1964
/* importFromURN() */
1966
/* See OGC recommendation paper 06-023r1 or later for details. */
2223
/* importFromURNPart() */
1967
2224
/************************************************************************/
1970
* \brief Initialize from OGC URN.
1972
* Initializes this spatial reference from a coordinate system defined
1973
* by an OGC URN prefixed with "urn:ogc:def:crs:" per recommendation
1974
* paper 06-023r1. Currently EPSG and OGC authority values are supported,
1975
* including OGC auto codes, but not including CRS1 or CRS88 (NAVD88).
1977
* This method is also support through SetFromUserInput() which can
1978
* normally be used for URNs.
1980
* @param pszURN the urn string.
1982
* @return OGRERR_NONE on success or an error code.
1985
OGRErr OGRSpatialReference::importFromURN( const char *pszURN )
2225
OGRErr OGRSpatialReference::importFromURNPart(const char* pszAuthority,
2226
const char* pszCode,
1988
const char *pszCur = pszURN + 16;
1990
if( EQUALN(pszURN,"urn:ogc:def:crs:",16) )
1991
pszCur = pszURN + 16;
1992
else if( EQUALN(pszURN,"urn:x-ogc:def:crs:",18) )
1993
pszCur = pszURN + 18;
1996
CPLError( CE_Failure, CPLE_AppDefined,
1997
"URN %s not a supported format.", pszURN );
1998
return OGRERR_FAILURE;
2001
/* -------------------------------------------------------------------- */
2002
/* Clear any existing definition. */
2003
/* -------------------------------------------------------------------- */
2004
if( GetRoot() != NULL )
2010
/* -------------------------------------------------------------------- */
2011
/* Find code (ignoring version) out of string like: */
2013
/* authority:version:code */
2014
/* -------------------------------------------------------------------- */
2015
const char *pszAuthority = pszCur;
2018
while( *pszCur != ':' && *pszCur )
2020
if( *pszCur == ':' )
2024
while( *pszCur != ':' && *pszCur )
2026
if( *pszCur == ':' )
2029
const char *pszCode = pszCur;
2031
2230
/* -------------------------------------------------------------------- */
2032
2231
/* Is this an EPSG code? Note that we import it with EPSG */
2085
2284
/* -------------------------------------------------------------------- */
2086
2285
/* Not a recognise OGC item. */
2087
2286
/* -------------------------------------------------------------------- */
2088
CPLError( CE_Failure, CPLE_AppDefined,
2089
"URN %s value not supported.",
2287
CPLError( CE_Failure, CPLE_AppDefined,
2288
"URN %s value not supported.",
2092
2291
return OGRERR_FAILURE;
2095
2294
/************************************************************************/
2295
/* importFromURN() */
2297
/* See OGC recommendation paper 06-023r1 or later for details. */
2298
/************************************************************************/
2301
* \brief Initialize from OGC URN.
2303
* Initializes this spatial reference from a coordinate system defined
2304
* by an OGC URN prefixed with "urn:ogc:def:crs:" per recommendation
2305
* paper 06-023r1. Currently EPSG and OGC authority values are supported,
2306
* including OGC auto codes, but not including CRS1 or CRS88 (NAVD88).
2308
* This method is also support through SetFromUserInput() which can
2309
* normally be used for URNs.
2311
* @param pszURN the urn string.
2313
* @return OGRERR_NONE on success or an error code.
2316
OGRErr OGRSpatialReference::importFromURN( const char *pszURN )
2321
if( EQUALN(pszURN,"urn:ogc:def:crs:",16) )
2322
pszCur = pszURN + 16;
2323
else if( EQUALN(pszURN,"urn:ogc:def:crs,crs:",20) )
2324
pszCur = pszURN + 20;
2325
else if( EQUALN(pszURN,"urn:x-ogc:def:crs:",18) )
2326
pszCur = pszURN + 18;
2327
else if( EQUALN(pszURN,"urn:opengis:crs:",16) )
2328
pszCur = pszURN + 16;
2329
else if( EQUALN(pszURN,"urn:opengis:def:crs:",20) )
2330
pszCur = pszURN + 20;
2333
CPLError( CE_Failure, CPLE_AppDefined,
2334
"URN %s not a supported format.", pszURN );
2335
return OGRERR_FAILURE;
2338
/* -------------------------------------------------------------------- */
2339
/* Clear any existing definition. */
2340
/* -------------------------------------------------------------------- */
2341
if( GetRoot() != NULL )
2347
/* -------------------------------------------------------------------- */
2348
/* Find code (ignoring version) out of string like: */
2350
/* authority:[version]:code */
2351
/* -------------------------------------------------------------------- */
2352
const char *pszAuthority = pszCur;
2355
while( *pszCur != ':' && *pszCur )
2357
if( *pszCur == ':' )
2361
const char* pszBeforeVersion = pszCur;
2362
while( *pszCur != ':' && *pszCur )
2364
if( *pszCur == ':' )
2367
/* We come here in the case, the content to parse is authority:code (instead of authority::code) */
2368
/* which is probably illegal according to http://www.opengeospatial.org/ogcUrnPolicy */
2369
/* but such content is found for example in what is returned by GeoServer */
2370
pszCur = pszBeforeVersion;
2372
const char *pszCode = pszCur;
2374
const char* pszComma = strchr(pszCur, ',');
2375
if (pszComma == NULL)
2376
return importFromURNPart(pszAuthority, pszCode, pszURN);
2379
/* There's a second part with the vertical SRS */
2380
pszCur = pszComma + 1;
2381
if (strncmp(pszCur, "crs:", 4) != 0)
2383
CPLError( CE_Failure, CPLE_AppDefined,
2384
"URN %s not a supported format.", pszURN );
2385
return OGRERR_FAILURE;
2390
char* pszFirstCode = CPLStrdup(pszCode);
2391
pszFirstCode[pszComma - pszCode] = '\0';
2392
OGRErr eStatus = importFromURNPart(pszAuthority, pszFirstCode, pszURN);
2393
CPLFree(pszFirstCode);
2395
// Do we want to turn this into a compound definition
2396
// with a vertical datum?
2397
if( eStatus == OGRERR_NONE )
2399
OGRSpatialReference oVertSRS;
2401
/* -------------------------------------------------------------------- */
2402
/* Find code (ignoring version) out of string like: */
2404
/* authority:[version]:code */
2405
/* -------------------------------------------------------------------- */
2406
pszAuthority = pszCur;
2409
while( *pszCur != ':' && *pszCur )
2411
if( *pszCur == ':' )
2415
pszBeforeVersion = pszCur;
2416
while( *pszCur != ':' && *pszCur )
2418
if( *pszCur == ':' )
2421
pszCur = pszBeforeVersion;
2425
eStatus = oVertSRS.importFromURNPart(pszAuthority, pszCode, pszURN);
2426
if( eStatus == OGRERR_NONE )
2428
OGR_SRSNode *poHorizSRS = GetRoot()->Clone();
2432
CPLString osName = poHorizSRS->GetChild(0)->GetValue();
2434
osName += oVertSRS.GetRoot()->GetValue();
2436
SetNode( "COMPD_CS", osName );
2437
GetRoot()->AddChild( poHorizSRS );
2438
GetRoot()->AddChild( oVertSRS.GetRoot()->Clone() );
2447
/************************************************************************/
2096
2448
/* importFromWMSAUTO() */
2097
2449
/************************************************************************/
2443
2795
/************************************************************************/
2797
/************************************************************************/
2800
* \brief Set the user visible GEOCCS name.
2802
* This method is the same as the C function OSRSetGeocCS().
2804
* This method will ensure a GEOCCS node is created as the root,
2805
* and set the provided name on it. If used on a GEOGCS coordinate system,
2806
* the DATUM and PRIMEM nodes from the GEOGCS will be tarnsferred over to
2809
* @param pszName the user visible name to assign. Not used as a key.
2811
* @return OGRERR_NONE on success.
2816
OGRErr OGRSpatialReference::SetGeocCS( const char * pszName )
2819
OGR_SRSNode *poGeogCS = NULL;
2820
OGR_SRSNode *poGeocCS = GetAttrNode( "GEOCCS" );
2822
if( poRoot != NULL && EQUAL(poRoot->GetValue(),"GEOGCS") )
2828
if( poGeocCS == NULL && GetRoot() != NULL )
2831
"OGRSpatialReference::SetGeocCS(%s) failed.\n"
2832
"It appears an incompatible root node (%s) already exists.\n",
2833
pszName, GetRoot()->GetValue() );
2834
return OGRERR_FAILURE;
2837
SetNode( "GEOCCS", pszName );
2839
if( poGeogCS != NULL )
2841
OGR_SRSNode *poDatum = poGeogCS->GetNode( "DATUM" );
2842
OGR_SRSNode *poPRIMEM = poGeogCS->GetNode( "PRIMEM" );
2843
if ( poDatum != NULL && poPRIMEM != NULL )
2845
poRoot->InsertChild( poDatum->Clone(), 1 );
2846
poRoot->InsertChild( poPRIMEM->Clone(), 2 );
2854
/************************************************************************/
2855
/* OSRSetGeocCS() */
2856
/************************************************************************/
2859
* \brief Set the user visible PROJCS name.
2861
* This function is the same as OGRSpatialReference::SetGeocCS()
2865
OGRErr OSRSetGeocCS( OGRSpatialReferenceH hSRS, const char * pszName )
2868
VALIDATE_POINTER1( hSRS, "OSRSetGeocCS", CE_Failure );
2870
return ((OGRSpatialReference *) hSRS)->SetGeocCS( pszName );
2873
/************************************************************************/
2875
/************************************************************************/
2878
* \brief Set the user visible VERT_CS name.
2880
* This method is the same as the C function OSRSetVertCS().
2882
* This method will ensure a VERT_CS node is created if needed. If the
2883
* existing coordinate system is GEOGCS or PROJCS rooted, then it will be
2884
* turned into a COMPD_CS.
2886
* @param pszVertCSName the user visible name of the vertical coordinate
2887
* system. Not used as a key.
2889
* @param pszVertDatumName the user visible name of the vertical datum. It
2890
* is helpful if this matches the EPSG name.
2892
* @param nVertDatumType the OGC vertical datum type, usually 2005.
2894
* @return OGRERR_NONE on success.
2899
OGRErr OGRSpatialReference::SetVertCS( const char * pszVertCSName,
2900
const char * pszVertDatumName,
2901
int nVertDatumType )
2904
/* -------------------------------------------------------------------- */
2905
/* Handle the case where we want to make a compound coordinate */
2907
/* -------------------------------------------------------------------- */
2908
if( IsProjected() || IsGeographic() )
2910
OGR_SRSNode *poNewRoot = new OGR_SRSNode( "COMPD_CS" );
2911
poNewRoot->AddChild( poRoot );
2915
else if( GetAttrNode( "VERT_CS" ) == NULL )
2918
/* -------------------------------------------------------------------- */
2919
/* If we already have a VERT_CS, wipe and recreate the root */
2920
/* otherwise create the VERT_CS now. */
2921
/* -------------------------------------------------------------------- */
2922
OGR_SRSNode *poVertCS = GetAttrNode( "VERT_CS" );
2924
if( poVertCS != NULL )
2926
poVertCS->ClearChildren();
2930
poVertCS = new OGR_SRSNode( "VERT_CS" );
2931
if( poRoot != NULL && EQUAL(poRoot->GetValue(),"COMPD_CS") )
2933
poRoot->AddChild( poVertCS );
2936
SetRoot( poVertCS );
2939
/* -------------------------------------------------------------------- */
2940
/* Set the name, datumname, and type. */
2941
/* -------------------------------------------------------------------- */
2942
OGR_SRSNode *poVertDatum;
2944
poVertCS->AddChild( new OGR_SRSNode( pszVertCSName ) );
2946
poVertDatum = new OGR_SRSNode( "VERT_DATUM" );
2947
poVertCS->AddChild( poVertDatum );
2949
poVertDatum->AddChild( new OGR_SRSNode( pszVertDatumName ) );
2951
CPLString osVertDatumType;
2952
osVertDatumType.Printf( "%d", nVertDatumType );
2953
poVertDatum->AddChild( new OGR_SRSNode( osVertDatumType ) );
2955
// add default axis node.
2956
OGR_SRSNode *poAxis = new OGR_SRSNode( "AXIS" );
2958
poAxis->AddChild( new OGR_SRSNode( "Up" ) );
2959
poAxis->AddChild( new OGR_SRSNode( "UP" ) );
2961
poVertCS->AddChild( poAxis );
2966
/************************************************************************/
2967
/* OSRSetVertCS() */
2968
/************************************************************************/
2971
* \brief Setup the vertical coordinate system.
2973
* This function is the same as OGRSpatialReference::SetVertCS()
2977
OGRErr OSRSetVertCS( OGRSpatialReferenceH hSRS,
2978
const char * pszVertCSName,
2979
const char * pszVertDatumName,
2980
int nVertDatumType )
2983
VALIDATE_POINTER1( hSRS, "OSRSetVertCS", CE_Failure );
2985
return ((OGRSpatialReference *) hSRS)->SetVertCS( pszVertCSName,
2990
/************************************************************************/
2991
/* SetCompoundCS() */
2992
/************************************************************************/
2995
* \brief Setup a compound coordinate system.
2997
* This method is the same as the C function OSRSetCompoundCS().
2999
* This method is replace the current SRS with a COMPD_CS coordinate system
3000
* consisting of the passed in horizontal and vertical coordinate systems.
3002
* @param pszName the name of the compound coordinate system.
3004
* @param poHorizSRS the horizontal SRS (PROJCS or GEOGCS).
3006
* @param poVertSRS the vertical SRS (VERT_CS).
3008
* @return OGRERR_NONE on success.
3012
OGRSpatialReference::SetCompoundCS( const char *pszName,
3013
const OGRSpatialReference *poHorizSRS,
3014
const OGRSpatialReference *poVertSRS )
3017
/* -------------------------------------------------------------------- */
3018
/* Verify these are legal horizontal and vertical coordinate */
3020
/* -------------------------------------------------------------------- */
3021
if( !poVertSRS->IsVertical() )
3023
CPLError( CE_Failure, CPLE_AppDefined,
3024
"SetCompoundCS() fails, vertical component is not VERT_CS." );
3025
return OGRERR_FAILURE;
3027
if( !poHorizSRS->IsProjected()
3028
&& !poHorizSRS->IsGeographic() )
3030
CPLError( CE_Failure, CPLE_AppDefined,
3031
"SetCompoundCS() fails, horizontal component is not PROJCS or GEOGCS." );
3032
return OGRERR_FAILURE;
3035
/* -------------------------------------------------------------------- */
3036
/* Replace with compound srs. */
3037
/* -------------------------------------------------------------------- */
3040
poRoot = new OGR_SRSNode( "COMPD_CS" );
3041
poRoot->AddChild( new OGR_SRSNode( pszName ) );
3042
poRoot->AddChild( poHorizSRS->GetRoot()->Clone() );
3043
poRoot->AddChild( poVertSRS->GetRoot()->Clone() );
3048
/************************************************************************/
3049
/* OSRSetCompoundCS() */
3050
/************************************************************************/
3053
* \brief Setup a compound coordinate system.
3055
* This function is the same as OGRSpatialReference::SetCompoundCS()
3057
OGRErr OSRSetCompoundCS( OGRSpatialReferenceH hSRS,
3058
const char *pszName,
3059
OGRSpatialReferenceH hHorizSRS,
3060
OGRSpatialReferenceH hVertSRS )
3063
VALIDATE_POINTER1( hSRS, "OSRSetCompoundCS", CE_Failure );
3064
VALIDATE_POINTER1( hHorizSRS, "OSRSetCompoundCS", CE_Failure );
3065
VALIDATE_POINTER1( hVertSRS, "OSRSetCompoundCS", CE_Failure );
3067
return ((OGRSpatialReference *) hSRS)->
3068
SetCompoundCS( pszName,
3069
(OGRSpatialReference *) hHorizSRS,
3070
(OGRSpatialReference *) hVertSRS );
3073
/************************************************************************/
2444
3074
/* SetProjCS() */
2445
3075
/************************************************************************/
5376
6210
/************************************************************************/
6211
/* IsSameVertCS() */
6212
/************************************************************************/
6215
* \brief Do the VertCS'es match?
6217
* This method is the same as the C function OSRIsSameVertCS().
6219
* @param poOther the SRS being compared against.
6221
* @return TRUE if they are the same or FALSE otherwise.
6224
int OGRSpatialReference::IsSameVertCS( const OGRSpatialReference *poOther ) const
6227
const char *pszThisValue, *pszOtherValue;
6229
/* -------------------------------------------------------------------- */
6230
/* Does the datum name match? */
6231
/* -------------------------------------------------------------------- */
6232
pszThisValue = this->GetAttrValue( "VERT_DATUM" );
6233
pszOtherValue = poOther->GetAttrValue( "VERT_DATUM" );
6235
if( pszThisValue == NULL || pszOtherValue == NULL
6236
|| !EQUAL(pszThisValue, pszOtherValue) )
6239
/* -------------------------------------------------------------------- */
6240
/* Do the units match? */
6241
/* -------------------------------------------------------------------- */
6242
pszThisValue = this->GetAttrValue( "VERT_CS|UNIT", 1 );
6243
if( pszThisValue == NULL )
6244
pszThisValue = "1.0";
6246
pszOtherValue = poOther->GetAttrValue( "VERT_CS|UNIT", 1 );
6247
if( pszOtherValue == NULL )
6248
pszOtherValue = "1.0";
6250
if( ABS(CPLAtof(pszOtherValue) - CPLAtof(pszThisValue)) > 0.00000001 )
6256
/************************************************************************/
6257
/* OSRIsSameVertCS() */
6258
/************************************************************************/
6261
* \brief Do the VertCS'es match?
6263
* This function is the same as OGRSpatialReference::IsSameVertCS().
6265
int OSRIsSameVertCS( OGRSpatialReferenceH hSRS1, OGRSpatialReferenceH hSRS2 )
6268
VALIDATE_POINTER1( hSRS1, "OSRIsSameVertCS", 0 );
6269
VALIDATE_POINTER1( hSRS2, "OSRIsSameVertCS", 0 );
6271
return ((OGRSpatialReference *) hSRS1)->IsSameVertCS(
6272
(OGRSpatialReference *) hSRS2 );
6275
/************************************************************************/
5378
6277
/************************************************************************/