OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimStatePlaneProjectionInfo.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts
6 //*******************************************************************
7 // $Id: ossimStatePlaneProjectionInfo.cpp 17815 2010-08-03 13:23:14Z dburken $
8 
16 #include <ossim/base/ossimNotify.h>
18 
20  const std::string& name,
21  int pcsCode,
22  const std::string& projName,
23  const std::string& param1,
24  const std::string& param2,
25  const std::string& param3,
26  const std::string& param4,
27  double falseEast,
28  double falseNorth,
29  const std::string& units,
30  const std::string& datumName)
31  :
32  thePcsCode (pcsCode),
33  theName (name),
34  theProjectionName (projName),
35  theDatum (0),
36  theOriginLat (param1),
37  theOriginLon (param2),
38  theOrigin (),
39  theParameter3 (0.0),
40  theParameter4 (0.0),
41  theFalseEasting (falseEast),
42  theFalseNorthing (falseNorth),
43  theScaleFactor (0.0),
44  theUnits (OSSIM_UNIT_UNKNOWN)
45 
46 {
47  //---
48  // If the projection name is abreviated, expand to be ossim class name.
49  //---
50  if (projName == "tm")
51  {
52  theProjectionName = "ossimTransMercatorProjection";
53  }
54  else if (projName == "lcc")
55  {
56  theProjectionName = "ossimLambertConformalConicProjection";
57  }
58 
59  // Set the projection specific stuff.
60  if (theProjectionName == "ossimTransMercatorProjection")
61  {
63  if(fabs(theParameter3) > FLT_EPSILON)
64  {
65  theScaleFactor = 1.0 - (1.0 / theParameter3);
66  }
67  else
68  {
69  theScaleFactor = 1.0;
70  }
71  }
72  else if (theProjectionName == "ossimLambertConformalConicProjection")
73  {
74  theParameter3 = ossimDms(param3).getDegrees();
75  theParameter4 = ossimDms(param4).getDegrees();
76  }
77  else
78  {
80  << "ossimStatePlaneProjectionInfo unhandled projection type: "
81  << projName << std::endl;
82  }
83 
85  if (!theDatum)
86  {
88  << "ossimStatePlaneProjectionInfo unhandled datum type: "
89  << datumName << std::endl;
90  }
91 
94  0,
95  theDatum);
96 
97  theUnits = static_cast<ossimUnitType>(
99 
100  // Currently only handle meters and us_survey_feet.
101  if ( (theUnits != OSSIM_METERS) &&
103  (theUnits != OSSIM_FEET) )
104  {
106  << "ossimStatePlaneProjectionInfo unhandled unit type: "
107  << units.c_str()
108  << std::endl;
109  }
110 }
111 
113 {
114  return thePcsCode;
115 }
116 
118 {
119  return theName;
120 }
121 
123 {
124  return theProjectionName;
125 }
126 
128 {
129  return theOriginLat.getDegrees();
130 }
131 
133 {
134  return theOriginLon.getDegrees();
135 }
136 
138 {
139  return theDatum;
140 }
141 
143 {
144  return theOrigin;
145 }
146 
148 {
149  return theParameter3;
150 }
151 
153 {
154  return theParameter4;
155 }
156 
158 {
159  return theFalseEasting;
160 }
161 
163 {
164  return theFalseNorthing;
165 }
166 
168 {
169  return theScaleFactor;
170 }
171 
173 {
175 }
176 
178 {
179  if(pcsCode == thePcsCode)
180  {
181  return true;
182  }
183 
184  return false;
185 }
186 
188 {
189  double result = theFalseEasting;
190  switch (theUnits)
191  {
193  result *= US_METERS_PER_FT;
194  break;
195  case OSSIM_FEET:
196  result *= MTRS_PER_FT;
197  break;
198  default:
199  break;
200  }
201  return result;
202 }
203 
205 {
206  double result = theFalseNorthing;
207  switch (theUnits)
208  {
210  result *= US_METERS_PER_FT;
211  break;
212  case OSSIM_FEET:
213  result *= MTRS_PER_FT;
214  break;
215  default:
216  break;
217  }
218  return result;
219 }
220 
222  ossimKeywordlist& kwl, const char* prefix)const
223 {
224  kwl.add(prefix,
226  thePcsCode,
227  true);
228 
229  kwl.add(prefix,
231  (ossimUnitTypeLut::instance()->getEntryString(theUnits)),
232  true);
233 
235 
236  kwl.add(prefix,
238  pt.toString().c_str(),
239  true);
240 
241  kwl.add(prefix,
243  origin().latd(),
244  true);
245 
246  kwl.add(prefix,
248  origin().lond(),
249  true);
250 
251  kwl.add(prefix,
253  projName(),
254  true);
255 
256  if(theDatum)
257  {
258 
259  kwl.add(prefix,
261  theDatum->code(),
262  true);
263  }
264 
266  {
267  kwl.add(prefix,
269  parallel1(),
270  true);
271  kwl.add(prefix,
273  parallel2(),
274  true);
275  }
276  else
277  {
278  kwl.add(prefix,
281  true);
282  }
283 }
284 
286 {
287  return theUnits;
288 }
289 
291  const ossimMapProjection* proj) const
292 {
293  if (!proj)
294  {
295  return false;
296  }
297 
298 #if 0
299  cout << "\ntheProjectionName: " << theProjectionName
300  << "\nclassName: " << proj->getClassName()
301  << "\ntheOrigin: " << theOrigin
302  << "\nproj->origin(): "<< proj->origin()
303  << "\nfalseEastingInMeters(): "<< falseEastingInMeters()
304  << "\nproj->getFalseEasting(): " << proj->getFalseEasting()
305  << "\nfalseNorthingInMeters(): " << falseNorthingInMeters()
306  << "\nproj->getFalseNorthing(): " << proj->getFalseNorthing()
307  << "\ndatum: " << theDatum->code()
308  << endl;
309 #endif
310 
311  if ( (theProjectionName != proj->getClassName()) ||
312  ( (theOrigin == proj->origin()) == false) ||
313  (falseEastingInMeters() != proj->getFalseEasting()) ||
314  (falseNorthingInMeters() != proj->getFalseNorthing()) )
315  {
316  return false;
317  }
318 
319  //---
320  // NOTE: Going from double to strings, radians to degrees and back is
321  // causing a wiggle in the floating point values; hence the
322  // ALLOWABLE_VARIANCE.
323  //---
324  const double ALLOWABLE_VARIANCE = 0.00000000000001;
325 
326  if (theProjectionName == "ossimTransMercatorProjection")
327  {
329  proj);
330  if (!tm)
331  {
332  return false;
333  }
334  double d1 = fabs(theScaleFactor - tm->getScaleFactor());
335  if (d1 < ALLOWABLE_VARIANCE)
336  {
337  return true;
338  }
339  }
340  else // Lambert.
341  {
344  if (!lam)
345  {
346  return false;
347  }
348  double d1 = fabs(parallel1() - lam->getStandardParallel1());
349  double d2 = fabs(parallel2() - lam->getStandardParallel2());
350  if ( (d1 < ALLOWABLE_VARIANCE) && (d2 < ALLOWABLE_VARIANCE) )
351  {
352  return true;
353  }
354  }
355 
356  return false;
357 }
358 
360  const ossimStatePlaneProjectionInfo& thePlane)
361 {
363  {
364  return os << "ossimStatePlaneProjection: "
365  << "\nName: " << thePlane.name()
366  << "\nPcsCode: " << thePlane.code()
367  << "\norigin: " << thePlane.origin()
368  << "\nscale factor: " << setprecision(12)
369  << thePlane.scaleFactor()
370  << "\nfalseEasting: " << thePlane.falseEasting()
371  << "\nfalseNorthing: " << thePlane.falseNorthing()
372  << endl;
373  }
374  else // Lambert
375  {
376  return os << "ossimStatePlaneProjection: "
377  << "\nName: " << thePlane.name()
378  << "\nPcsCode: " << thePlane.code()
379  << "\norigin: " << thePlane.origin()
380  << "\nphi1: "
381  << setprecision(12) << thePlane.parallel1()
382  << "\nphi2: "
383  << setprecision(12) << thePlane.parallel2()
384  << "\nfalseEasting: " << thePlane.falseEasting()
385  << "\nfalseNorthing: " << thePlane.falseNorthing()
386  << endl;
387  }
388 }
static const char * DATUM_KW
virtual double getFalseNorthing() const
static const char * FALSE_EASTING_NORTHING_UNITS_KW
static const char * CENTRAL_MERIDIAN_KW
ossimUnitType
Represents serializable keyword/value map.
static ossimDatumFactoryRegistry * instance()
instance method
virtual ossimString getEntryString(ossim_int32 entry_number) const
virtual const ossimString & code() const
Definition: ossimDatum.h:57
ossimString units() const
Not stored as string; hence, returned by value.
virtual ossim_int32 getEntryNumber(const char *entry_string, bool case_insensitive=true) const
virtual ossimString getClassName() const
Definition: ossimObject.cpp:64
static const char * TYPE_KW
#define STATIC_TYPE_NAME(T)
Definition: ossimRtti.h:325
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
#define US_METERS_PER_FT
bool matchesProjection(const ossimMapProjection *proj) const
Checks parameters of projection against this.
#define FLT_EPSILON
virtual ossimGpt origin() const
virtual const ossimDatum * create(const ossimString &code) const
create method
double toDouble() const
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
static const char * STD_PARALLEL_1_KW
double getDegrees() const
Definition: ossimDms.h:71
static const char * FALSE_EASTING_NORTHING_KW
static const char * ORIGIN_LATITUDE_KW
#define MTRS_PER_FT
virtual double getFalseEasting() const
static const char * PCS_CODE_KW
ossimString toString(ossim_uint32 precision=15) const
Definition: ossimDpt.cpp:160
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
ossimStatePlaneProjectionInfo(const std::string &name, int pcsCode, const std::string &projCode, const std::string &param1, const std::string &param2, const std::string &param3, const std::string &param4, double falseEast, double falseNorth, const std::string &units, const std::string &datumName)
static const char * SCALE_FACTOR_KW
std::ostream & operator<<(std::ostream &os, const ossimStatePlaneProjectionInfo &thePlane)
static const char * STD_PARALLEL_2_KW
static ossimUnitTypeLut * instance()
Returns the static instance of an ossimUnitTypeLut object.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
void populateProjectionKeywords(ossimKeywordlist &kwl, const char *prefix=0) const