OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGoogleProjection.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 //
8 //*******************************************************************
10 
11 RTTI_DEF1(ossimGoogleProjection, "ossimGoogleProjection", ossimMapProjection)
12 
13 
14 //***************** THIS CODE WAS PULLED FROM THE INTERNET FOR GLOBAL MERCATOR ******
15 // I will leave as is without modifications
16 //
17 #define deg2rad(d) (((d)*M_PI)/180)
18 #define rad2deg(d) (((d)*180)/M_PI)
19 #define earth_radius 6378137
20 
21 /* The following functions take or return there results in degrees */
22 
23 double y2lat_d(double y) { return rad2deg(2 * atan(exp( deg2rad(y) ) ) - M_PI/2); }
24 double x2lon_d(double x) { return x; }
25 double lat2y_d(double lat) { return rad2deg(log(tan(M_PI/4+ deg2rad(lat)/2))); }
26 double lon2x_d(double lon) { return lon; }
27 
28 /* The following functions take or return there results in something close to meters, along the equator */
29 
30 double y2lat_m(double y) { return rad2deg(2 * atan(exp( (y / earth_radius ) )) - M_PI/2); }
31 double x2lon_m(double x) { return rad2deg(x / earth_radius); }
32 double lat2y_m(double lat) { return earth_radius * log(tan(M_PI/4+ deg2rad(lat)/2)); }
33 double lon2x_m(double lon) { return deg2rad(lon) * earth_radius; }
34 
35 //******************** END GLOBAL MERCATOR CODE ***********************
36 
38  const ossimGpt& origin)
39  :ossimMapProjection(ellipsoid, origin)
40 {
41  thePcsCode = 3857;
42  update();
43 }
45  :ossimMapProjection(src)
46 {
47  thePcsCode = 3857;
48  update();
49 }
50 
52 {
53 
54 }
55 
57 {
59 }
60 
61 ossimGpt ossimGoogleProjection::inverse(const ossimDpt &eastingNorthing)const
62 {
63  /*
64  double lon = (eastingNorthing.x / 20037508.34) * 180.0;
65  double lat = (eastingNorthing.y / 20037508.34) * 180.0;
66 
67  lat = 180.0/M_PI * (2.0 * atan(exp(lat * M_PI / 180)) - M_PI / 2.0);
68 
69  return ossimGpt(lat, lon, 0, theDatum);
70  */
71  //return ossimGpt(merc_lat(eastingNorthing.y), merc_lon(eastingNorthing.x), 0, theDatum);
72  return ossimGpt(y2lat_m(eastingNorthing.y), x2lon_m(eastingNorthing.x), 0, theDatum);
73 }
74 
76 {
77  /*
78  double easting = 0.0;
79  double northing = 0.0;
80  ossimGpt gpt = latLon;
81 
82  if (theDatum)
83  {
84  if (theDatum->code() != latLon.datum()->code())
85  {
86  gpt.changeDatum(theDatum); // Shift to our datum.
87  }
88  }
89  //double y = Math.Log(Math.Tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180);
90  easting = gpt.lond()*20037508.34/180.0;
91  northing = log(tan((90.0 + gpt.latd())*M_PI/360.0))/(M_PI/180.0);
92  northing *=20037508.34/180.0;
93 
94  return ossimDpt(easting, northing);
95  */
96 
97  return ossimDpt(lon2x_m(latLon.lond()), lat2y_m(latLon.latd()));
98 }
99 
100 bool ossimGoogleProjection::saveState(ossimKeywordlist& kwl, const char* prefix) const
101 {
102  return ossimMapProjection::saveState(kwl, prefix);
103 }
104 
105 bool ossimGoogleProjection::loadState(const ossimKeywordlist& kwl, const char* prefix)
106 {
107  thePcsCode = 3857;
108  // Must do this first.
109  bool flag = ossimMapProjection::loadState(kwl, prefix);
110 
111  update();
112  return flag;
113 }
114 
116 {
117  if (!ossimMapProjection::operator==(projection))
118  return false;
119 
120  const ossimGoogleProjection* p = dynamic_cast<const ossimGoogleProjection*>(&projection);
121 
122  return (p != 0);
123 }
124 
ossim_uint32 x
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
ossimGoogleProjection(const ossimEllipsoid &ellipsoid=ossimEllipsoid(), const ossimGpt &origin=ossimGpt())
double lond() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:97
Represents serializable keyword/value map.
ossim_uint32 y
double y
Definition: ossimDpt.h:165
double lat2y_m(double lat)
double lat2y_d(double lat)
double latd() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:87
#define rad2deg(d)
double lon2x_m(double lon)
#define M_PI
virtual bool operator==(const ossimProjection &projection) const
Compares this to arg projection and returns TRUE if the same.
double y2lat_m(double y)
#define earth_radius
double x2lon_d(double x)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
#define deg2rad(d)
double x2lon_m(double x)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
ossim_uint32 thePcsCode
Projection Coordinate System(PCS) code.
virtual ossimGpt inverse(const ossimDpt &projectedPoint) const
Will take a point in meters and convert it to ground.
double lon2x_d(double lon)
virtual ossimDpt forward(const ossimGpt &worldPoint) const
All map projections will convert the world coordinate to an easting northing (Meters).
double x
Definition: ossimDpt.h:164
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
double y2lat_d(double y)
const ossimDatum * theDatum
This is only set if we want to have built in datum shifting.