CoordinateSystemRegistry.cc
Go to the documentation of this file.
1 
9 #include <map>
10 #include <string>
11 
12 #include <fwk/CoordinateSystemRegistry.h>
13 #include <utl/CoordinateSystem.h>
14 #include <utl/AugerCoordinateSystem.h>
15 #include <utl/ReferenceEllipsoid.h>
16 #include <utl/UTMPoint.h>
17 #include <utl/AugerUnits.h>
18 #include <utl/AugerException.h>
19 #include <utl/ErrorLogger.h>
20 #include <utl/ShadowPtr.h>
21 #include <fwk/CentralConfig.h>
22 #include <utl/Reader.h>
23 #include <utl/config.h>
24 #include <utl/Deprecator.h>
25 
27 using std::map;
28 using namespace utl;
29 
30 
31 namespace fwk {
32 
33  namespace CoordinateSystemRegistry {
34 
35  namespace { // private part of the implementation
36 
37  typedef map<std::string, CoordinateSystemPtr> Registry;
38 
39 
40  static utl::ShadowPtr<Registry> gRegistry;
41 
42 
43  void
44  RegisterOne(const std::string& id,
45  const CoordinateSystemPtr& cs)
46  {
47  const bool ok = gRegistry->insert(std::make_pair(id, cs)).second;
48  if (!ok) {
49  std::ostringstream msg;
50  msg << "Double insertion of coordinateSystem with id " << id;
51  WARNING(msg);
52  }
53  }
54 
55  } // anonymous namespace
56 
57 
58  void Init() {
59  if (!gRegistry)
60  gRegistry = new Registry;
61  else {
62  const std::string msg =
63  "Calling Init(), but CoordinateSystemRegistry already initialized.";
64  ERROR(msg);
65  throw utl::InitSequenceException(msg);
66  }
67 
68  const CoordinateSystemPtr& ecef = CoordinateSystem::GetRootCoordinateSystem();
70  RegisterOne("ECEF", ecef);
72 
73  Branch csList = CentralConfig::GetInstance()->GetTopBranch("coordinateSystemList");
74  for (Branch cB = csList.GetFirstChild(); cB; cB = cB.GetNextSibling()) {
75  if (cB.GetName() == "CoordinateSystem") {
76  const std::string name = cB.GetChild("Id").Get<std::string>();
77  const double northing = cB.GetChild("Northing").Get<double>();
78  const double easting = cB.GetChild("Easting").Get<double>();
79  double height = cB.GetChild("Height").Get<double>();
80  const int zone = cB.GetChild("Zone").Get<int>();
81  const char band = cB.GetChild("Band").Get<char>();
82  const UTMPoint origin(northing, easting, height, zone, band,wgs84);
84  RegisterOne(name, cs);
85  }
86  }
87  }
88 
89 
91  Get(const std::string& id)
92  {
93  if (!gRegistry)
94  Init();
95 
96  Registry::iterator it = gRegistry->find(id);
97 
98  if (it == gRegistry->end()) {
99  std::ostringstream msg;
100  msg << "Coordinate system with id " << id << " does not exist.";
101  ERROR(msg);
102  throw InvalidCoordinateSystemException(msg.str());
103  }
104 
105  return it->second;
106  }
107 
108 
109  /* Deprecated way */
112  {
113  Deprecator::GetInstance().Deprecated(
114  "fwk::CoordinateSystemRegistry::Get(const CoordinateSystemID&)",
115  "",
116  "For fetching coordinate system config from XML use "
117  "fwk::CoordinateSystemRegistry::Get(const CoordinateSystemXMLID&)"
118  );
119 
120  // map to the new method for the few coordinate systems which earlier have been hardcoded
121  switch (id) {
122  case eUndefined:
123  break;
124  case eECEF:
125  return Get("ECEF");
126  case eMalargue:
127  return Get("Malargue");
128  case ePampaAmarilla:
129  return Get("PampaAmarilla");
130  case eCLF:
131  return Get("CLF");
132  case eXLF:
133  return Get("XLF");
134  case eLamar:
135  return Get("Lamar");
136  case eNewYork:
137  return Get("NewYork");
138  }
139 
140  // if coordinate system has not been found, it is not accessible with the old method.
141  std::ostringstream msg;
142  msg << "Coordinate system with id " << id << " does not exist. Please use the new interface, "
143  "and define your coordinate system in 'coordinateSystemList.xml'.";
144  ERROR(msg);
145  throw InvalidCoordinateSystemException(msg.str());
146  }
147 
148  }
149 
150 }
Branch GetTopBranch() const
Definition: Branch.cc:63
static Policy::type Create(const Point &theOrigin, const ReferenceEllipsoid &theEllipsoid, const CoordinateSystemPtr &theReferenceCS)
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
The X-treme laser facility XLF.
The central laser facility CLF.
void Init()
Initialise the registry.
bool ok(bool okay)
Definition: testlib.cc:89
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
static const ReferenceEllipsoid & Get(const EllipsoidID theID)
Get known ellipsoid by registered ID.
T Get() const
Definition: Branch.h:271
Exception to use if sequence of initialisations violated.
Branch GetNextSibling() const
Get next sibling of this branch.
Definition: Branch.cc:284
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
Definition: Branch.h:107
Reference ellipsoids for UTM transformations.
Base class for exceptions in the CoordinateSystemRegistry.
northern site CS (exact position to be decided...)
Approximate centre of the southern site.
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
southern site CS as of conventions
CoordinateSystemID
Identifiers for all well-known coordinate systems.
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
static void InitWithECEF(const CoordinateSystemPtr &theECEF)
Initialise the registry specifying the ECEF (instead of the Root CS)
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.