OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimEllipsoidFactory.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 // Author: Garrett Potts
8 //
9 //*******************************************************************
10 // $Id: ossimEllipsoidFactory.cpp 22905 2014-09-30 13:49:12Z dburken $
11 
14 #include <ossim/base/ossimNotify.h>
15 #include <ossim/base/ossimString.h>
16 
18 {
19  static ossimEllipsoidFactory inst;
20 
21  //---
22  // Boolean test here is necessary to avoid infinite loop from Ellipsoid
23  // classes calling this factory's instance() method. Leave this convoluted
24  // code as is. (OLK 09/14)
25  //---
26  static bool testInst = false;
27  if(!testInst)
28  {
29  testInst = true;
30  inst.initializeTable();
31  }
32 
33  return &inst;
34 }
35 
37 {
38 }
39 
41 {
42  deleteAll();
43 }
44 
46 {
47  // Can be 2-letter code or EPSG integer code for ellipsoids (7000-series). Make sure it is alpha:
48  if ( code.empty() )
49  {
50  return 0;
51  }
52 
53  const ossimEllipsoid* ellipsoid = 0;
54  ossimString alphaCode = code;
55 
56  // Check if the code passed in was actually numeric EPSG (vs. two char alpha code):
57  ossim_uint32 epsg_code = code.toUInt32();
58  if (epsg_code)
59  {
60  // EPSG was specified, fetch the equivalent alpha code from the map:
61  EpsgTableType::const_iterator iter = theEpsgTable.find(epsg_code);
62  if (iter != theEpsgTable.end())
63  alphaCode = (*iter).second;
64  }
65 
66  // Established two-letter code. Now fetch the ellipsoid instance:
67  TableType::const_iterator iter = theEllipsoidTable.find(alphaCode);
68  if(iter != theEllipsoidTable.end())
69  ellipsoid = iter->second;
70  else
71  {
72  ossimNotify(ossimNotifyLevel_WARN) << "ossimEllipsoidFactory::create WARNING:"
73  << "\nDid not create ellipsoid for code: " << code << std::endl;
74  }
75 
76  return ellipsoid;
77 }
78 
80 {
81  // Do nothing if tables were already initialized:
82  if (!theEllipsoidTable.empty())
83  {
84  return;
85  }
86 
87  // This table bridges between EPSG 7000-series codes to two-letter code:
88  theEpsgTable.insert(std::make_pair(7001, std::string("AA")));
89  theEpsgTable.insert(std::make_pair(7002, std::string("AM")));
90  theEpsgTable.insert(std::make_pair(7003, std::string("AN")));
91  theEpsgTable.insert(std::make_pair(7004, std::string("BR")));
92  theEpsgTable.insert(std::make_pair(7006, std::string("BN")));
93  theEpsgTable.insert(std::make_pair(7008, std::string("CC")));
94  theEpsgTable.insert(std::make_pair(7012, std::string("CD")));
95  theEpsgTable.insert(std::make_pair(7011, std::string("CE")));
96  theEpsgTable.insert(std::make_pair(7015, std::string("EA")));
97  theEpsgTable.insert(std::make_pair(7016, std::string("EB")));
98  theEpsgTable.insert(std::make_pair(7044, std::string("EC")));
99  theEpsgTable.insert(std::make_pair(7056, std::string("ED")));
100  theEpsgTable.insert(std::make_pair(7018, std::string("EE")));
101  theEpsgTable.insert(std::make_pair(7019, std::string("RF")));
102  theEpsgTable.insert(std::make_pair(7020, std::string("HE")));
103  theEpsgTable.insert(std::make_pair(7053, std::string("HO")));
104  theEpsgTable.insert(std::make_pair(7021, std::string("ID")));
105  theEpsgTable.insert(std::make_pair(7022, std::string("IN")));
106  theEpsgTable.insert(std::make_pair(7024, std::string("KA")));
107  theEpsgTable.insert(std::make_pair(7003, std::string("SA"))); // Same as "AN"
108  theEpsgTable.insert(std::make_pair(7043, std::string("WD")));
109  theEpsgTable.insert(std::make_pair(7030, std::string("WE")));
110  theEpsgTable.insert(std::make_pair(7059, std::string("PV")));
111 
112  theEllipsoidTable.insert(std::make_pair(std::string("AA"),
113  new ossimEllipsoid(std::string("Airy"), std::string("AA"),
114  6377563.396, 6356256.9090, 7001)));
115  theEllipsoidTable.insert(std::make_pair(std::string("AM"),
116  new ossimEllipsoid(std::string("Modified Airy"), std::string("AM"),
117  6377340.189, 6356034.448, 7002)));
118  theEllipsoidTable.insert(std::make_pair(std::string("AN"),
119  new ossimEllipsoid(std::string("Australian National"), std::string("AN"),
120  6378160.000, 6356774.7190, 7003)));
121  theEllipsoidTable.insert(std::make_pair(std::string("BR"),
122  new ossimEllipsoid(std::string("Bessel 1841"), std::string("BR"),
123  6377397.155, 6356078.9630, 7004)));
124  theEllipsoidTable.insert(std::make_pair(std::string("BN"),
125  new ossimEllipsoid(std::string("Bessel 1841(Namibia)"), std::string("BN"),
126  6377483.865, 6356165.3830, 7006)));
127  theEllipsoidTable.insert(std::make_pair(std::string("CC"),
128  new ossimEllipsoid(std::string("Clarke 1866"), std::string("CC"),
129  6378206.400, 6356583.8000, 7008)));
130  theEllipsoidTable.insert(std::make_pair(std::string("CD"),
131  new ossimEllipsoid(std::string("Clarke 1880"), std::string("CD"),
132  6378249.145, 6356514.8700, 7012)));
133  theEllipsoidTable.insert(std::make_pair(std::string("CE"),
134  new ossimEllipsoid(std::string("Clarke 1880 (IGN)EPSG 7011"), std::string("CE"),
135  6378249.200, 6356515.0000, 7011)));
136  theEllipsoidTable.insert(std::make_pair(std::string("EA"),
137  new ossimEllipsoid(std::string("Everest"), std::string("EA"),
138  6377276.345, 6356075.4130, 7015)));
139  theEllipsoidTable.insert(std::make_pair(std::string("EB"),
140  new ossimEllipsoid(std::string("Everest (E. Malasia, Brunei)"), std::string("EB"),
141  6377298.556, 6356097.55, 7016)));
142  theEllipsoidTable.insert(std::make_pair(std::string("EC"),
143  new ossimEllipsoid(std::string("Everest 1956 (India)"), std::string("EC"),
144  6377301.243, 6356100.228, 7044)));
145  theEllipsoidTable.insert(std::make_pair(std::string("ED"),
146  new ossimEllipsoid(std::string("Everest 1969 (West Malasia)"), std::string("ED"),
147  6377295.664, 6356094.668, 7056)));
148  theEllipsoidTable.insert(std::make_pair(std::string("EE"),
149  new ossimEllipsoid(std::string("Everest 1948(W.Mals. & Sing.)"), std::string("EE"),
150  6377304.063, 6356103.039, 7018)));
151 
152  // No codes for next two:
153  theEllipsoidTable.insert(std::make_pair(std::string("EF"),
154  new ossimEllipsoid(std::string("Everest (Pakistan)"), std::string("EF"),
155  6377309.613, 6356109.571, 0)));
156  theEllipsoidTable.insert(std::make_pair(std::string("FA"),
157  new ossimEllipsoid(std::string("Mod. Fischer 1960(South Asia)"), std::string("FA"),
158  6378155.0, 6356773.32, 0)));
159 
160  theEllipsoidTable.insert(std::make_pair(std::string("RF"),
161  new ossimEllipsoid(std::string("GRS 80"), std::string("RF"),
162  6378137.0, 6356752.3141, 7019)));
163  theEllipsoidTable.insert(std::make_pair(std::string("HE"),
164  new ossimEllipsoid(std::string("Helmert 1906"), std::string("HE"),
165  6378200.0, 6356818.17, 7020)));
166  theEllipsoidTable.insert(std::make_pair(std::string("HO"),
167  new ossimEllipsoid(std::string("Hough"), std::string("HO"),
168  6378270.0, 6356794.3430, 7053)));
169  theEllipsoidTable.insert(std::make_pair(std::string("ID"),
170  new ossimEllipsoid(std::string("Indonesian 1974"), std::string("ID"),
171  6378160.0, 6356774.504, 7021)));
172  theEllipsoidTable.insert(std::make_pair(std::string("IN"),
173  new ossimEllipsoid(std::string("International 1924"), std::string("IN"),
174  6378388.0, 6356911.946, 7022)));
175  theEllipsoidTable.insert(std::make_pair(std::string("KA"),
176  new ossimEllipsoid(std::string("Krassovsky"), std::string("KA"),
177  6378245.0, 6356863.0190, 7024)));
178  theEllipsoidTable.insert(std::make_pair(std::string("SA"),
179  new ossimEllipsoid(std::string("South American 1969"),std::string("SA"),
180  6378160.0, 6356774.719, 7003)));
181  theEllipsoidTable.insert(std::make_pair(std::string("WD"),
182  new ossimEllipsoid(std::string("WGS 72"), std::string("WD"),
183  6378135.000, 6356750.5200, 7043)));
184  theEllipsoidTable.insert(std::make_pair(std::string("WE"),
185  new ossimEllipsoid(std::string("WGS 84"), std::string("WE"),
186  6378137.000, 6356752.3142, 7030)));
187  theEllipsoidTable.insert(std::make_pair(std::string("PV"),
188  new ossimEllipsoid(std::string("Popular Visualization Sphere"), std::string("7059"),
189  6378137.000, 6378137.000, 7059)));
190 
191  theWgs84Ellipsoid = new ossimEllipsoid(std::string("WGS 84"), std::string("WE"),
192  6378137.000, 6356752.3142, 7030);
193  theWgs72Ellipsoid = new ossimEllipsoid(std::string("WGS 72"), std::string("WD"),
194  6378135.000, 6356750.5200, 7043);
195 }
196 
198 {
199  TableType::const_iterator ellipsoid = theEllipsoidTable.begin();
200 
201  while(ellipsoid != theEllipsoidTable.end())
202  {
203  delete (*ellipsoid).second;
204  ++ellipsoid;
205  }
206 
207  theEllipsoidTable.clear();
208  theEpsgTable.clear();
209 
210  if (theWgs84Ellipsoid)
211  {
212  delete theWgs84Ellipsoid;
213  theWgs84Ellipsoid = 0;
214  }
215  if (theWgs72Ellipsoid)
216  {
217  delete theWgs72Ellipsoid;
218  theWgs72Ellipsoid = 0;
219  }
220 }
221 
222 //*************************************************************************************************
223 // Given an alpha code (for example "WE" for WGS84), returns the corresponding EPSG code or 0
224 // if not found.
225 //*************************************************************************************************
227 {
228  ossim_uint32 epsg_code = 0;
229  if (alpha_code.empty())
230  return 0;
231 
232  EpsgTableType::const_iterator iter = theEpsgTable.begin();
233  while ((iter != theEpsgTable.end()) && (epsg_code == 0))
234  {
235  if (iter->second == alpha_code.string())
236  {
237  epsg_code = iter->first;
238  }
239  iter++;
240  }
241  return epsg_code;
242 }
static ossimEllipsoidFactory * instance()
ossimEllipsoid * theWgs72Ellipsoid
ossim_uint32 toUInt32() const
ossimEllipsoid * theWgs84Ellipsoid
unsigned int ossim_uint32
const ossimEllipsoid * create(const ossimString &code) const
ossim_uint32 findEpsgCode(const ossimString &alpha_code) const
Given an alpha code (for example "WE" for WGS84), returns the corresponding EPSG code or 0 if not fou...
bool empty() const
Definition: ossimString.h:411
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
const std::string & string() const
Definition: ossimString.h:414