OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ossimOgcWktTranslator Class Reference

#include <ossimOgcWktTranslator.h>

Public Member Functions

 ossimOgcWktTranslator ()
 
bool toOssimKwl (const ossimString &wktString, ossimKeywordlist &kwl, const char *prefix=NULL) const
 
ossimString fromOssimKwl (const ossimKeywordlist &kwl, const char *prefix=NULL) const
 
ossimString wktToOssimDatum (const ossimString &datum) const
 
ossimString ossimToWktDatum (const ossimString &datum) const
 
ossimString wktToOssimProjection (const ossimString &projection) const
 
ossimString ossimToWktProjection (const ossimString &projection) const
 

Protected Member Functions

void initializeDatumTable ()
 
void initializeProjectionTable ()
 

Protected Attributes

std::map< std::string, std::string > theWktToOssimDatumTranslation
 
std::map< std::string, std::string > theWktToOssimProjectionTranslation
 
std::map< std::string, std::string > theOssimToWktDatumTranslation
 
std::map< std::string, std::string > theOssimToWktProjectionTranslation
 

Detailed Description

Definition at line 29 of file ossimOgcWktTranslator.h.

Constructor & Destructor Documentation

◆ ossimOgcWktTranslator()

ossimOgcWktTranslator::ossimOgcWktTranslator ( )

Member Function Documentation

◆ fromOssimKwl()

ossimString ossimOgcWktTranslator::fromOssimKwl ( const ossimKeywordlist kwl,
const char *  prefix = NULL 
) const

Definition at line 56 of file ossimOgcWktTranslator.cpp.

References ossimString::before(), ossimString::c_str(), ossimKeywordNames::CENTRAL_MERIDIAN_KW, ossimString::contains(), ossimKeywordNames::DATUM_KW, ossimString::empty(), EPSG_CODE_MAX, ossimKeywordNames::FALSE_EASTING_KW, ossimKeywordNames::FALSE_EASTING_NORTHING_KW, ossimKeywordNames::FALSE_EASTING_NORTHING_UNITS_KW, ossimKeywordNames::FALSE_NORTHING_KW, ossimKeywordlist::find(), ossimEpsgProjectionDatabase::findProjectionCode(), ossimEpsgProjectionDatabase::findProjectionName(), ossimUnitConversionTool::getValue(), ossimKeywordNames::HEMISPHERE_KW, ossimUnitTypeLut::instance(), ossimEpsgProjectionDatabase::instance(), ossimKeywordNames::ORIGIN_LATITUDE_KW, OSSIM_FEET, OSSIM_METERS, OSSIM_US_SURVEY_FEET, ossimNotify(), ossimNotifyLevel_WARN, ossimKeywordNames::PCS_CODE_KW, ossimKeywordNames::SCALE_FACTOR_KW, ossimUnitConversionTool::setValue(), ossimKeywordNames::STD_PARALLEL_1_KW, ossimKeywordNames::STD_PARALLEL_2_KW, ossimString::toInt(), ossimString::toLong(), ossimDpt::toPoint(), ossimString::trim(), ossimKeywordNames::TYPE_KW, ossimString::upcase(), USER_DEFINED, ossimDpt::x, ossimDpt::y, and ossimKeywordNames::ZONE_KW.

