OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
GroundControlPoint.cpp
Go to the documentation of this file.
1 //**************************************************************************************************
2 //
3 // OSSIM Open Source Geospatial Data Processing Library
4 // See top level LICENSE.txt file for license information
5 //
6 //**************************************************************************************************
7 
10 #include <ossim/base/ossimGpt.h>
11 
12 namespace ossim
13 {
14 
16 {
17 
18 }
19 
20 GroundControlPoint::GroundControlPoint(const Json::Value& json_node)
21 : m_covariance (3)
22 {
23  m_covariance.ReSize(3);
24  loadJSON(json_node);
25 }
26 
27 
29 {
30 
31 }
32 
33 void GroundControlPoint::loadJSON(const Json::Value& json_node)
34 {
35  ostringstream xmsg;
36  xmsg<<__FILE__<<": ";
37 
38  m_id = json_node["gcpId"].asString();
39  if (m_id.empty())
40  m_id = json_node["pointId"].asString();
41 
42  if (json_node.isMember("lat") && json_node.isMember("lon") && json_node.isMember("hgt"))
43  {
44  ossimGpt refGpt;
45  refGpt.lat = json_node["lat"].asDouble();
46  refGpt.lon = json_node["lon"].asDouble();
47  refGpt.hgt = json_node["hgt"].asDouble();
48  m_gcp = ossimEcefPoint(refGpt);
49  }
50  else if (json_node.isMember("x") && json_node.isMember("y") && json_node.isMember("z"))
51  {
52  m_gcp.x() = json_node["x"].asDouble();
53  m_gcp.y() = json_node["y"].asDouble();
54  m_gcp.z() = json_node["z"].asDouble();
55  }
56  else
57  {
58  xmsg<<"Ground point coordinates JSON not correct. JSON: \n"<<json_node.toStyledString()<<endl;
59  throw ossimException(xmsg.str());
60  }
61 
62  const Json::Value& covariance = json_node["covariance"];
63  unsigned int covSize = covariance.size();
64  if ((covSize != 6) || (covSize != 9))
65  {
66  xmsg<<"No covariance information in JSON or not correctly formatted (must be 6 or 9 element array)";
67  throw ossimException(xmsg.str());
68  }
69 
70  // TODO: Covariance in proper coordinate system. ENU -> ECF conversion needed here?
71  if (covSize == 6)
72  {
73  m_covariance(0,0) = covariance[0].asDouble();
74  m_covariance(1,1) = covariance[1].asDouble();
75  m_covariance(2,2) = covariance[2].asDouble();
76  m_covariance(0,1) = covariance[3].asDouble();
77  m_covariance(0,2) = covariance[4].asDouble();
78  m_covariance(1,2) = covariance[5].asDouble();
79  }
80  else
81  {
82  m_covariance(0,0) = covariance[0].asDouble();
83  m_covariance(0,1) = covariance[1].asDouble();
84  m_covariance(0,2) = covariance[2].asDouble();
85  m_covariance(1,0) = covariance[3].asDouble();
86  m_covariance(1,1) = covariance[4].asDouble();
87  m_covariance(1,2) = covariance[5].asDouble();
88  m_covariance(2,0) = covariance[6].asDouble();
89  m_covariance(2,1) = covariance[7].asDouble();
90  m_covariance(2,2) = covariance[8].asDouble();
91  }
92 
93  // TODO: Implement GCP cross-correlation
94  if (json_node.isMember("crossCovariances") || json_node.isMember("gpCrossCovList"))
95  {
96  ossimNotify(ossimNotifyLevel_WARN)<<"GCP cross covariances are specified in the JSON, but the"
97  " capability is not yet implemented!"<<endl;
98  }
99 }
100 
101 void GroundControlPoint::saveJSON(Json::Value& json_node) const
102 {
103  // ID
104  json_node["gcpId"] = m_id;
105 
106  // ECF
107  json_node["X"] = m_gcp.x();
108  json_node["Y"] = m_gcp.y();
109  json_node["Z"] = m_gcp.z();
110 
111  Json::Value covJson (Json::arrayValue);
112  covJson[0] = m_covariance(1,1);
113  covJson[1] = m_covariance(2,2);
114  covJson[2] = m_covariance(3,3);
115  covJson[3] = m_covariance(1,2);
116  covJson[4] = m_covariance(1,3);
117  covJson[5] = m_covariance(2,3);
118 
119  json_node["covariance"] = covJson;
120 }
121 } // end namespace ossimMsp
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
NEWMAT::SymmetricMatrix m_covariance
This code was derived from https://gist.github.com/mshockwave.
Definition: Barrier.h:8
double x() const
ossim_float64 hgt
Height in meters above the ellipsiod.
Definition: ossimGpt.h:274
ossim_float64 lon
Definition: ossimGpt.h:266
virtual void loadJSON(const Json::Value &json)
double y() const
ossim_float64 lat
Definition: ossimGpt.h:265
virtual void saveJSON(Json::Value &json) const
double z() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)