OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimEpsgProjectionFactory.cpp
Go to the documentation of this file.
1 //*************************************************************************************************
2 // License: See top level LICENSE.txt file.
3 //
4 // Author: Oscar Kramer
5 //
6 // DESCRIPTION:
7 // Projection Factory for EPSG coded projections. These are projections
8 // that are fully defined in database files and specified via a projection coordinate system (PCS)
9 // code.
10 //
11 //*************************************************************************************************
12 // $Id: ossimEpsgProjectionFactory.cpp 22929 2014-10-29 18:11:04Z gpotts $
13 
20 #include <sstream>
21 
22 //ossimEpsgProjectionFactory* ossimEpsgProjectionFactory::m_instance = 0;
23 
24 //*************************************************************************************************
26 //*************************************************************************************************
28 {
29  static ossimEpsgProjectionFactory inst;
30 
31  return &inst;
32 
33  //if(!m_instance)
34  // m_instance = new ossimEpsgProjectionFactory;
35  //return m_instance;
36 }
37 
38 //*************************************************************************************************
40 //*************************************************************************************************
42 {
43 }
44 
45 //*************************************************************************************************
47 //*************************************************************************************************
49  const char *prefix) const
50 {
51  ossimProjection* proj = 0;
52 
53  // Look for a PCS (Projected Coordinate System) code entry and construct the basic projection.
54  // This is the bootstrap for creating the fully-initialized proj:
55  ossimString proj_spec = keywordList.find(prefix, ossimKeywordNames::PCS_CODE_KW);
56  if(!proj_spec.empty())
57  proj = createProjection(proj_spec);
58 
59  if (!proj)
60  {
61  // An alternate way of specifying an EPSG projection is by its database name:
62  proj_spec = keywordList.find(prefix, ossimKeywordNames::PROJECTION_KW);
63  proj = createProjection(proj_spec);
64  }
65 
66  if (!proj)
67  return NULL;
68 
69  // The tie points and perhaps other params might still be in the KWL, so pass the KWL on to the
70  // new projection after it has been amended with the default proj info extracted from the
71  // EPSG code (i.e., sans tiepoints and gsd):
72  ossimKeywordlist proj_kwl;
73  proj->saveState(proj_kwl, prefix);
78  proj_kwl.addList(keywordList, false); // false: do not override existing items
79  proj->loadState(proj_kwl, prefix);
80 
81  return proj;
82 }
83 
84 //*************************************************************************************************
85 // This is the principal factory method. It accepts a string in one of three formats:
86 //
87 // 1. <group>:<code>, for example "EPSG:32615"
88 // 2. <code>, for example "32615", this is the CRS code ID for the projerection.
89 // 3. AUTO:<comma-separated spec>, for specifying custom user-defined codes.
90 //
91 // Both projected and geographic (Platte Carre) codes are handled.
92 //
93 // IMPORTANT NOTE: Image tie-points cannot be conveyed by an EPSG projection code. The projection
94 // created here will not be fully initialized for use in rendering imagery.
95 //*************************************************************************************************
97 {
98  std::vector<ossimString> split_line;
99 
100  // Intercept custom codes here before resorting to the database. This really shouldn't be in this
101  // class but nobody else is parsing for it, so leave it here for now.
102  if (ossimString(spec).downcase().contains("auto"))
103  {
104  split_line = spec.after(":").explode(",");
105  return createProjFromAutoCode(split_line);
106  }
107 
108  // Strip commonly found or bar '|' from end if present.
109  ossimString s = spec;
110  s.trim(ossimString("|"));
111 
112  // Otherwise, pass along the request to the database object for record search:
114 }
115 
116 //*************************************************************************************************
119 //*************************************************************************************************
121 ossimEpsgProjectionFactory::createProjFromAutoCode(const std::vector<ossimString>& spec) const
122 {
123  if (spec.size() < 3)
124  return 0;
125 
126  ossim_uint32 code = spec[0].toUInt32();
127  ossimGpt origin (spec[2].toDouble(), spec[1].toDouble()) ;
128 
129  // Only a few AUTO codes are considered:
130  switch(code)
131  {
132  case 42001:
133  {
135  utm->setZone(origin);
136  utm->setHemisphere(origin);
137  utm->setOrigin(origin);
138  utm->update();
139  //utm->setPcsCode(42001);
140  return utm;
141  }
142 
143  case 42002:
144  {
146  transMerc->setFalseNorthing(origin.latd()>=0.0?0.0:10000000.0);
147  transMerc->setOrigin(ossimGpt(0.0, origin.lond()));
148  transMerc->setScaleFactor(.9996);
149  transMerc->update();
150  // transMerc->setPcsCode(42002);
151  return transMerc;
152  }
153 
154  case 42003:
155  {
157  ortho->setOrigin(origin);
158  ortho->update();
159  //ortho->setPcsCode(42003);
160  return ortho;
161  }
162 
163  case 42004:
164  {
166  geographic->setOrigin(origin);
167  geographic->update();
168  //geographic->setPcsCode(42004);
169  return geographic;
170  }
171  }
172  return 0;
173 }
174 
175 //*************************************************************************************************
177 {
178  return createProjection(typeName);
179 }
180 
181 //*************************************************************************************************
183  const char* prefix)const
184 {
185  return createProjection(kwl, prefix);
186 }
187 
188 //*************************************************************************************************
190 //*************************************************************************************************
192  ossim_uint32 /* entryIdx */)const
193 {
194  return 0;
195 }
196 
197 //*************************************************************************************************
200 //*************************************************************************************************
201 void ossimEpsgProjectionFactory::getTypeNameList(std::vector<ossimString>& typeList) const
202 {
204  return;
205 }
206 
ossimEpsgProjectionFactory()
Constructor loads all SRS CSV files specified in the ossim prefs.
static const char * PROJECTION_KW
double lond() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:97
Represents serializable keyword/value map.
const char * find(const char *key) const
virtual void setOrigin(const ossimGpt &origin)
Sets theOrigin to origin.
void addList(const ossimKeywordlist &src, bool overwrite=true)
virtual void setOrigin(const ossimGpt &origin)
This will set the utm zone and utm origin base on origin passed in.
ossimMapProjection * createProjFromAutoCode(const std::vector< ossimString > &spec) const
When the CRS is specified with the "AUTO:<spec>" code format, this method is invoked to parse the <sp...
virtual ossimObject * createObject(const ossimString &typeName) const
void getProjectionsList(std::vector< ossimString > &typeList) const
Populates caller&#39;s list with all projections currently represented in the database.
double latd() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:87
static const char * PIXEL_SCALE_XY_KW
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
static const char * TIE_POINT_XY_KW
static ossimEpsgProjectionDatabase * instance()
Instantiates singleton instance of this class:
unsigned int ossim_uint32
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
void setFalseNorthing(double falseNorthing)
virtual void setOrigin(const ossimGpt &origin)
std::vector< ossimString > explode(const ossimString &delimeter) const
void setZone(const ossimGpt &ground)
static const char * PCS_CODE_KW
bool empty() const
Definition: ossimString.h:411
virtual ossimProjection * createProjection(const ossimFilename &filename, ossim_uint32 entryIdx) const
STUB. Not implemented.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual void getTypeNameList(std::vector< ossimString > &typeList) const
This returns the type name of all objects in all factories.
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.
void setHemisphere(const ossimGpt &ground)
void remove(const char *key)
static ossimEpsgProjectionFactory * instance()
Implements singleton pattern.
ossimProjection * findProjection(const ossimString &proj_spec) const
Returns a projection corresponding to the projection specified, or NULL if no entry found...
Projection Factory for coded projections defined in database.
static const char * PIXEL_SCALE_UNITS_KW
static const char * TIE_POINT_UNITS_KW