58 {
61 
62  ossimString wktString;
63  OGRSpatialReference oSRS;
64 
65  if(projType == "")
66  {
67  return wktString;
68  }
69 
70  ossimString zone = kwl.find(prefix, ossimKeywordNames::ZONE_KW);
71  ossimString hemisphere = kwl.find(prefix, ossimKeywordNames::HEMISPHERE_KW);
72  ossimString parallel1 = kwl.find(prefix, ossimKeywordNames::STD_PARALLEL_1_KW);
73  ossimString parallel2 = kwl.find(prefix, ossimKeywordNames::STD_PARALLEL_2_KW);
75  ossimString centralMeridian = kwl.find(prefix, ossimKeywordNames::CENTRAL_MERIDIAN_KW);
77  ossimString pcsCode = kwl.find(prefix, ossimKeywordNames::PCS_CODE_KW);
78 
79  ossimDpt falseEastingNorthing;
80  // Get the false easting northing.
81  falseEastingNorthing.x = 0.0;
82  falseEastingNorthing.y = 0.0;
83  const char *lookup =
85  if (lookup)
86  {
87  ossimUnitType units =
89  getEntryNumber(lookup));
90 
92  if (lookup)
93  {
94  ossimDpt eastingNorthing;
95  eastingNorthing.toPoint(std::string(lookup));
96 
97  switch (units)
98  {
99  case OSSIM_METERS:
100  {
101  falseEastingNorthing = eastingNorthing;
102  break;
103  }
104  case OSSIM_FEET:
106  {
108  ut.setValue(eastingNorthing.x, units);
109  falseEastingNorthing.x = ut.getValue(OSSIM_METERS);
110  ut.setValue(eastingNorthing.y, units);
111  falseEastingNorthing.y = ut.getValue(OSSIM_METERS);
112  break;
113  }
114  default:
115  {
116  // Unhandled unit type!
118  << "ossimOgcWktTranslator::fromOssimKwl WARNING!"
119  << "Unhandled unit type for "
121  << ": "
123  getEntryString(units).c_str() )
124  << endl;
125  break;
126  }
127  } // End of switch (units)
128 
129  } // End of if (FALSE_EASTING_NORTHING_KW)
130 
131  } // End of if (FALSE_EASTING_NORTHING_UNITS_KW)
132  else
133  {
134  // BACKWARDS COMPATIBILITY LOOKUPS...
135  lookup = kwl.find(prefix, ossimKeywordNames::FALSE_EASTING_KW);
136  if(lookup)
137  {
138  falseEastingNorthing.x = fabs(ossimString(lookup).toFloat64());
139  }
140 
141  lookup = kwl.find(prefix, ossimKeywordNames::FALSE_NORTHING_KW);
142  if(lookup)
143  {
144  falseEastingNorthing.y = fabs(ossimString(lookup).toFloat64());
145  }
146  }
147 
148  oSRS.SetLinearUnits("Meter", 1.0);
149 
150  int pcsCodeVal = (pcsCode.empty() == false) ? pcsCode.toInt() : EPSG_CODE_MAX;
151 
152  // since approximately ossim version r20036
153  // kwl.find(prefix, ossimKeywordNames::PCS_CODE_KW)
154  // return 0 instead of "" previously.
155  // the to following lines ensure backward compatibility
156  // Since EPSG:0 is not a valid epsg code, the fix is safe
157  // (ref http://spatialreference.org/ref/epsg/)
158  if(pcsCodeVal == 0)
159  pcsCodeVal = EPSG_CODE_MAX;
160 
161  if(pcsCodeVal < EPSG_CODE_MAX)
162  {
163  // ESH 06/2008 -- HACK!!!
164  // If the PCS code is for a HARN state plane and the implied pcs code's units
165  // is feet (us or intl), we find the equivalent code for units of meters.
166  // We're doing this because ArcMap (9.2 and less) doesn't understand the
167  // non-meters HARN codes. However, the units are left unchanged in this
168  // process, so the units can be different than the user-specified pcs code.
169  // ArcMap 9.2 seems to understand the mixed definition just fine.
171  ossimString pcsCodeName = proj_db->findProjectionName(pcsCodeVal);
172  if ( pcsCodeName.contains("HARN") && pcsCodeName.contains("_Feet") )
173  {
174  ossimString feetStr("_Feet");
175  ossimString newPcsCodeName( pcsCodeName.before(feetStr).c_str() );
176  ossimString epsg_spec = proj_db->findProjectionCode(newPcsCodeName);
177  ossim_uint32 new_code = epsg_spec.after(":").toUInt32();
178  if (new_code)
179  pcsCodeVal = new_code;
180  }
181  oSRS.importFromEPSG( pcsCodeVal );
182  }
183  if(projType == "ossimUtmProjection")
184  {
185 #if 0
186  hemisphere = hemisphere.trim().upcase();
187 
188  if(hemisphere != "")
189  {
190  oSRS.SetUTM(zone.toLong(), hemisphere != "S");
191  }
192  else
193  {
194  oSRS.SetUTM(zone.toLong(), true);
195  }
196 #else
197  // ESH 09/2008: Adapting code from ossimTiffWriter.cpp for
198  // converting UTM zone,hemisphere to a PCS code.
199 
200  short gcs = USER_DEFINED;
201 
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;
219  else
220  {
221  if(traceDebug())
222  {
224  << "DATUM = " << datumType << " tag not written " << std::endl
225  << "Please let us know so we can add it" << std::endl;
226  }
227  }
228 
229  int mapZone = zone.toInt();
230  hemisphere = hemisphere.trim().upcase();
231  bool bDoImportFromEPSG = false;
232 
233  switch ( gcs )
234  {
235  case GCS_WGS_84:
236  {
237  if (hemisphere == "N") // Northern hemisphere.
238  {
239  pcsCodeVal = 32600 + mapZone;
240  }
241  else // Southern hemisphere.
242  {
243  pcsCodeVal = 32700 + mapZone;
244  }
245  bDoImportFromEPSG = true;
246  break;
247  }
248 
249  case GCS_WGS_72:
250  {
251  if (hemisphere == "N") // Northern hemisphere.
252  {
253  pcsCodeVal = 32200 + mapZone;
254  }
255  else // Southern hemisphere.
256  {
257  pcsCodeVal = 32300 + mapZone;
258  }
259  bDoImportFromEPSG = true;
260  break;
261  }
262 
263  case GCS_NAD27:
264  {
265  if (hemisphere == "N") // Northern hemisphere.
266  {
267  pcsCodeVal = 26700 + mapZone;
268  }
269  else // Southern hemisphere.
270  {
271  pcsCodeVal = 32000 + mapZone;
272  }
273  bDoImportFromEPSG = true;
274  break;
275  }
276 
277  case GCS_NAD83:
278  {
279  if (hemisphere == "N") // Northern hemisphere.
280  {
281  pcsCodeVal = 26900 + mapZone;
282  }
283  else // Southern hemisphere.
284  {
285  pcsCodeVal = 32100 + mapZone;
286  }
287  bDoImportFromEPSG = true;
288  break;
289  }
290 
291  default:
292  {
293  //***
294  // Use a projection code that does not imply a datum.
295  // See section "6.3.3.2 Projection Codes" for definition.
296  //***
297  if (hemisphere == "N") // Northern hemisphere.
298  {
299  pcsCodeVal = 16000 + mapZone;
300  }
301  else // Southern hemisphere.
302  {
303  pcsCodeVal = 16100 + abs(mapZone);
304  }
305  break;
306  }
307  } // End of "switch ( gcs )"
308 
309  if ( bDoImportFromEPSG == true )
310  oSRS.importFromEPSG( pcsCodeVal );
311  else
312  {
313  if(hemisphere != "")
314  {
315  oSRS.SetUTM(zone.toLong(), hemisphere != "S");
316  }
317  else
318  {
319  oSRS.SetUTM(zone.toLong(), true);
320  }
321  }
322 #endif
323  }
324  else if(projType == "ossimLlxyProjection")
325  {
326  OGRSpatialReference oGeogCS;
327 
328  oGeogCS.SetEquirectangular(0.0,
329  0.0,
330  0.0,
331  0.0);
332  oGeogCS.SetAngularUnits(SRS_UA_DEGREE, atof(SRS_UA_DEGREE_CONV));
333 
334  oSRS.CopyGeogCSFrom( &oGeogCS );
335  }
336  else if(projType == "ossimEquDistCylProjection")
337  {
338  OGRSpatialReference oGeogCS;
339 
340  oGeogCS.SetEquirectangular(originLat.toDouble(),
341  centralMeridian.toDouble(),
342  falseEastingNorthing.x,
343  falseEastingNorthing.y);
344  oGeogCS.SetAngularUnits(SRS_UA_DEGREE, atof(SRS_UA_DEGREE_CONV));
345 
346  oSRS.CopyGeogCSFrom( &oGeogCS );
347  }
348  else if(projType == "ossimSinusoidalProjection")
349  {
350  oSRS.SetSinusoidal(centralMeridian.toDouble(),
351  falseEastingNorthing.x,
352  falseEastingNorthing.y);
353  }
354  else if(projType == "ossimCylEquAreaProjection")
355  {
356  oSRS.SetCEA(originLat.toDouble(),
357  centralMeridian.toDouble(),
358  falseEastingNorthing.x,
359  falseEastingNorthing.y);
360  }
361  else if(projType == "ossimCassiniProjection")
362  {
363  oSRS.SetCS(originLat.toDouble(),
364  centralMeridian.toDouble(),
365  falseEastingNorthing.x,
366  falseEastingNorthing.y);
367  }
368  else if(projType == "ossimAlbersProjection")
369  {
370  oSRS.SetACEA(parallel1.toDouble(),
371  parallel2.toDouble(),
372  originLat.toDouble(),
373  centralMeridian.toDouble(),
374  falseEastingNorthing.x,
375  falseEastingNorthing.y);
376  }
377  else if(projType == "ossimAzimEquDistProjection")
378  {
379  oSRS.SetAE(originLat.toDouble(),
380  centralMeridian.toDouble(),
381  falseEastingNorthing.x,
382  falseEastingNorthing.y);
383  }
384  else if(projType == "ossimEckert4Projection")
385  {
386  oSRS.SetEckertIV(centralMeridian.toDouble(),
387  falseEastingNorthing.x,
388  falseEastingNorthing.y);
389  }
390  else if(projType == "ossimEckert6Projection")
391  {
392  oSRS.SetEckertVI(centralMeridian.toDouble(),
393  falseEastingNorthing.x,
394  falseEastingNorthing.y);
395  }
396  else if(projType == "ossimGnomonicProjection")
397  {
398  oSRS.SetGnomonic(originLat.toDouble(),
399  centralMeridian.toDouble(),
400  falseEastingNorthing.x,
401  falseEastingNorthing.y);
402  }
403  else if(projType == "ossimLambertConformalConicProjection")
404  {
405  oSRS.SetLCC(parallel1.toDouble(),
406  parallel2.toDouble(),
407  originLat.toDouble(),
408  centralMeridian.toDouble(),
409  falseEastingNorthing.x,
410  falseEastingNorthing.y);
411  }
412  else if(projType == "ossimVanDerGrintenProjection")
413  {
414  oSRS.SetVDG(centralMeridian.toDouble(),
415  falseEastingNorthing.x,
416  falseEastingNorthing.y);
417  }
418  else if(projType == "ossimMillerProjection")
419  {
420  oSRS.SetMC(originLat.toDouble(),
421  centralMeridian.toDouble(),
422  falseEastingNorthing.x,
423  falseEastingNorthing.y);
424  }
425  else if(projType == "ossimMercatorProjection")
426  {
427  oSRS.SetMercator(originLat.toDouble(),
428  centralMeridian.toDouble(),
429  scale.toDouble(),
430  falseEastingNorthing.x,
431  falseEastingNorthing.y);
432  }
433  else if(projType == "ossimMollweidProjection")
434  {
435  oSRS.SetMollweide(centralMeridian.toDouble(),
436  falseEastingNorthing.x,
437  falseEastingNorthing.y);
438  }
439  else if(projType == "ossimNewZealandMapGridProjection")
440  {
441  oSRS.SetNZMG(originLat.toDouble(),
442  centralMeridian.toDouble(),
443  falseEastingNorthing.x,
444  falseEastingNorthing.y);
445  }
446  else if(projType == "ossimOrthoGraphicProjection")
447  {
448  oSRS.SetOrthographic(originLat.toDouble(),
449  centralMeridian.toDouble(),
450  falseEastingNorthing.x,
451  falseEastingNorthing.y);
452  }
453  else if(projType == "ossimPolarStereoProjection")
454  {
455  oSRS.SetPS(originLat.toDouble(),
456  centralMeridian.toDouble(),
457  scale.toDouble(),
458  falseEastingNorthing.x,
459  falseEastingNorthing.y);
460  }
461  else if(projType == "ossimPolyconicProjectio")
462  {
463  oSRS.SetPolyconic(originLat.toDouble(),
464  centralMeridian.toDouble(),
465  falseEastingNorthing.x,
466  falseEastingNorthing.y);
467  }
468  else if(projType == "ossimStereographicProjection")
469  {
470  oSRS.SetStereographic(originLat.toDouble(),
471  centralMeridian.toDouble(),
472  scale.toDouble(),
473  falseEastingNorthing.x,
474  falseEastingNorthing.y);
475  }
476  else if(projType == "ossimTransMercatorProjection")
477  {
478  oSRS.SetTM(originLat.toDouble(),
479  centralMeridian.toDouble(),
480  scale.toDouble(),
481  falseEastingNorthing.x,
482  falseEastingNorthing.y);
483  }
484  else
485  {
486  cerr << "ossimOgcWktTranslator::fromOssimKwl:\n"
487  << "Projection translation for "
488  << projType
489  << " not supported "
490  << endl;
491  }
492 
493  if(pcsCodeVal >= EPSG_CODE_MAX)
494  {
495  datumType = datumType.upcase();
496 
497  if(datumType == "WGE")
498  {
499  oSRS.SetWellKnownGeogCS("WGS84");
500  }
501  else if(datumType == "WGD")
502  {
503  oSRS.SetWellKnownGeogCS("WGS72");
504  }
505  else if(datumType == "NAS-C") //1927
506  {
507  oSRS.SetWellKnownGeogCS("NAD27");
508  }
509  else if(datumType == "NAS") //1927
510  {
511  oSRS.SetWellKnownGeogCS("NAD27");
512  }
513  else if(datumType == "NAR-C") // 1983
514  {
515  oSRS.SetWellKnownGeogCS("NAD83");
516  }
517  else if(datumType == "NAR") // 1983
518  {
519  oSRS.SetWellKnownGeogCS("NAD83");
520  }
521  else if(datumType == "NTF")
522  {
523  oSRS.SetWellKnownGeogCS("EPSG:4275");
524  }
525  else
526  {
527  cerr << "ossimOgcWktTranslator::fromOssimKwl: Datum translation for "
528  << datumType
529  <<" not supported"
530  << endl;
531  }
532  }
533 
534  char* exportString = NULL;
535  oSRS.exportToWkt(&exportString);
536 
537  if(exportString)
538  {
539  wktString = exportString;
540  OGRFree(exportString);
541  }
542 
543  return wktString;
544 
545 }
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...
double getValue(ossimUnitType unitType=OSSIM_METERS) const
static ossimString upcase(const ossimString &aString)
Definition: ossimString.cpp:34
static const char * DATUM_KW
static const char * FALSE_EASTING_NORTHING_UNITS_KW
static const char * CENTRAL_MERIDIAN_KW
ossimUnitType
const char * find(const char *key) const
void setValue(double value, ossimUnitType unitType=OSSIM_METERS)
double y
Definition: ossimDpt.h:165
bool contains(char aChar) const
Definition: ossimString.h:58
Projection Database for coded projections defined in database files and specified via some coordinate...
ossim_uint32 findProjectionCode(const ossimString &projection_name) const
Given a projection name, assigns the group (e.g., "EPSG") and code of the projection.
#define abs(a)
Definition: auxiliary.h:74
static const char * TYPE_KW
#define EPSG_CODE_MAX
static const char * ZONE_KW
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.
Definition: ossimDpt.cpp:192
double toDouble() const
static const char * STD_PARALLEL_1_KW
static const char * FALSE_EASTING_KW
#define USER_DEFINED
static const char * FALSE_EASTING_NORTHING_KW
static const char * ORIGIN_LATITUDE_KW
static const char * PCS_CODE_KW
long toLong() const
toLong&#39;s deprecated, please use the toInts...
static const char * HEMISPHERE_KW
double x
Definition: ossimDpt.h:164
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool empty() const
Definition: ossimString.h:411
static const char * SCALE_FACTOR_KW
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&#39;t understand the non-me...
int toInt() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ initializeDatumTable()

