22 #include <geovalues.h> 25 #include <ogr_spatialref.h> 40 static const double SEMI_MAJOR_AXIS_WGS84 = 6378137.0;
41 static const double SEMI_MINOR_AXIS_WGS84 = 6356752.3142;
43 static ossimTrace traceDebug(
"ossimOgcWktTranslator:debug");
54 #define EPSG_CODE_MAX 32767 55 #define USER_DEFINED 32767 57 const char *prefix)
const 63 OGRSpatialReference oSRS;
81 falseEastingNorthing.
x = 0.0;
82 falseEastingNorthing.
y = 0.0;
89 getEntryNumber(lookup));
95 eastingNorthing.
toPoint(std::string(lookup));
101 falseEastingNorthing = eastingNorthing;
118 <<
"ossimOgcWktTranslator::fromOssimKwl WARNING!" 119 <<
"Unhandled unit type for " 123 getEntryString(units).c_str() )
138 falseEastingNorthing.
x = fabs(
ossimString(lookup).toFloat64());
144 falseEastingNorthing.
y = fabs(
ossimString(lookup).toFloat64());
148 oSRS.SetLinearUnits(
"Meter", 1.0);
177 ossim_uint32 new_code = epsg_spec.after(
":").toUInt32();
179 pcsCodeVal = new_code;
181 oSRS.importFromEPSG( pcsCodeVal );
183 if(projType ==
"ossimUtmProjection")
190 oSRS.SetUTM(zone.
toLong(), hemisphere !=
"S");
194 oSRS.SetUTM(zone.
toLong(),
true);
202 if (datumType ==
"WGE") gcs = GCS_WGS_84;
203 else if (datumType ==
"WGD") gcs = GCS_WGS_72;
204 else if (datumType ==
"NAR-C") gcs = GCS_NAD83;
205 else if (datumType ==
"NAR") gcs = GCS_NAD83;
206 else if (datumType ==
"NAS-C") gcs = GCS_NAD27;
207 else if (datumType ==
"NAS") gcs = GCS_NAD27;
208 else if (datumType ==
"ADI-M") gcs = GCS_Adindan;
209 else if (datumType ==
"ARF-M") gcs = GCS_Arc_1950;
210 else if (datumType ==
"ARS-M") gcs = GCS_Arc_1960;
211 else if (datumType ==
"EUR-7" || datumType ==
"EUR-M") gcs = GCS_ED50;
212 else if ((datumType ==
"OGB-7") ||
213 (datumType ==
"OGB-M") ||
214 (datumType ==
"OGB-A") ||
215 (datumType ==
"OGB-B") ||
216 (datumType ==
"OGB-C") ||
217 (datumType ==
"OGB-D")) gcs = GCS_OSGB_1936;
218 else if (datumType ==
"TOY-M") gcs = GCS_Tokyo;
224 <<
"DATUM = " << datumType <<
" tag not written " << std::endl
225 <<
"Please let us know so we can add it" << std::endl;
229 int mapZone = zone.
toInt();
231 bool bDoImportFromEPSG =
false;
237 if (hemisphere ==
"N")
239 pcsCodeVal = 32600 + mapZone;
243 pcsCodeVal = 32700 + mapZone;
245 bDoImportFromEPSG =
true;
251 if (hemisphere ==
"N")
253 pcsCodeVal = 32200 + mapZone;
257 pcsCodeVal = 32300 + mapZone;
259 bDoImportFromEPSG =
true;
265 if (hemisphere ==
"N")
267 pcsCodeVal = 26700 + mapZone;
271 pcsCodeVal = 32000 + mapZone;
273 bDoImportFromEPSG =
true;
279 if (hemisphere ==
"N")
281 pcsCodeVal = 26900 + mapZone;
285 pcsCodeVal = 32100 + mapZone;
287 bDoImportFromEPSG =
true;
297 if (hemisphere ==
"N")
299 pcsCodeVal = 16000 + mapZone;
303 pcsCodeVal = 16100 +
abs(mapZone);
309 if ( bDoImportFromEPSG ==
true )
310 oSRS.importFromEPSG( pcsCodeVal );
315 oSRS.SetUTM(zone.
toLong(), hemisphere !=
"S");
319 oSRS.SetUTM(zone.
toLong(),
true);
324 else if(projType ==
"ossimLlxyProjection")
326 OGRSpatialReference oGeogCS;
328 oGeogCS.SetEquirectangular(0.0,
332 oGeogCS.SetAngularUnits(SRS_UA_DEGREE, atof(SRS_UA_DEGREE_CONV));
334 oSRS.CopyGeogCSFrom( &oGeogCS );
336 else if(projType ==
"ossimEquDistCylProjection")
338 OGRSpatialReference oGeogCS;
340 oGeogCS.SetEquirectangular(originLat.
toDouble(),
342 falseEastingNorthing.
x,
343 falseEastingNorthing.
y);
344 oGeogCS.SetAngularUnits(SRS_UA_DEGREE, atof(SRS_UA_DEGREE_CONV));
346 oSRS.CopyGeogCSFrom( &oGeogCS );
348 else if(projType ==
"ossimSinusoidalProjection")
350 oSRS.SetSinusoidal(centralMeridian.
toDouble(),
351 falseEastingNorthing.
x,
352 falseEastingNorthing.
y);
354 else if(projType ==
"ossimCylEquAreaProjection")
358 falseEastingNorthing.
x,
359 falseEastingNorthing.
y);
361 else if(projType ==
"ossimCassiniProjection")
365 falseEastingNorthing.
x,
366 falseEastingNorthing.
y);
368 else if(projType ==
"ossimAlbersProjection")
374 falseEastingNorthing.
x,
375 falseEastingNorthing.
y);
377 else if(projType ==
"ossimAzimEquDistProjection")
381 falseEastingNorthing.
x,
382 falseEastingNorthing.
y);
384 else if(projType ==
"ossimEckert4Projection")
386 oSRS.SetEckertIV(centralMeridian.
toDouble(),
387 falseEastingNorthing.
x,
388 falseEastingNorthing.
y);
390 else if(projType ==
"ossimEckert6Projection")
392 oSRS.SetEckertVI(centralMeridian.
toDouble(),
393 falseEastingNorthing.
x,
394 falseEastingNorthing.
y);
396 else if(projType ==
"ossimGnomonicProjection")
398 oSRS.SetGnomonic(originLat.
toDouble(),
400 falseEastingNorthing.
x,
401 falseEastingNorthing.
y);
403 else if(projType ==
"ossimLambertConformalConicProjection")
409 falseEastingNorthing.
x,
410 falseEastingNorthing.
y);
412 else if(projType ==
"ossimVanDerGrintenProjection")
414 oSRS.SetVDG(centralMeridian.
toDouble(),
415 falseEastingNorthing.
x,
416 falseEastingNorthing.
y);
418 else if(projType ==
"ossimMillerProjection")
422 falseEastingNorthing.
x,
423 falseEastingNorthing.
y);
425 else if(projType ==
"ossimMercatorProjection")
427 oSRS.SetMercator(originLat.
toDouble(),
430 falseEastingNorthing.
x,
431 falseEastingNorthing.
y);
433 else if(projType ==
"ossimMollweidProjection")
435 oSRS.SetMollweide(centralMeridian.
toDouble(),
436 falseEastingNorthing.
x,
437 falseEastingNorthing.
y);
439 else if(projType ==
"ossimNewZealandMapGridProjection")
443 falseEastingNorthing.
x,
444 falseEastingNorthing.
y);
446 else if(projType ==
"ossimOrthoGraphicProjection")
448 oSRS.SetOrthographic(originLat.
toDouble(),
450 falseEastingNorthing.
x,
451 falseEastingNorthing.
y);
453 else if(projType ==
"ossimPolarStereoProjection")
458 falseEastingNorthing.
x,
459 falseEastingNorthing.
y);
461 else if(projType ==
"ossimPolyconicProjectio")
463 oSRS.SetPolyconic(originLat.
toDouble(),
465 falseEastingNorthing.
x,
466 falseEastingNorthing.
y);
468 else if(projType ==
"ossimStereographicProjection")
470 oSRS.SetStereographic(originLat.
toDouble(),
473 falseEastingNorthing.
x,
474 falseEastingNorthing.
y);
476 else if(projType ==
"ossimTransMercatorProjection")
481 falseEastingNorthing.
x,
482 falseEastingNorthing.
y);
486 cerr <<
"ossimOgcWktTranslator::fromOssimKwl:\n" 487 <<
"Projection translation for " 495 datumType = datumType.
upcase();
497 if(datumType ==
"WGE")
499 oSRS.SetWellKnownGeogCS(
"WGS84");
501 else if(datumType ==
"WGD")
503 oSRS.SetWellKnownGeogCS(
"WGS72");
505 else if(datumType ==
"NAS-C")
507 oSRS.SetWellKnownGeogCS(
"NAD27");
509 else if(datumType ==
"NAS")
511 oSRS.SetWellKnownGeogCS(
"NAD27");
513 else if(datumType ==
"NAR-C")
515 oSRS.SetWellKnownGeogCS(
"NAD83");
517 else if(datumType ==
"NAR")
519 oSRS.SetWellKnownGeogCS(
"NAD83");
521 else if(datumType ==
"NTF")
523 oSRS.SetWellKnownGeogCS(
"EPSG:4275");
527 cerr <<
"ossimOgcWktTranslator::fromOssimKwl: Datum translation for " 534 char* exportString = NULL;
535 oSRS.exportToWkt(&exportString);
539 wktString = exportString;
540 OGRFree(exportString);
549 const char *prefix)
const 552 static const char MODULE[] =
"ossimOgcWktTranslator::toOssimKwl";
559 const char* wkt = wktString.
c_str();
561 OGRSpatialReferenceH hSRS = NULL;
565 hSRS = OSRNewSpatialReference(NULL);
566 if( OSRImportFromWkt( hSRS, (
char **) &wkt ) != OGRERR_NONE )
568 OSRDestroySpatialReference( hSRS );
574 const char* epsg_code = OSRGetAttrValue( hSRS,
"AUTHORITY", 1 );
579 <<
"epsg_code: " << (epsg_code?epsg_code:
"null") <<
"\n";
588 const char* units = NULL;
589 OGR_SRSNode* node = ((OGRSpatialReference *)hSRS)->GetRoot();
590 int nbChild = node->GetChildCount();
591 for (
int i = 0; i < nbChild; i++)
593 OGR_SRSNode* curChild = node->GetChild(i);
594 if (strcmp(curChild->GetValue(),
"UNIT") == 0)
596 units = curChild->GetChild(0)->GetValue();
603 <<
"units: " << (units?units:
"null") <<
"\n";
607 bool bGeog = OSRIsGeographic(hSRS);
608 if ( bGeog ==
false )
610 ossim_units =
"meters";
621 ossim_units =
"us_survey_feet";
625 ossim_units =
"degrees";
630 ossim_units =
"meters";
636 ossim_units =
"degrees";
642 <<
"ossim_units: " << ossim_units <<
"\n";
661 const char* pszProjection = OSRGetAttrValue( hSRS,
"PROJECTION", 0 );
668 ossimString localCs = OSRGetAttrValue( hSRS,
"LOCAL_CS", 0 );
669 localCs = localCs.
upcase();
670 if(localCs ==
"GREATBRITAIN_GRID")
672 ossimProj =
"ossimBngProjection";
674 else if (ossim_units.
contains(
"degree"))
677 ossimProj =
"ossimEquDistCylProjection";
684 if(ossimProj ==
"ossimEquDistCylProjection" )
685 ossim_units =
"degrees";
694 << MODULE <<
"DEBUG:" 695 <<
"\nossimProj = " << ossimProj << endl;
700 falseEastingNorthing.
x = OSRGetProjParm(hSRS, SRS_PP_FALSE_EASTING, 0.0, NULL);
701 falseEastingNorthing.
y = OSRGetProjParm(hSRS, SRS_PP_FALSE_NORTHING, 0.0, NULL);
706 if(ossimProj ==
"ossimBngProjection")
710 "ossimBngProjection",
713 else if(ossimProj ==
"ossimCylEquAreaProjection")
717 OSRGetProjParm(hSRS, SRS_PP_STANDARD_PARALLEL_1, 0.0, NULL),
722 OSRGetProjParm(hSRS, SRS_PP_STANDARD_PARALLEL_1, 0.0, NULL),
727 getEntryNumber(ossim_units.
c_str()));
742 else if(ossimProj ==
"ossimEquDistCylProjection")
746 "ossimEquDistCylProjection",
751 getEntryNumber(ossim_units.
c_str()));
768 OSRGetProjParm(hSRS, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL),
772 OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL),
775 else if( (ossimProj ==
"ossimLambertConformalConicProjection") ||
776 (ossimProj ==
"ossimAlbersProjection") )
792 OSRGetProjParm(hSRS, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL),
796 OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL),
800 OSRGetProjParm(hSRS, SRS_PP_STANDARD_PARALLEL_1, 0.0, NULL),
804 OSRGetProjParm(hSRS, SRS_PP_STANDARD_PARALLEL_2, 0.0, NULL),
807 else if(ossimProj ==
"ossimMercatorProjection")
811 "ossimMercatorProjection",
815 OSRGetProjParm(hSRS, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL),
819 OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL),
830 else if(ossimProj ==
"ossimSinusoidalProjection")
834 "ossimSinusoidalProjection",
838 OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL),
849 else if(ossimProj ==
"ossimTransMercatorProjection")
852 int nZone = OSRGetUTMZone( hSRS, &bNorth );
857 "ossimUtmProjection",
877 "ossimTransMercatorProjection",
881 OSRGetProjParm(hSRS, SRS_PP_SCALE_FACTOR, 1.0, NULL),
886 OSRGetProjParm(hSRS, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL),
890 OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL),
907 <<
"ossimOgcWktTranslator::toOssimKwl DEBUG:\n" 908 <<
"Projection conversion to OSSIM not supported !!!!!!!!!\n" 909 <<
"Please send the following string to the development staff\n" 910 <<
"to be added to the transaltion to OSSIM\n" 918 const char *datum = OSRGetAttrValue( hSRS,
"DATUM", 0 );
933 if( oDatum ==
"WGE" &&
ossimString(epsg_code) ==
"3857" )
939 OSRDestroySpatialReference( hSRS );
944 << MODULE <<
" exit status = true" 965 std::string(
"North_American_Datum_1927")));
967 std::string(
"North_American_Datum_1983")));
969 std::string(
"North_American_Datum_1927")));
971 std::string(
"North_American_Datum_1983")));
973 std::string(
"WGS_1984")));
975 std::string(
"OGB-B")));
977 std::string(
"NTF")));
983 std::string(
"ossimTransMercatorProjection")));
985 std::string(
"ossimEquDistCylProjection")));
987 std::string(
"ossimAlbersProjection")));
989 std::string(
"ossimLambertConformalConicProjection")));
991 std::string(
"ossimSinusoidalProjection")));
993 std::string(
"ossimMercatorProjection")));
995 std::string(SRS_PT_TRANSVERSE_MERCATOR)));
997 std::string(SRS_PT_EQUIRECTANGULAR)));
999 std::string(SRS_PT_ALBERS_CONIC_EQUAL_AREA)));
1001 std::string(SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP)));
1003 std::string(SRS_PT_SINUSOIDAL)));
1005 std::string(SRS_PT_MERCATOR_1SP)));
1011 if(datum.
contains(
"North_American_Datum_1927"))
1015 if(datum.
contains(
"North_American_Datum_1983"))
1039 if(datum.
contains(
"Nouvelle_Triangulation_Francaise"))
1053 result = (*i).second;
1061 map<std::string, std::string>::const_iterator i =
1065 result = (*i).second;
1073 map<std::string, std::string>::const_iterator i =
1077 result = (*i).second;
ossimString before(const ossimString &str, std::string::size_type pos=0) const
METHOD: before(str, pos) Returns string beginning at pos and ending one before the token str If strin...
static ossimString upcase(const ossimString &aString)
static const char * DATUM_KW
static const char * FALSE_EASTING_NORTHING_UNITS_KW
static const char * CENTRAL_MERIDIAN_KW
Represents serializable keyword/value map.
const char * find(const char *key) const
ossimString fromOssimKwl(const ossimKeywordlist &kwl, const char *prefix=NULL) const
ossimString ossimToWktProjection(const ossimString &projection) const
ossimString ossimToWktDatum(const ossimString &datum) const
bool contains(char aChar) const
static ossimString toString(bool aValue)
Numeric to string methods.
Projection Database for coded projections defined in database files and specified via some coordinate...
virtual ossimString getClassName() const
ossimString wktToOssimDatum(const ossimString &datum) const
std::map< std::string, std::string > theOssimToWktDatumTranslation
ossim_uint32 findProjectionCode(const ossimString &projection_name) const
Given a projection name, assigns the group (e.g., "EPSG") and code of the projection.
static const char * TYPE_KW
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
static const char * ZONE_KW
void initializeProjectionTable()
ossimString wktToOssimProjection(const ossimString &projection) const
static const char * FALSE_NORTHING_KW
static ossimEpsgProjectionDatabase * instance()
Instantiates singleton instance of this class:
unsigned int ossim_uint32
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
void toPoint(const std::string &s)
Initializes this point from string.
static const char * STD_PARALLEL_1_KW
static const char * FALSE_EASTING_KW
static ossimString downcase(const ossimString &aString)
static const char * FALSE_EASTING_NORTHING_KW
static const char * ORIGIN_LATITUDE_KW
static const char * UNITS_KW
static const char * PCS_CODE_KW
std::map< std::string, std::string > theWktToOssimProjectionTranslation
long toLong() const
toLong's deprecated, please use the toInts...
ossimString toString(ossim_uint32 precision=15) const
std::map< std::string, std::string > theWktToOssimDatumTranslation
static const char * HEMISPHERE_KW
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
virtual ossimProjection * createProjection(const ossimFilename &filename, ossim_uint32 entryIdx) const
STUB. Not implemented.
bool toOssimKwl(const ossimString &wktString, ossimKeywordlist &kwl, const char *prefix=NULL) const
static const char * SCALE_FACTOR_KW
std::map< std::string, std::string > theOssimToWktProjectionTranslation
static const char * STD_PARALLEL_2_KW
static ossimUnitTypeLut * instance()
Returns the static instance of an ossimUnitTypeLut object.
ossimString findProjectionName(ossim_uint32 epsg_code) const
NECESSARY HACK ### (originally implemented by ESH)ArcMap (9.2 and less) doesn't understand the non-me...
static ossimEpsgProjectionFactory * instance()
Implements singleton pattern.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void initializeDatumTable()