OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimMapProjectionInfo.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2001 ImageLinks Inc.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: David Burken
7 //
8 // Description:
9 // Class for encapsulate projection info given a projection, datum, and
10 // output rectangle.
11 //
12 // NOTE:
13 // - Output rectangle should be relative to the center of pixels.
14 // Shifts will be made for "pixel is area" internally.
15 //
16 //*******************************************************************
17 // $Id: ossimMapProjectionInfo.cpp 13025 2008-06-13 17:06:30Z sbortman $
18 
19 #include <cstdlib>
20 #include <fstream>
21 #include <time.h>
22 
23 using namespace std;
24 
27 #include <ossim/base/ossimTrace.h>
28 #include <ossim/base/ossimCommon.h>
30 #include <ossim/base/ossimDatum.h>
33 #include <ossim/base/ossimDrect.h>
37 
38 //***
39 // Static trace for debugging.
40 //***
41 static ossimTrace traceDebug("ossimMapProjectionInfo::debug");
42 
43 //***
44 // Keywords for getStateFrom/saveStateTo.
45 //***
47 "viewinfo.output_readme_in_us_ft_flag";
48 
49 const char* ossimMapProjectionInfo::PIXEL_TYPE_KW = "viewinfo.pixel_type";
50 
52 "viewinfo.readme_image_string";
53 
55  const ossimDrect& output_rect)
56  :
57  theProjection (proj),
58  theErrorStatus (false),
59  theLinesPerImage (0),
60  thePixelsPerLine (0),
61  theCornerGroundPt (),
62  theCornerEastingNorthingPt (),
63  theCenterGroundPt (),
64  theCenterEastingNorthingPt (0.0, 0.0),
65  thePixelType (OSSIM_PIXEL_IS_POINT),
66  theOutputInfoInFeetFlag (false),
67  theImageInfoString ()
68 {
69  if (!theProjection)
70  {
71  theErrorStatus = true;
73  << "FATAL ossimMapProjectionInfo::ossimMapProjectionInfo: "
74  << "Null projection pointer passed to constructor!"
75  << "\nError status has been set. Returning..."
76  << std::endl;
77  return;
78  }
79 
80  initializeMembers(output_rect);
81 
82  if (traceDebug())
83  {
85  << "DEBUG ossimMapProjectionInfo::ossimMapProjectionInfo:\n"
86  << "output_rect: " << output_rect << "\n"
87  << *this << std::endl;
88  }
89 }
90 
92 {
93 }
94 
96 {
97  return theErrorStatus;
98 }
99 
101 {
102  theBoundingRect = rect;
103  theLinesPerImage = ossim::round<int>(rect.height());
104  thePixelsPerLine = ossim::round<int>(rect.width());
105 
107  theCornerGroundPt[0]);
108 
110  theCornerGroundPt[1]);
111 
113  theCornerGroundPt[2]);
114 
115 
117  theCornerGroundPt[3]);
118 
121 
124 
127 
130 
134  theCornerEastingNorthingPt[3].x) / 4.0;
135 
139  theCornerEastingNorthingPt[3].y) / 4.0;
140 
142 }
143 
144 
146  const char* prefix)const
147 {
148  theProjection->saveState(kwl, prefix);
149 
151  {
152  ossimGpt gpt = ulGroundPt();
153  kwl.add(prefix,
155  ossimDpt(gpt).toString().c_str(),
156  true);
157  kwl.add(prefix,
159  ossimUnitTypeLut::instance()->getEntryString(OSSIM_DEGREES),
160  true);
161  }
162  else
163  {
165  kwl.add(prefix,
167  dpt.toString().c_str(),
168  true);
169  kwl.add(prefix,
171  ossimUnitTypeLut::instance()->getEntryString(OSSIM_METERS),
172  true);
173  }
174 }
175 
177 {
178  if (!os)
179  {
180  return os;
181  }
182 
183  os << setiosflags(ios::left)
184  << setiosflags(ios::fixed)
185  << "ossimMapProjectionInfo Data Members:\n"
186  << "Projection name: " << theProjection->getProjectionName()
187  << setw(30) << "\nOutput pixel type:"
188  << ((getPixelType() == OSSIM_PIXEL_IS_POINT) ? "pixel is point" :
189  "pixel is area")
190  << setw(30) << "\nMeters per pixel:"
191  << getMetersPerPixel()
192  << setw(30) << "\nUS survey feet per pixel:"
194  << setw(30) << "\nDecimal degrees per pixel:"
196  << setw(30) << "\nNumber of lines:"
198  << setw(30) << "\nNumber of pixels:"
200  << setw(30) << "\nUpper left ground point:"
201  << theCornerGroundPt[0]
202  << setw(30) << "\nUpper right ground point:"
203  << theCornerGroundPt[1]
204  << setw(30) << "\nLower right ground point:"
205  << theCornerGroundPt[2]
206  << setw(30) << "\nLower left ground point:"
207  << theCornerGroundPt[3]
208  << setw(30) << "\nUpper left easting_northing:"
210  << setw(30) << "\nUpper right easting_northing:"
212  << setw(30) << "\nLower right easting_northing:"
214  << setw(30) << "\nLower left easting_northing:"
216  << setw(30) << "\nCenter ground point:"
218  << setw(30) << "\nCenter easting_northing:"
220  << "\nMap Projection dump:";
221  theProjection->print(os);
222 
223  return os;
224 }
225 
227 {
228  thePixelType = type;
229 }
230 
232 {
233  return thePixelType;
234 }
235 
237 {
239 }
240 
242 {
244 }
245 
247 {
248  return theImageInfoString;
249 }
250 
252 {
253  theImageInfoString = string;
254 }
255 
257 {
258  return theProjection;
259 }
260 
262 {
264  {
265  ossimDpt mpp = getMetersPerPixel();
266  ossimDpt pt;
267  pt.x = theCornerEastingNorthingPt[0].x - (mpp.x / 2.0);
268  pt.y = theCornerEastingNorthingPt[0].y + (mpp.y / 2.0);
269  return pt;
270  }
271  else
272  {
273  return theCornerEastingNorthingPt[0];
274  }
275 }
276 
278 {
280  {
281  ossimDpt mpp = getMetersPerPixel();
282  ossimDpt pt;
283  pt.x = theCornerEastingNorthingPt[1].x + (mpp.x / 2.0);
284  pt.y = theCornerEastingNorthingPt[1].y + (mpp.y / 2.0);
285  return pt;
286  }
287  else
288  {
289  return theCornerEastingNorthingPt[1];
290  }
291 }
292 
294 {
296  {
297  ossimDpt mpp = getMetersPerPixel();
298  ossimDpt pt;
299  pt.x = theCornerEastingNorthingPt[2].x + (mpp.x / 2.0);
300  pt.y = theCornerEastingNorthingPt[2].y - (mpp.y / 2.0);
301  return pt;
302  }
303  else
304  {
305  return theCornerEastingNorthingPt[2];
306  }
307 }
308 
310 {
312  {
313  ossimDpt mpp = getMetersPerPixel();
314  ossimDpt pt;
315  pt.x = theCornerEastingNorthingPt[3].x - (mpp.x / 2.0);
316  pt.y = theCornerEastingNorthingPt[3].y - (mpp.y / 2.0);
317  return pt;
318  }
319  else
320  {
321  return theCornerEastingNorthingPt[3];
322  }
323 }
324 
326 {
328  {
330  ossimGpt gpt;
331  gpt.latd(theCornerGroundPt[0].latd() + (ddpp.y / 2.0));
332  gpt.lond(theCornerGroundPt[0].lond() - (ddpp.x / 2.0));
333  return gpt;
334  }
335  else
336  {
337  return theCornerGroundPt[0];
338  }
339 }
340 
342 {
344  {
346  ossimGpt gpt;
347  gpt.latd(theCornerGroundPt[1].latd() + (ddpp.y / 2.0));
348  gpt.lond(theCornerGroundPt[1].lond() + (ddpp.x / 2.0));
349  return gpt;
350  }
351  else
352  {
353  return theCornerGroundPt[1];
354  }
355 }
356 
358 {
360  {
362  ossimGpt gpt;
363  gpt.latd(theCornerGroundPt[2].latd() - (ddpp.y / 2.0));
364  gpt.lond(theCornerGroundPt[2].lond() + (ddpp.x / 2.0));
365  return gpt;
366  }
367  else
368  {
369  return theCornerGroundPt[2];
370  }
371 }
372 
374 {
376  {
378  ossimGpt gpt;
379  gpt.latd(theCornerGroundPt[3].latd() - (ddpp.y / 2.0));
380  gpt.lond(theCornerGroundPt[3].lond() - (ddpp.x / 2.0));
381  return gpt;
382  }
383  else
384  {
385  return theCornerGroundPt[3];
386  }
387 }
388 
390 {
391  // Center is simply center, no shift for pixel is area...
392  return theCenterGroundPt;
393 }
394 
396 {
398 }
399 
401 {
402  return theLinesPerImage;
403 }
404 
406 {
407  return thePixelsPerLine;
408 }
409 
411  const char* )
412 {
413  const char* lookupReturn = kwl.find(README_IMAGE_STRING_KW);
414 
415  //***
416  // "theImageInfoString" goes in the README file "Image:" field and can
417  // be used to identify the image.
418  //***
419  if (lookupReturn) theImageInfoString = lookupReturn;
420 
421  lookupReturn = kwl.find(ossimKeywordNames::PIXEL_TYPE_KW);
422 
423  if (lookupReturn)
424  {
425  ossimString tmp = lookupReturn;
426 
427  tmp.downcase();
428 
429  if (tmp.contains("area"))
430  {
432  }
433  else
434  {
436  }
437  }
438 
439  lookupReturn = kwl.find(OUTPUT_US_FT_INFO_KW);
440 
441  if (lookupReturn)
442  {
443  int tmp = atoi(lookupReturn);
444 
445  if (tmp)
446  {
448  }
449  else
450  {
451  theOutputInfoInFeetFlag = false;
452  }
453  }
454 
455  if (traceDebug())
456  {
458  << "DEBUG ossimMapProjectionInfo::loadState:"
459  << "\ntheImageInfoString: " << theImageInfoString
460  << "\nthePixelType: " << int(thePixelType)
461  << "\ntheOutputInfoInFeetFlag: " << theOutputInfoInFeetFlag
462  << endl;
463  }
464 
465  return true;
466 }
467 
469  const char* ) const
470 {
473 
474  ossimString tmp;
475 
477  {
478  tmp = "point";
479  }
480  else
481  {
482  tmp = "area";
483  }
484 
485  kwl.add(PIXEL_TYPE_KW,
486  tmp.chars());
487 
490 
491  return true;
492 }
493 
495 {
497 
498  pt.x = ossim::mtrs2usft(pt.x);
499 
500  pt.y = ossim::mtrs2usft(pt.y);
501 
502  return pt;
503 }
504 
506 {
508  pt.x = ossim::mtrs2usft(pt.x);
509  pt.y = ossim::mtrs2usft(pt.y);
510  return pt;
511 }
512 
514 {
516  pt.x = ossim::mtrs2usft(pt.x);
517  pt.y = ossim::mtrs2usft(pt.y);
518  return pt;
519 }
520 
522 {
524  pt.x = ossim::mtrs2usft(pt.x);
525  pt.y = ossim::mtrs2usft(pt.y);
526  return pt;
527 }
528 
530 {
532 }
533 
535 {
537 
538  pt.x = ossim::mtrs2usft(pt.x);
539  pt.y = ossim::mtrs2usft(pt.y);
540 
541  return pt;
542 }
543 
545 {
547 }
virtual const ossimDpt & getDecimalDegreesPerPixel() const
Returns decimal degrees per pixel as an ossimDpt with "x" representing longitude and "y" representing...
ossimGpt urGroundPt() const
Returns the upper right ground point.
ossim_float64 width() const
Definition: ossimDrect.h:522
ossim_int32 linesPerImage() const
double lond() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:97
Represents serializable keyword/value map.
ossimDpt lrEastingNorthingPtInFt() const
Returns the lower right easting and northing as a ossimDpt.
const char * find(const char *key) const
const ossimDpt & ul() const
Definition: ossimDrect.h:339
ossimDpt getUsSurveyFeetPerPixel() const
Returns the pixel size in U.S.
double y
Definition: ossimDpt.h:165
ossimDpt getDecimalDegreesPerPixel() const
Returns the decimal degrees per pixel.
bool contains(char aChar) const
Definition: ossimString.h:58
ossimDpt ulEastingNorthingPtInFt() const
Returns the upper left easting and northing as a ossimDpt.
virtual bool isGeographic() const
void setPixelType(ossimPixelType type)
Sets the data member "thePixelType".
const ossimMapProjection * theProjection
ossimDpt lrEastingNorthingPt() const
Returns the lower right easting and northing as a ossimDpt.
double latd() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:87
virtual ossimGpt inverse(const ossimDpt &projectedPoint) const =0
Will take a point in meters and convert it to ground.
ossimPixelType getPixelType() const
Returns data member "thePixelType".
bool errorStatus() const
Returns true on error false if ok.
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
bool unitsInFeet() const
Returns the data member "theOutputInfoInFeetFlag".
void setOutputFeetFlag(bool flag)
Sets the data member "theOutputInfoInFeetFlag".
virtual ossimGpt lineSampleToWorld(const ossimDpt &projectedPoint) const
static const char * README_IMAGE_STRING_KW
static const char * TIE_POINT_XY_KW
virtual void lineSampleToEastingNorthing(const ossimDpt &liineSample, ossimDpt &eastingNorthing) const
ossimGpt lrGroundPt() const
Returns the lower right ground point.
ossimDpt centerEastingNorthingPt() const
ossimString getImageInfoString() const
Returns theImageInfoString.
virtual ossimString getProjectionName() const
Returns the projection name.
const char * chars() const
For backward compatibility.
Definition: ossimString.h:77
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
ossimGpt ulGroundPt() const
Returns the upper left ground point.
ossimDpt urEastingNorthingPt() const
Returns the upper right easting and northing as a ossimDpt.
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
ossim_int32 pixelsPerLine() const
ossim_float64 height() const
Definition: ossimDrect.h:517
void setImageInfoString(const ossimString &string)
Used to set data member "theImageInfoString".
ossimDpt llEastingNorthingPt() const
Returns the lower left easting and northing as a ossimDpt.
const ossimMapProjection * getProjection() const
Returns reference to "theProjection".
ossimDpt getMetersPerPixel() const
Returns the pixel size in meters.
void getGeom(ossimKeywordlist &kwl, const char *prefix=0) const
Adds tie point to keyword list.
ossimString theImageInfoString
"theImageInfoString" goes in the README file "Image:" field to identify the image.
ossimDpt ulEastingNorthingPt() const
Returns the upper left easting and northing as a ossimDpt.
ossimPixelType
ossimString toString(ossim_uint32 precision=15) const
Definition: ossimDpt.cpp:160
void initializeMembers(const ossimDrect &output_rect)
ossimDpt llEastingNorthingPtInFt() const
Returns the lower left easting and northing as a ossimDpt.
ossimGpt centerGroundPt() const
Returns the center ground point.
static const char * PIXEL_TYPE_KW
const ossimDpt & ur() const
Definition: ossimDrect.h:340
static const char * PIXEL_TYPE_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 theOutputInfoInFeetFlag
If "theOutputInfoInFeetFlag" is true the readme file tie point info will be output in both meters and...
const ossimDpt & ll() const
Definition: ossimDrect.h:342
double mtrs2usft(double meters)
Definition: ossimCommon.h:375
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual ossimDpt getMetersPerPixel() const
std::ostream & print(std::ostream &os) const
Formatted print of data members.
ossimDpt urEastingNorthingPtInFt() const
Returns the upper right easting and northing as a ossimDpt.
static ossimUnitTypeLut * instance()
Returns the static instance of an ossimUnitTypeLut object.
const ossimDpt & lr() const
Definition: ossimDrect.h:341
ossimPixelType thePixelType
"thePixelType" defines whether the tie point coordinates are relative to the center of the pixel(whic...
virtual std::ostream & print(std::ostream &out) const
Prints data members to stream.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
static const char * TIE_POINT_UNITS_KW
ossimGpt llGroundPt() const
Returns the lower left ground point.
int ossim_int32
static const char * OUTPUT_US_FT_INFO_KW