void ossimOgcWktTranslator::initializeDatumTable ( )
protected

Definition at line 952 of file ossimOgcWktTranslator.cpp.

References theOssimToWktDatumTranslation, and theWktToOssimDatumTranslation.

Referenced by ossimOgcWktTranslator().

953 {
954 // theWktToOssimDatumTranslation.insert(make_pair(ossimString("North_American_Datum_1927"),
955 // ossimString("NAS-C")));
956 
957 // theWktToOssimDatumTranslation.insert(make_pair(ossimString("North_American_Datum_1983"),
958 // ossimString("NAR-C")));
959 // theWktToOssimDatumTranslation.insert(make_pair(ossimString("WGS_1984"),
960 // ossimString("WGE")));
961 // theWktToOssimDatumTranslation.insert(make_pair(ossimString("OSGB_1936"),
962 // ossimString("OSGB_1936")));
963 
964  theOssimToWktDatumTranslation.insert(make_pair(std::string("NAS-C"),
965  std::string("North_American_Datum_1927")));
966  theOssimToWktDatumTranslation.insert(make_pair(std::string("NAR-C"),
967  std::string("North_American_Datum_1983")));
968  theOssimToWktDatumTranslation.insert(make_pair(std::string("NAS"),
969  std::string("North_American_Datum_1927")));
970  theOssimToWktDatumTranslation.insert(make_pair(std::string("NAR"),
971  std::string("North_American_Datum_1983")));
972  theOssimToWktDatumTranslation.insert(make_pair(std::string("WGE"),
973  std::string("WGS_1984")));
974  theWktToOssimDatumTranslation.insert(make_pair(std::string("OSGB_1936"),
975  std::string("OGB-B")));
976  theWktToOssimDatumTranslation.insert(make_pair(std::string("Nouvelle_Triangulation_Francaise"),
977  std::string("NTF")));
978 }
std::map< std::string, std::string > theOssimToWktDatumTranslation
std::map< std::string, std::string > theWktToOssimDatumTranslation

