OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimLlxyProjection.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2002 ImageLinks Inc.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: David Burken
7 //
8 // Description:
9 //
10 // Contains class definition for ossimLlxy. This is a simple "latitude /
11 // longitude to x / y" projection.
12 //
13 //*******************************************************************
14 // $Id: ossimLlxyProjection.cpp 20060 2011-09-07 12:33:46Z gpotts $
15 
20 #include <ossim/base/ossimDatum.h>
21 
22 // RTTI information for the ossimMapProjection
23 RTTI_DEF1(ossimLlxyProjection, "ossimLlxyProjection" , ossimMapProjection);
24 
25 // About 1 meter.
26 static const ossim_float64 DEFAULT_DEGREES_PER_PIXEL = 8.9831528412e-006;
27 
29 {
30  // set to about 1 meter per pixel
31  theDegreesPerPixel.y = DEFAULT_DEGREES_PER_PIXEL;
32  theDegreesPerPixel.x = DEFAULT_DEGREES_PER_PIXEL;
39 }
40 
42  :
44 {
45  theOrigin = rhs.theOrigin;
46  theUlGpt = rhs.theUlGpt;
57 }
58 
60  double latSpacing,
61  double lonSpacing)
62  :
64 {
65  theOrigin = origin;
66  theUlGpt = origin;
67  theUlEastingNorthing.y = 0.0;
68  theUlEastingNorthing.x = 0.0;
71  theDegreesPerPixel.y = latSpacing;
72  theDegreesPerPixel.x = lonSpacing;
77 }
78 
80  const ossimGpt& origin)
81  :ossimMapProjection(ellipsoid, origin)
82 {
83  theDegreesPerPixel.y = 1.0;
84  theDegreesPerPixel.x = 1.0;
91 }
92 
94 {
95 }
96 
98 {
99  return new ossimLlxyProjection(*this);
100 }
101 
102 //*****************************************************************************
103 // METHOD: ossimMapProjection::computeDegreesPerPixel
104 //
105 //*****************************************************************************
107  const ossimDpt& metersPerPixel,
108  double &deltaLat,
109  double &deltaLon)
110 {
111  ossimDpt mpd = ground.metersPerDegree();
112  ossimDpt dpm(1.0/mpd.x,
113  1.0/mpd.y);
114  deltaLat = metersPerPixel.y*dpm.y;
115  deltaLon = metersPerPixel.x*dpm.x;
116 }
117 
118 //*****************************************************************************
119 // METHOD: ossimMapProjection::computeMetersPerPixel
120 //
121 //*****************************************************************************
123  double deltaDegreesPerPixelLat,
124  double deltaDegreesPerPixelLon,
125  ossimDpt &metersPerPixel)
126 {
127  metersPerPixel = center.metersPerDegree();
128  metersPerPixel.x *= deltaDegreesPerPixelLon;
129  metersPerPixel.y *= deltaDegreesPerPixelLat;
130 }
131 
133  ossimDpt& lineSampPt) const
134 {
135  ossimGpt gpt = worldPoint;
136 
137  if (*theOrigin.datum() != *gpt.datum())
138  {
139  // Apply datum shift if it's not the same.
140  gpt.changeDatum(theOrigin.datum());
141  }
142 
143  lineSampPt.line = (theUlGpt.latd() - gpt.latd()) / theDegreesPerPixel.y;
144  lineSampPt.samp = (gpt.lond() - theUlGpt.lond()) / theDegreesPerPixel.x;
145 }
146 
148  ossimGpt& worldPt) const
149 {
150  worldPt.makeNan();
151  // Start with the origin. This will keep the origin's datum.
152  worldPt.datum(theOrigin.datum());
153 
154  double lat = theUlGpt.latd() - (lineSampPt.line * theDegreesPerPixel.y);
155  double lon = theUlGpt.lond() + (lineSampPt.samp * theDegreesPerPixel.x);
156 
157  //---
158  // Assuming the origin had a lon between -180 and 180 and lat between -90
159  // and 90.
160  //---
161 // if (lon > 180.0)
162 // {
163 // lon -= 360.0;
164 // }
165 // else if (lon < -180.0)
166 // {
167 // lon += 360.0;
168 // }
169 // if (lat > 90.0)
170 // {
171 // lat -= 90.0;
172 // }
173 // else if (lat < -90.0)
174 // {
175 // lat = -180.0 - lat;
176 // }
177 
178  worldPt.latd(lat);
179  worldPt.lond(lon);
181  {
183  }
184 }
185 
187 {
188  out << setiosflags(ios::fixed) << setprecision(15)
189  << "ossimLlxyProjection dump:"
190  << "\norigin: " << theOrigin
191  << "\nlatitude spacing in decimal degrees: " << theDegreesPerPixel.y
192  << "\nlongitude spacing in decimal degrees: " << theDegreesPerPixel.x
193  << "\n\nossimMapProjection dump:\n" << endl;
194 
195  return ossimMapProjection::print(out);
196 }
197 
199 {
205 }
206 
208  const char* prefix) const
209 {
210  // Base class...
211  ossimMapProjection::saveState(kwl, prefix);
212 
213  return true;
214 }
215 
217  const char* prefix)
218 {
219  // Base class...
220  ossimMapProjection::loadState(kwl, prefix);
221 
222  if (theOrigin.hasNans() == false)
223  {
224  if ( (theDegreesPerPixel.hasNans() == false) &&
226  {
227  // Compute meters per pixel from origin and decimal degrees.
232  }
233  else if( (theMetersPerPixel.hasNans() == false) &&
235  {
236  // Compute decimal degrees per pixel from origin and meters.
241  }
242  else
243  {
244  // Assign some value.
245  theDegreesPerPixel.y = DEFAULT_DEGREES_PER_PIXEL;
246  theDegreesPerPixel.x = DEFAULT_DEGREES_PER_PIXEL;
251  }
252  }
253 
254  return true;
255 }
256 
258 {
259  const ossimLlxyProjection* proj = dynamic_cast<const ossimLlxyProjection*>(&projection);
260 
261  if(!proj)
262  {
263  return false;
264  }
265 
266  return ( // (theOrigin == proj->theOrigin) && // tmp... fix gpt!
269 }
270 
271 
273 {
274  ossimDpt result;
275 
276  worldToLineSample(worldPoint, result);
277 
278  return result;
279 }
280 
281 ossimGpt ossimLlxyProjection::inverse(const ossimDpt &projectedPoint) const
282 {
283  ossimGpt result;
284 
285  lineSampleToWorld(projectedPoint, result);
286 
287  return result;
288 }
289 
291 {
292  theDegreesPerPixel.y = spacing;
293 
294  // Update the meters per pixel.
295  ossimDpt pt = ossimGpt(0.0, 0.0).metersPerDegree();
297 }
298 
300 {
301  theDegreesPerPixel.x = spacing;
302 
303  // Update the meters per pixel.
304  ossimDpt pt = ossimGpt(0.0, 0.0).metersPerDegree();
306 }
307 
309 {
310  return true;
311 }
312 
314 {
315  return theDegreesPerPixel.y;
316 }
317 
319 {
320  return theDegreesPerPixel.x;
321 }
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual double getLonSpacing() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual void worldToLineSample(const ossimGpt &worldPoint, ossimDpt &lineSampPt) const
virtual ossimDpt forward(const ossimGpt &worldPoint) const
All map projections will convert the world coordinate to an easting northing (Meters).
double lond() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:97
Represents serializable keyword/value map.
virtual void setLatSpacing(double spacing)
virtual std::ostream & print(std::ostream &out) const
Prints data members to stream.
double samp
Definition: ossimDpt.h:164
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
virtual void computeMetersPerPixel()
This will go from the ground point and give you an approximate meters per pixel.
double y
Definition: ossimDpt.h:165
ossimDpt theUlEastingNorthing
Hold tie point as easting northing.
RTTI_DEF1(ossimLlxyProjection, "ossimLlxyProjection", ossimMapProjection)
void makeNan()
Definition: ossimGpt.h:130
ossim_float64 hgt
Height in meters above the ellipsiod.
Definition: ossimGpt.h:274
virtual double getLatSpacing() const
static ossimElevManager * instance()
METHOD: instance() Implements singelton pattern.
ossimGpt theUlGpt
Hold tie point in decimal degrees.
double latd() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:87
void changeDatum(const ossimDatum *datum)
This will actually perform a shift.
Definition: ossimGpt.cpp:316
virtual void setMetersPerPixel(const ossimDpt &gsd)
const ossimDatum * datum() const
datum().
Definition: ossimGpt.h:196
double ossim_float64
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
double line
Definition: ossimDpt.h:165
ossimDpt theMetersPerPixel
Holds the number of meters per pixel.
virtual double getHeightAboveEllipsoid(const ossimGpt &gpt)
virtual ossimGpt origin() const
virtual const ossimEllipsoid * ellipsoid() const
Definition: ossimDatum.h:60
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
bool hasNans() const
Definition: ossimDpt.h:67
virtual ossimObject * dup() const
bool hasNans() const
Definition: ossimGpt.h:135
virtual void lineSampleToWorld(const ossimDpt &lineSampPt, ossimGpt &worldPt) const
ossimDpt theDegreesPerPixel
Hold the decimal degrees per pixel.
double x
Definition: ossimDpt.h:164
virtual void setMetersPerPixel(const ossimDpt &pt)
ossimDpt metersPerDegree() const
Definition: ossimGpt.cpp:498
ossimEllipsoid theEllipsoid
This method verifies that the projection parameters match the current pcs code.
virtual void setLonSpacing(double spacing)
virtual void computeDegreesPerPixel()
Computes the approximate resolution in degrees/pixel.
virtual std::ostream & print(std::ostream &out) const
Prints data members to stream.
virtual ossimGpt inverse(const ossimDpt &projectedPoint) const
Will take a point in meters and convert it to ground.
virtual bool operator==(const ossimProjection &projection) const
Compares this to arg projection and returns TRUE if the same.
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
virtual bool isGeographic() const
const ossimDatum * theDatum
This is only set if we want to have built in datum shifting.