OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimCadrgProjection.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: Garrett Potts
7 //
8 //*******************************************************************
9 // $Id: ossimCadrgProjection.cpp 17815 2010-08-03 13:23:14Z dburken $
13 #include <ossim/base/ossimTrace.h>
15 #include <ossim/base/ossimDatum.h>
16 
17 RTTI_DEF1(ossimCadrgProjection, "ossimCadrgProjection", ossimMapProjection)
18 
19 double ossimCadrgProjection::theOldZoneExtents[] = {0.0, 32.0, 48.0, 56.0, 64.0,
20  68.0, 72.0, 76.0, 80.0, 90.0};
21 double ossimCadrgProjection::theCadrgArcA[] = { 369664, 302592, 245760, 199168,
22  163328, 137216, 110080, 82432 };
23 
24 double ossimCadrgProjection::theNorthLimit = 90.0*M_PI/180.0;
25 double ossimCadrgProjection::theSouthLimit = -90.0*M_PI/180.0;
26 
29  theCadrgZone(1),
30  theMapScale(5000000),
31  theWidth(0.0),
32  theHeight(0.0)
33 {
35 }
36 
38 {
39 
40 }
41 
43 {
44  return new ossimCadrgProjection(*this);
45 }
46 
47 
49 {
50  ossimDpt lineSample;
51 
52  worldToLineSample(worldPoint, lineSample);
53 
54  return lineSample;
55 }
56 
57 ossimGpt ossimCadrgProjection::inverse(const ossimDpt& /* eastingNorthing */)const
58 {
59  double lat=0.0;
60  double lon=0.0;
61 
62  return ossimGpt(lat*DEG_PER_RAD, lon*DEG_PER_RAD, 0.0, theDatum);
63 }
64 
66 {
67  double easting = 0.0;
68  double northing = 0.0;
69  ossimGpt gpt = latLon;
70 
71  if (theDatum)
72  {
73  if (theDatum->code() != latLon.datum()->code())
74  {
75  gpt.changeDatum(theDatum); // Shift to our datum.
76  }
77  }
78 
79  return ossimDpt(easting, northing);
80 }
81 
83 {
84  ossimGpt worldPoint;
85 
86  lineSampleToWorld(projectedPoint, worldPoint);
87 
88  return worldPoint;
89 }
90 
92  ossimDpt& lineSample)const
93 {
94  double lat = worldPoint.latd();
95  double lon = worldPoint.lond();
96  double centerLat = theOrigin.latd();
97  double centerLon = theOrigin.lond()*DEG_PER_RAD;
98 
99  lineSample.y = (centerLat - lat)/90.0*thePixelConstant.y;
100  lineSample.x = (lon - centerLon)/360.0*thePixelConstant.x;
101 
102  lineSample = lineSample - theUlLineSample;
103 }
104 
106  ossimGpt& gpt)const
107 {
108  gpt = theOrigin;
109 
110 
111  ossimDpt adjustedPixel(projectedPoint.x + theUlLineSample.x,
112  projectedPoint.y + theUlLineSample.y);
113 
114 // double lat = gpt.latd() - (90/thePixelConstant.y)*adjustedPixel.y;
115 // double lon = gpt.lond() + (360/thePixelConstant.x)*adjustedPixel.x;
116  double lat = gpt.latd() - (90/thePixelConstant.y)*adjustedPixel.y;
117  double lon = gpt.lond() + (360/thePixelConstant.x)*adjustedPixel.x;
118 
119  gpt.latd(lat);
120  gpt.lond(lon);
121 
122  gpt.clampLat(-90, 90);
123  gpt.clampLon(-180, 180);
124 }
125 
127  long zone)const
128 {
129  double adrgscale = 1000000/scale;
130 
131  // E-W pixel constant
132  double x_pix = (double) adrgscale*theCadrgArcA[zone-1] / 512.0;
133 
134  // Increase, if necessary, to the next highest integer value
135  x_pix = ceil(x_pix);
136  x_pix = x_pix * 1.33333;//(512*100)/(150*256);
137 
138  // Round the final result.
139  x_pix = ossim::round<int>(x_pix);
140 
141  return x_pix*256.0;
142 
143 }
144 
146 {
147  double adrgscale = 1000000/scale;
148  const long CADRG_ARC_B = 400384;
149 
150  double y_pix = (double) adrgscale * CADRG_ARC_B / 512.0;
151 
152  // Increase, if necessary, to the next highest integer value
153  y_pix = ceil(y_pix);
154 
155  y_pix = y_pix * 0.33333;//(512*100)/(4*150*256);
156 
157  // Round the final result.
158  y_pix = ossim::round<int>(y_pix);
159 
160  return y_pix*256.0;
161 }
162 
164 {
165  theUlLineSample = ossimDpt(0,0);
166 
169  theCadrgZone);
170  double height = theHeight;
171  double width = theWidth;
172 
173  if(width > thePixelConstant.x)
174  {
175  width = thePixelConstant.x;
176  }
177 
178  if(height > thePixelConstant.y)
179  {
180  height = thePixelConstant.y;
181  }
182 
183 
184  theUlLineSample.x = -width/2.0;
185  theUlLineSample.y = -height/2.0;
186 }
187 
189  const char* prefix)const
190 {
191  bool result = ossimProjection::saveState(kwl, prefix);
192 
193  kwl.add(prefix,
195  theCadrgZone,
196  true);
197 
198  kwl.add(prefix,
199  "map_scale",
200  theMapScale,
201  true);
202 
203  kwl.add(prefix,
205  theHeight,
206  true);
207 
208  kwl.add(prefix,
210  theWidth,
211  true);
212 
213  kwl.add(prefix,
215  theUlGpt.latd(),
216  true);
217 
218  kwl.add(prefix,
220  theUlGpt.lond(),
221  true);
222 
223  kwl.add(prefix,
225  theLlGpt.latd(),
226  true);
227 
228  kwl.add(prefix,
230  theLlGpt.lond(),
231  true);
232 
233  kwl.add(prefix,
235  theLrGpt.latd(),
236  true);
237 
238  kwl.add(prefix,
240  theLrGpt.lond(),
241  true);
242 
243  kwl.add(prefix,
245  theUrGpt.latd(),
246  true);
247 
248  kwl.add(prefix,
250  theUrGpt.lond(),
251  true);
252 
253 
254 
255  if(theDatum)
256  {
257  kwl.add(prefix,
259  theDatum->code(),
260  true);
261  }
262 
263  return result;
264 }
265 
266 
268  const char* prefix)
269 {
270  ossimProjection::loadState(kwl, prefix);
271 
272 
273  const char* lookup = kwl.find(prefix, ossimKeywordNames::UL_LAT_KW);
274  if(lookup)
275  {
276  theUlGpt.latd(ossimString(lookup).toDouble());
277  }
278  else
279  {
280  theUlGpt.latd(90.0);
281  }
282 
283  lookup = kwl.find(prefix, ossimKeywordNames::UL_LON_KW);
284  if(lookup)
285  {
286  theUlGpt.lond(ossimString(lookup).toDouble());
287  }
288  else
289  {
290  theUlGpt.lond(-180.0);
291  }
292 
293  lookup = kwl.find(prefix, ossimKeywordNames::LL_LAT_KW);
294  if(lookup)
295  {
296  theLlGpt.latd(ossimString(lookup).toDouble());
297  }
298  else
299  {
300  theLlGpt.latd(0.0);
301  }
302 
303  lookup = kwl.find(prefix, ossimKeywordNames::LL_LON_KW);
304  if(lookup)
305  {
306  theLlGpt.lond(ossimString(lookup).toDouble());
307  }
308  else
309  {
310  theLlGpt.lond(-180.0);
311  }
312 
313  lookup = kwl.find(prefix, ossimKeywordNames::LR_LAT_KW);
314  if(lookup)
315  {
316  theLrGpt.latd(ossimString(lookup).toDouble());
317  }
318  else
319  {
320  theLrGpt.latd(0.0);
321  }
322 
323  lookup = kwl.find(prefix, ossimKeywordNames::LR_LON_KW);
324  if(lookup)
325  {
326  theLrGpt.lond(ossimString(lookup).toDouble());
327  }
328  else
329  {
330  theLrGpt.lond(180.0);
331  }
332 
333  lookup = kwl.find(prefix, ossimKeywordNames::LR_LAT_KW);
334  if(lookup)
335  {
336  theLrGpt.latd(ossimString(lookup).toDouble());
337  }
338  else
339  {
340  theLrGpt.latd(0.0);
341  }
342 
343  lookup = kwl.find(prefix, ossimKeywordNames::LR_LON_KW);
344  if(lookup)
345  {
346  theLrGpt.lond(ossimString(lookup).toDouble());
347  }
348  else
349  {
350  theLrGpt.lond(180.0);
351  }
352 
353  lookup = kwl.find(prefix, ossimKeywordNames::UR_LAT_KW);
354  if(lookup)
355  {
356  theUrGpt.latd(ossimString(lookup).toDouble());
357  }
358  else
359  {
360  theUrGpt.latd(90.0);
361  }
362 
363  lookup = kwl.find(prefix, ossimKeywordNames::UR_LON_KW);
364  if(lookup)
365  {
366  theUrGpt.lond(ossimString(lookup).toDouble());
367  }
368  else
369  {
370  theUrGpt.lond(180.0);
371  }
372 
373  const char* zone = kwl.find(prefix,
375  if(zone)
376  {
377  theCadrgZone = ossimString(zone).toLong();
378  }
379  const char* mapScale = kwl.find(prefix,
380  "map_scale");
381  if(mapScale)
382  {
383  theMapScale = ossimString(mapScale).toDouble();
384  }
385  const char *height = kwl.find(prefix,
387  const char *width = kwl.find(prefix,
389  if(height)
390  {
391  theHeight = ossimString(height).toDouble();
392  }
393 
394  if(width)
395  {
396  theWidth = ossimString(width).toDouble();
397  }
398 
400 
401  return true;
402 }
403 
404 //*************************************************************************************************
406 //*************************************************************************************************
408 {
409  if (!ossimMapProjection::operator==(proj))
410  return false;
411 
412  const ossimCadrgProjection* p = dynamic_cast<const ossimCadrgProjection*>(&proj);
413  if (!p) return false;
414 
415  if (theUlGpt != p->theUlGpt) return false;
416  if (theLlGpt != p->theLlGpt) return false;
417  if (theLrGpt != p->theLrGpt) return false;
418  if (theUrGpt != p->theUrGpt) return false;
419  if (!ossim::almostEqual(theWidth,p->theWidth)) return false;
420  if (!ossim::almostEqual(theHeight,p->theHeight)) return false;
421  if (theCadrgZone != p->theCadrgZone) return false;
422 
423  return true;
424 }
static double theCadrgArcA[8]
static const char * DATUM_KW
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
double lond() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:97
#define DEG_PER_RAD
virtual ossimDpt worldToLineSample(const ossimGpt &worldPoint) const
Represents serializable keyword/value map.
static const char * UL_LAT_KW
const char * find(const char *key) const
bool almostEqual(T x, T y, T tolerance=FLT_EPSILON)
Definition: ossimCommon.h:53
void clampLon(double low, double high)
Definition: ossimGpt.h:228
double y
Definition: ossimDpt.h:165
virtual const ossimString & code() const
Definition: ossimDatum.h:57
static const char * NUMBER_LINES_KW
virtual ossimDpt forward(const ossimGpt &latLon) const
All map projections will convert the world coordinate to an easting northing (Meters).
static const char * LR_LON_KW
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
const ossimDatum * datum() const
datum().
Definition: ossimGpt.h:196
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
static const char * ZONE_KW
virtual ossimGpt lineSampleToWorld(const ossimDpt &projectedPoint) const
static const char * LR_LAT_KW
#define M_PI
static const char * LL_LON_KW
double toDouble() const
static const char * LL_LAT_KW
double computeYPixConstant(double scale) const
void clampLat(double low, double high)
Definition: ossimGpt.h:234
virtual ossimObject * dup() const
static double theOldZoneExtents[10]
long toLong() const
toLong&#39;s deprecated, please use the toInts...
double computeXPixConstant(double scale, long zone) const
virtual bool operator==(const ossimProjection &projection) const
Returns TRUE if principal parameters are within epsilon tolerance.
double x
Definition: ossimDpt.h:164
static const char * UL_LON_KW
static const char * UR_LAT_KW
static const char * UR_LON_KW
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
virtual ossimGpt inverse(const ossimDpt &eastingNorthing) const
Will take a point in meters and convert it to ground.
static const char * NUMBER_SAMPLES_KW
const ossimDatum * theDatum
This is only set if we want to have built in datum shifting.