◆ initializeProjectionTable()

void ossimOgcWktTranslator::initializeProjectionTable ( )
protected

Definition at line 980 of file ossimOgcWktTranslator.cpp.

References theOssimToWktProjectionTranslation, and theWktToOssimProjectionTranslation.

Referenced by ossimOgcWktTranslator().

981 {
982  theWktToOssimProjectionTranslation.insert(make_pair(std::string(SRS_PT_TRANSVERSE_MERCATOR),
983  std::string("ossimTransMercatorProjection")));
984  theWktToOssimProjectionTranslation.insert(make_pair(std::string(SRS_PT_EQUIRECTANGULAR),
985  std::string("ossimEquDistCylProjection")));
986  theWktToOssimProjectionTranslation.insert(make_pair(std::string(SRS_PT_ALBERS_CONIC_EQUAL_AREA),
987  std::string("ossimAlbersProjection")));
988  theWktToOssimProjectionTranslation.insert(make_pair(std::string(SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP),
989  std::string("ossimLambertConformalConicProjection")));
990  theWktToOssimProjectionTranslation.insert(make_pair(std::string(SRS_PT_SINUSOIDAL),
991  std::string("ossimSinusoidalProjection")));
992  theWktToOssimProjectionTranslation.insert(make_pair(std::string(SRS_PT_MERCATOR_1SP),
993  std::string("ossimMercatorProjection")));
994  theOssimToWktProjectionTranslation.insert(make_pair(std::string("ossimTransMercatorProjection"),
995  std::string(SRS_PT_TRANSVERSE_MERCATOR)));
996  theOssimToWktProjectionTranslation.insert(make_pair(std::string("ossimEquDistCylProjection"),
997  std::string(SRS_PT_EQUIRECTANGULAR)));
998  theOssimToWktProjectionTranslation.insert(make_pair(std::string("ossimAlbersProjection"),
999  std::string(SRS_PT_ALBERS_CONIC_EQUAL_AREA)));
1000  theOssimToWktProjectionTranslation.insert(make_pair(std::string("ossimLambertConformalConicProjection"),
1001  std::string(SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP)));
1002  theOssimToWktProjectionTranslation.insert(make_pair(std::string("ossimSinusoidalProjection"),
1003  std::string(SRS_PT_SINUSOIDAL)));
1004  theOssimToWktProjectionTranslation.insert(make_pair(std::string("ossimMercatorProjection"),
1005  std::string(SRS_PT_MERCATOR_1SP)));
1006 
1007 }
std::map< std::string, std::string > theWktToOssimProjectionTranslation
std::map< std::string, std::string > theOssimToWktProjectionTranslation

◆ ossimToWktDatum()

ossimString ossimOgcWktTranslator::ossimToWktDatum ( const ossimString datum) const

Definition at line 1047 of file ossimOgcWktTranslator.cpp.

References theOssimToWktDatumTranslation.

1048 {
1049  ossimString result;
1050  map<std::string, std::string>::const_iterator i = theOssimToWktDatumTranslation.find(datum);
1051  if(i != theOssimToWktDatumTranslation.end())
1052  {
1053  result = (*i).second;
1054  }
1055  return result;
1056 }
std::map< std::string, std::string > theOssimToWktDatumTranslation

◆ ossimToWktProjection()

ossimString ossimOgcWktTranslator::ossimToWktProjection ( const ossimString projection) const

Definition at line 1070 of file ossimOgcWktTranslator.cpp.

References theOssimToWktProjectionTranslation.

1071 {
1072  ossimString result;
1073  map<std::string, std::string>::const_iterator i =
1075  if(i != theOssimToWktProjectionTranslation.end())
1076  {
1077  result = (*i).second;
1078  }
1079  return result;
1080 }
std::map< std::string, std::string > theOssimToWktProjectionTranslation

◆ toOssimKwl()

bool ossimOgcWktTranslator::toOssimKwl ( const ossimString wktString,
ossimKeywordlist kwl,
const char *  prefix = NULL 
) const

Definition at line 547 of file ossimOgcWktTranslator.cpp.

551 {
552  static const char MODULE[] = "ossimOgcWktTranslator::toOssimKwl";
553 
554  if(traceDebug())
555  {
556  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n";
557  }
558 
559  const char* wkt = wktString.c_str();
560 
561  OGRSpatialReferenceH hSRS = NULL;
562  ossimDpt falseEastingNorthing;
563 
564  // Translate the WKT into an OGRSpatialReference.
565  hSRS = OSRNewSpatialReference(NULL);
566  if( OSRImportFromWkt( hSRS, (char **) &wkt ) != OGRERR_NONE )
567  {
568  OSRDestroySpatialReference( hSRS );
569  return false;
570  }
571 
572  // Determine if State Plane Coordinate System
573  ossimString ossimProj = "";
574  const char* epsg_code = OSRGetAttrValue( hSRS, "AUTHORITY", 1 );
575 
576  if(traceDebug())
577  {
579  << "epsg_code: " << (epsg_code?epsg_code:"null") << "\n";
580  }
581 
582  //---
583  // Extract Units
584  // ESH 11/2008: Check for geographic system when setting default units.
585  // If geographic, use degrees.
586  //---
587 // const char* units = OSRGetAttrValue( hSRS, "UNIT", 0 );
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++)
592  {
593  OGR_SRSNode* curChild = node->GetChild(i);
594  if (strcmp(curChild->GetValue(), "UNIT") == 0)
595  {
596  units = curChild->GetChild(0)->GetValue();
597  }
598  }
599 
600  if(traceDebug())
601  {
603  << "units: " << (units?units:"null") << "\n";
604  }
605 
606  ossimString ossim_units;
607  bool bGeog = OSRIsGeographic(hSRS);
608  if ( bGeog == false )
609  {
610  ossim_units = "meters";
611  if ( units != NULL )
612  {
613  // Down case to avoid case mismatch.
614  ossimString s = units;
615  s.downcase();
616 
617  if( ( s == ossimString("us survey foot") ) ||
618  ( s == ossimString("u.s. foot") ) ||
619  ( s == ossimString("foot_us") ) )
620  {
621  ossim_units = "us_survey_feet";
622  }
623  else if( s == ossimString("degree") )
624  {
625  ossim_units = "degrees";
626  }
627  else if( ( s == ossimString("meter") ) ||
628  ( s == ossimString("metre") ) )
629  {
630  ossim_units = "meters";
631  }
632  }
633  }
634  else
635  {
636  ossim_units = "degrees";
637  }
638 
639  if(traceDebug())
640  {
642  << "ossim_units: " << ossim_units << "\n";
643  }
644 
645  // OLK 05/2010 -- ossimProj string was never being set to projection type (except state plane
646  // which is not even a projection type)! This was a bug. Using EPSG factory to attempt to get
647  // proper projection:
648  if (epsg_code)
649  {
650  ossimString epsg_spec ("EPSG:");
651  epsg_spec += ossimString::toString(ossimString(epsg_code));
653  if (proj)
654  ossimProj = proj->getClassName();
655  delete proj;
656  }
657 
658  if(ossimProj == "")
659  {
660  // Determine which other Projection System is represented.
661  const char* pszProjection = OSRGetAttrValue( hSRS, "PROJECTION", 0 );
662  if(pszProjection)
663  {
664  ossimProj = wktToOssimProjection(pszProjection);
665  }
666  else
667  {
668  ossimString localCs = OSRGetAttrValue( hSRS, "LOCAL_CS", 0 );
669  localCs = localCs.upcase();
670  if(localCs == "GREATBRITAIN_GRID")
671  {
672  ossimProj = "ossimBngProjection";
673  }
674  else if (ossim_units.contains("degree"))
675  {
676  // Assumption...
677  ossimProj = "ossimEquDistCylProjection";
678  }
679  }
680  }
681 
682  // ESH 11/2008: Ticket #479, if we've got a geographic coordsys
683  // make sure the units are set to degrees.
684  if(ossimProj == "ossimEquDistCylProjection" )
685  ossim_units = "degrees";
686 
687  // ESH 11/2008: Ticket #479, don't set units until we've checked
688  // whether or not the projection was updated.
689  kwl.add(prefix, ossimKeywordNames::UNITS_KW, ossim_units, true);
690 
691  if (traceDebug())
692  {
694  << MODULE << "DEBUG:"
695  << "\nossimProj = " << ossimProj << endl;
696  }
697 
698  kwl.add(prefix, ossimKeywordNames::TYPE_KW, ossimProj.c_str(), true);
699 
700  falseEastingNorthing.x = OSRGetProjParm(hSRS, SRS_PP_FALSE_EASTING, 0.0, NULL);
701  falseEastingNorthing.y = OSRGetProjParm(hSRS, SRS_PP_FALSE_NORTHING, 0.0, NULL);
702  if (epsg_code)
703  {
704  kwl.add(prefix, ossimKeywordNames::PCS_CODE_KW, epsg_code, true);
705  }
706  if(ossimProj == "ossimBngProjection")
707  {
708  kwl.add(prefix,
710  "ossimBngProjection",
711  true);
712  }
713  else if(ossimProj == "ossimCylEquAreaProjection")
714  {
715  kwl.add(prefix,
717  OSRGetProjParm(hSRS, SRS_PP_STANDARD_PARALLEL_1, 0.0, NULL),
718  true);
719 
720  kwl.add(prefix,
722  OSRGetProjParm(hSRS, SRS_PP_STANDARD_PARALLEL_1, 0.0, NULL),
723  true);
724 
725  ossimUnitType units =
727  getEntryNumber(ossim_units.c_str()));
728  if ( units == OSSIM_METERS ||
729  units == OSSIM_FEET ||
730  units == OSSIM_US_SURVEY_FEET )
731  {
732  kwl.add(prefix,
734  falseEastingNorthing.toString(),
735  true);
736  kwl.add(prefix,
738  ossim_units,
739  true);
740  }
741  }
742  else if(ossimProj == "ossimEquDistCylProjection")
743  {
744  kwl.add(prefix,
746  "ossimEquDistCylProjection",
747  true);
748 
749  ossimUnitType units =
751  getEntryNumber(ossim_units.c_str()));
752  if ( units == OSSIM_METERS ||
753  units == OSSIM_FEET ||
754  units == OSSIM_US_SURVEY_FEET )
755  {
756  kwl.add(prefix,
758  falseEastingNorthing.toString(),
759  true);
760  kwl.add(prefix,
762  ossim_units,
763  true);
764  }
765 
766  kwl.add(prefix,
768  OSRGetProjParm(hSRS, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL),
769  true);
770  kwl.add(prefix,
772  OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL),
773  true);
774  }
775  else if( (ossimProj == "ossimLambertConformalConicProjection") ||
776  (ossimProj == "ossimAlbersProjection") )
777  {
778  kwl.add(prefix,
780  ossimProj.c_str(),
781  true);
782  kwl.add(prefix,
784  falseEastingNorthing.toString(),
785  true);
786  kwl.add(prefix,
788  ossim_units,
789  true);
790  kwl.add(prefix,
792  OSRGetProjParm(hSRS, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL),
793  true);
794  kwl.add(prefix,
796  OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL),
797  true);
798  kwl.add(prefix,
800  OSRGetProjParm(hSRS, SRS_PP_STANDARD_PARALLEL_1, 0.0, NULL),
801  true);
802  kwl.add(prefix,
804  OSRGetProjParm(hSRS, SRS_PP_STANDARD_PARALLEL_2, 0.0, NULL),
805  true);
806  }
807  else if(ossimProj == "ossimMercatorProjection")
808  {
809  kwl.add(prefix,
811  "ossimMercatorProjection",
812  true);
813  kwl.add(prefix,
815  OSRGetProjParm(hSRS, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL),
816  true);
817  kwl.add(prefix,
819  OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL),
820  true);
821  kwl.add(prefix,
823  falseEastingNorthing.toString(),
824  true);
825  kwl.add(prefix,
827  ossim_units,
828  true);
829  }
830  else if(ossimProj == "ossimSinusoidalProjection")
831  {
832  kwl.add(prefix,
834  "ossimSinusoidalProjection",
835  true);
836  kwl.add(prefix,
838  OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL),
839  true);
840  kwl.add(prefix,
842  falseEastingNorthing.toString(),
843  true);
844  kwl.add(prefix,
846  ossim_units,
847  true);
848  }
849  else if(ossimProj == "ossimTransMercatorProjection")
850  {
851  int bNorth;
852  int nZone = OSRGetUTMZone( hSRS, &bNorth );
853  if( nZone != 0 )
854  {
855  kwl.add(prefix,
857  "ossimUtmProjection",
858  true);
859 
860  kwl.add(prefix,
862  nZone,
863  true);
864  if( bNorth )
865  {
866  kwl.add(prefix, ossimKeywordNames::HEMISPHERE_KW, "N", true);
867  }
868  else
869  {
870  kwl.add(prefix, ossimKeywordNames::HEMISPHERE_KW, "S", true);
871  }
872  }
873  else
874  {
875  kwl.add(prefix,
877  "ossimTransMercatorProjection",
878  true);
879  kwl.add(prefix,
881  OSRGetProjParm(hSRS, SRS_PP_SCALE_FACTOR, 1.0, NULL),
882  true);
883 
884  kwl.add(prefix,
886  OSRGetProjParm(hSRS, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL),
887  true);
888  kwl.add(prefix,
890  OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL),
891  true);
892  kwl.add(prefix,
894  falseEastingNorthing.toString(),
895  true);
896  kwl.add(prefix,
898  ossim_units,
899  true);
900  }
901  }
902  else
903  {
904  if (traceDebug())
905  {
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"
911  << wkt << endl;
912  }
913  return false;
914  }
915 
916  // extract out the datum
917  //
918  const char *datum = OSRGetAttrValue( hSRS, "DATUM", 0 );
919  ossimString oDatum = "WGE";
920 
921  if( datum )
922  {
923  oDatum = wktToOssimDatum(datum);
924  if(oDatum == "")
925  {
926  oDatum = "WGE";
927  }
928  }
929 
930  // Trouble with ESPG 3857
931  // The ellipsoid used by ossim is the WGS84 one with minor and major axis differs.
932  // We need to build our own projection in this case.
933  if( oDatum == "WGE" && ossimString(epsg_code) == "3857" )
934  {
935  oDatum = "6055";
936  }
937  kwl.add(prefix, ossimKeywordNames::DATUM_KW, oDatum, true);
938 
939  OSRDestroySpatialReference( hSRS );
940 
941  if (traceDebug())
942  {
944  << MODULE << " exit status = true"
945  << std::endl;
946  }
947 
948  return true;
949 }
static ossimString upcase(const ossimString &aString)
Definition: ossimString.cpp:34
static const char * DATUM_KW
static const char * FALSE_EASTING_NORTHING_UNITS_KW
static const char * CENTRAL_MERIDIAN_KW
ossimUnitType
double y
Definition: ossimDpt.h:165
bool contains(char aChar) const
Definition: ossimString.h:58
static ossimString toString(bool aValue)
Numeric to string methods.
virtual ossimString getClassName() const
Definition: ossimObject.cpp:64
ossimString wktToOssimDatum(const ossimString &datum) const
static const char * TYPE_KW
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
static const char * ZONE_KW
ossimString wktToOssimProjection(const ossimString &projection) const
static const char * STD_PARALLEL_1_KW
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
static const char * FALSE_EASTING_NORTHING_KW
static const char * ORIGIN_LATITUDE_KW
static const char * UNITS_KW
static const char * PCS_CODE_KW
ossimString toString(ossim_uint32 precision=15) const
Definition: ossimDpt.cpp:160
static const char * HEMISPHERE_KW
double x
Definition: ossimDpt.h:164
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
virtual ossimProjection * createProjection(const ossimFilename &filename, ossim_uint32 entryIdx) const
STUB. Not implemented.
static const char * SCALE_FACTOR_KW
static const char * STD_PARALLEL_2_KW
static ossimUnitTypeLut * instance()
Returns the static instance of an ossimUnitTypeLut object.
static ossimEpsgProjectionFactory * instance()
Implements singleton pattern.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ wktToOssimDatum()

ossimString ossimOgcWktTranslator::wktToOssimDatum ( const ossimString datum) const

Returns the empty string if the datum is not found

Definition at line 1009 of file ossimOgcWktTranslator.cpp.

References ossimString::contains().

1010 {
1011  if(datum.contains("North_American_Datum_1927"))
1012  {
1013  return "NAS-C";
1014  }
1015  if(datum.contains("North_American_Datum_1983"))
1016  {
1017  return "NAR-C";
1018  }
1019  if(datum.contains("WGS_1984"))
1020  {
1021  return "WGE";
1022  }
1023  if(datum.contains("OSGA"))
1024  {
1025  return "OGB-A";
1026  }
1027  if(datum.contains("OSGB"))
1028  {
1029  return "OGB-B";
1030  }
1031  if(datum.contains("OSGC"))
1032  {
1033  return "OGB-C";
1034  }
1035  if(datum.contains("OSGD"))
1036  {
1037  return "OGB-D";
1038  }
1039  if(datum.contains("Nouvelle_Triangulation_Francaise"))
1040  {
1041  return "NTF";
1042  }
1043 
1044  return "";
1045 }
bool contains(char aChar) const
Definition: ossimString.h:58

◆ wktToOssimProjection()

ossimString ossimOgcWktTranslator::wktToOssimProjection ( const ossimString projection) const

Definition at line 1058 of file ossimOgcWktTranslator.cpp.

References theWktToOssimProjectionTranslation.

1059 {
1060  std::string result;
1061  map<std::string, std::string>::const_iterator i =
1063  if(i != theWktToOssimProjectionTranslation.end())
1064  {
1065  result = (*i).second;
1066  }
1067  return result;
1068 }
std::map< std::string, std::string > theWktToOssimProjectionTranslation

Member Data Documentation

◆ theOssimToWktDatumTranslation

std::map<std::string, std::string> ossimOgcWktTranslator::theOssimToWktDatumTranslation
protected

Definition at line 55 of file ossimOgcWktTranslator.h.

Referenced by initializeDatumTable(), and ossimToWktDatum().

◆ theOssimToWktProjectionTranslation

std::map<std::string, std::string> ossimOgcWktTranslator::theOssimToWktProjectionTranslation
protected

Definition at line 56 of file ossimOgcWktTranslator.h.

Referenced by initializeProjectionTable(), and ossimToWktProjection().

◆ theWktToOssimDatumTranslation

std::map<std::string, std::string> ossimOgcWktTranslator::theWktToOssimDatumTranslation
protected

Definition at line 52 of file ossimOgcWktTranslator.h.

Referenced by initializeDatumTable().

◆ theWktToOssimProjectionTranslation

std::map<std::string, std::string> ossimOgcWktTranslator::theWktToOssimProjectionTranslation
protected

Definition at line 53 of file ossimOgcWktTranslator.h.

Referenced by initializeProjectionTable(), and wktToOssimProjection().


The documentation for this class was generated from the following files: