Isis 3 Programmer Reference
Equirectangular.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "Equirectangular.h"
8 
9 #include <cmath>
10 #include <cfloat>
11 
12 #include "Constants.h"
13 #include "IException.h"
14 #include "TProjection.h"
15 #include "Pvl.h"
16 #include "PvlGroup.h"
17 #include "PvlKeyword.h"
18 
19 using namespace std;
20 namespace Isis {
49  Equirectangular::Equirectangular(Pvl &label, bool allowDefaults) :
50  TProjection::TProjection(label) {
51  try {
52  // Try to read the mapping group
53  PvlGroup &mapGroup = label.findGroup("Mapping", Pvl::Traverse);
54 
55  // Compute the default value if allowed and needed
56  if (!mapGroup.hasKeyword("CenterLongitude")) {
57  if (allowDefaults) {
58  double lon = (m_minimumLongitude + m_maximumLongitude) / 2.0;
59  mapGroup += PvlKeyword("CenterLongitude", toString(lon));
60  }
61  else {
62  QString message = "Cannot project using Equirectangular Cylindrical";
63  message += " without [CenterLongitude] value. Keyword does not exist";
64  message += " in labels and defaults are not allowed.";
65  throw IException(IException::Unknown, message, _FILEINFO_);
66  }
67  }
68 
69  if (!mapGroup.hasKeyword("CenterLatitude")) {
70  if (allowDefaults) {
71  double lat = (m_minimumLatitude + m_maximumLatitude) / 2.0;
72  mapGroup += PvlKeyword("CenterLatitude", toString(lat));
73  }
74  else {
75  QString message = "Cannot project using Equirectangular Cylindrical";
76  message += " without [CenterLatitude] value. Keyword does not exist";
77  message += " in labels and defaults are not allowed.";
78  throw IException(IException::Unknown, message, _FILEINFO_);
79  }
80  }
81 
82  // Get the center longitude, convert to radians, adjust for longitude
83  // direction
84  m_centerLongitude = mapGroup["CenterLongitude"];
85  m_centerLongitude *= PI / 180.0;
87 
88  // Get the center latitude, the radius at the clat, and convert to radians
89  m_centerLatitude = mapGroup["CenterLatitude"];
91  m_centerLatitude *= PI / 180.0;
92 
93  // This keyword is just for user's information, and was put in for Hirise
94  if (!mapGroup.hasKeyword("CenterLatitudeRadius")) {
95  mapGroup += PvlKeyword("CenterLatitudeRadius");
96  }
97 
98  mapGroup["CenterLatitudeRadius"] = toString(m_clatRadius);
99 
100  // Compute cos of the center latitude and make sure it is valid as
101  // we will be dividing with it later on
103  if (fabs(m_cosCenterLatitude) < DBL_EPSILON) {
104  QString message = "Keyword value for CenterLatitude is "
105  "too close to the pole";
106  throw IException(IException::Io, message, _FILEINFO_);
107  }
108  }
109  catch(IException &e) {
110  QString message = "Invalid label group [Mapping]";
111  throw IException(e, IException::Io, message, _FILEINFO_);
112  }
113  }
114 
117  }
118 
128  if (!Projection::operator==(proj)) return false;
129  // dont do the below it is a recusive plunge
130  // if (Projection::operator!=(proj)) return false;
131  Equirectangular *equi = (Equirectangular *) &proj;
132  if (equi->m_centerLongitude != m_centerLongitude) return false;
133  if (equi->m_centerLatitude != m_centerLatitude) return false;
134  return true;
135  }
136 
142  QString Equirectangular::Name() const {
143  return "Equirectangular";
144  }
145 
151  QString Equirectangular::Version() const {
152  return "1.0";
153  }
154 
162  return m_centerLatitude * 180.0 / PI;
163  }
164 
171  return true;
172  }
173 
185  bool Equirectangular::SetGround(const double lat, const double lon) {
186  // Convert to radians
187  m_latitude = lat;
188  m_longitude = lon;
189  double latRadians = lat * PI / 180.0;
190  double lonRadians = lon * PI / 180.0;
191  if (m_longitudeDirection == PositiveWest) lonRadians *= -1.0;
192 
193  // Compute the coordinate
194  double deltaLon = (lonRadians - m_centerLongitude);
195  double x = m_clatRadius * m_cosCenterLatitude * deltaLon;
196  double y = m_clatRadius * latRadians;
197  SetComputedXY(x, y);
198  m_good = true;
199  return m_good;
200  }
201 
215  bool Equirectangular::SetCoordinate(const double x, const double y) {
216  // Save the coordinate
217  SetXY(x, y);
218 
219  // Compute latitude and make sure it is not above 90
221  if ((fabs(m_latitude) - HALFPI) > DBL_EPSILON) {
222  m_good = false;
223  return m_good;
224  }
225 
226  // Compute longitude
229 
230  // Convert to degrees
231  m_latitude *= 180.0 / PI;
232  m_longitude *= 180.0 / PI;
233 
234  // Cleanup the longitude
236  // Do these if the projection is circular
237  // m_longitude = To360Domain (m_longitude);
238  // if (m_longitudeDomain == 180) m_longitude = To180Domain(m_longitude);
239 
240  m_good = true;
241  return m_good;
242  }
243 
267  bool Equirectangular::XYRange(double &minX, double &maxX,
268  double &minY, double &maxY) {
269  // Check the corners of the lat/lon range
274 
275  // Make sure everything is ordered
276  if (m_minimumX >= m_maximumX) return false;
277  if (m_minimumY >= m_maximumY) return false;
278 
279  // Return X/Y min/maxs
280  minX = m_minimumX;
281  maxX = m_maximumX;
282  minY = m_minimumY;
283  maxY = m_maximumY;
284  return true;
285  }
286 
294  PvlGroup mapping = TProjection::Mapping();
295 
296  mapping += m_mappingGrp["CenterLatitude"];
297  mapping += m_mappingGrp["CenterLongitude"];
298 
299  return mapping;
300  }
301 
310 
311  mapping += m_mappingGrp["CenterLatitude"];
312 
313  return mapping;
314  }
315 
324 
325  mapping += m_mappingGrp["CenterLongitude"];
326 
327  return mapping;
328  }
329 
330 }
331 
344 extern "C" Isis::Projection *EquirectangularPlugin(Isis::Pvl &lab,
345  bool allowDefaults) {
346  return new Isis::Equirectangular(lab, allowDefaults);
347 }
348 
Isis::TProjection::m_maximumLatitude
double m_maximumLatitude
Contains the maximum latitude for the entire ground range.
Definition: TProjection.h:356
Isis::Equirectangular::Name
QString Name() const
Returns the name of the map projection, "Equirectangular".
Definition: Equirectangular.cpp:142
Isis::HALFPI
const double HALFPI
The mathematical constant PI/2.
Definition: Constants.h:41
Isis::Equirectangular::SetGround
bool SetGround(const double lat, const double lon)
This method is used to set the latitude/longitude (assumed to be of the correct LatitudeType,...
Definition: Equirectangular.cpp:185
Isis::TProjection::m_longitude
double m_longitude
This contains the currently set longitude value.
Definition: TProjection.h:318
Isis::PvlObject::findGroup
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:129
Isis::IException::Io
@ Io
A type of error that occurred when performing an actual I/O operation.
Definition: IException.h:155
Isis::TProjection::m_minimumLongitude
double m_minimumLongitude
Contains the minimum longitude for the entire ground range.
Definition: TProjection.h:358
Isis::Equirectangular::MappingLatitudes
virtual PvlGroup MappingLatitudes()
This function returns a PvlGroup containing the latitude keywords that this projection uses,...
Definition: Equirectangular.cpp:308
Isis::TProjection::m_latitude
double m_latitude
This contains the currently set latitude value.
Definition: TProjection.h:316
Isis::PI
const double PI
The mathematical constant PI.
Definition: Constants.h:40
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::Equirectangular::m_centerLatitude
double m_centerLatitude
The center latitude for the map projection.
Definition: Equirectangular.h:91
Isis::TProjection::m_longitudeDirection
LongitudeDirection m_longitudeDirection
An enumerated type indicating the LongitudeDirection read from the labels.
Definition: TProjection.h:324
Isis::TProjection::m_minimumLatitude
double m_minimumLatitude
Contains the minimum latitude for the entire ground range.
Definition: TProjection.h:354
Isis::TProjection::PositiveWest
@ PositiveWest
Longitude values increase in the westerly direction.
Definition: TProjection.h:225
Isis::IException::Unknown
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:118
Isis::Projection::m_minimumY
double m_minimumY
See minimumX description.
Definition: Projection.h:327
Isis::Projection::GetX
double GetX() const
Calculates the unrotated form of current x value.
Definition: Projection.cpp:818
Isis::PvlContainer::hasKeyword
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Definition: PvlContainer.cpp:159
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::Projection::SetXY
void SetXY(double x, double y)
This protected method is a helper for derived classes.
Definition: Projection.cpp:804
Isis::Equirectangular::TrueScaleLatitude
double TrueScaleLatitude() const
Returns the latitude of true scale, in degrees.
Definition: Equirectangular.cpp:161
Isis::TProjection::XYRangeCheck
void XYRangeCheck(const double latitude, const double longitude)
This convience function is established to assist in the development of the XYRange virtual method.
Definition: TProjection.cpp:1062
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::Projection::m_mappingGrp
PvlGroup m_mappingGrp
Mapping group that created this projection.
Definition: Projection.h:329
Isis::Projection::GetY
double GetY() const
Calculates the unrotated form of the current y value.
Definition: Projection.cpp:829
Isis::PvlObject::Traverse
@ Traverse
Search child objects.
Definition: PvlObject.h:158
Isis::Equirectangular::SetCoordinate
bool SetCoordinate(const double x, const double y)
This method is used to set the projection x/y.
Definition: Equirectangular.cpp:215
Isis::Projection::m_minimumX
double m_minimumX
The data elements m_minimumX, m_minimumY, m_maximumX, and m_maximumY are convience data elements when...
Definition: Projection.h:317
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::Equirectangular::operator==
bool operator==(const Projection &proj)
Compares two Projection objects to see if they are equal.
Definition: Equirectangular.cpp:127
Isis::Projection::m_good
bool m_good
Indicates if the contents of m_x, m_y, m_latitude, and m_longitude are valid.
Definition: Projection.h:300
Isis::TProjection
Base class for Map TProjections.
Definition: TProjection.h:166
Isis::Equirectangular::~Equirectangular
~Equirectangular()
Destroys the Equirectangular object.
Definition: Equirectangular.cpp:116
Isis::Equirectangular::Mapping
virtual PvlGroup Mapping()
This function returns a PvlGroup containing the keywords that this projection uses,...
Definition: Equirectangular.cpp:293
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::Equirectangular::m_clatRadius
double m_clatRadius
The radius of the target planet at the center latitude.
Definition: Equirectangular.h:93
Isis::TProjection::MappingLongitudes
virtual PvlGroup MappingLongitudes()
This function returns the longitude keywords that this projection uses.
Definition: TProjection.cpp:1739
Isis::Equirectangular
Equirectangular Map Projection.
Definition: Equirectangular.h:70
Isis::TProjection::LocalRadius
double LocalRadius() const
This method returns the local radius in meters at the current latitude position.
Definition: TProjection.cpp:353
Isis::Projection::SetComputedXY
void SetComputedXY(double x, double y)
This protected method is a helper for derived classes.
Definition: Projection.cpp:780
Isis::Equirectangular::MappingLongitudes
virtual PvlGroup MappingLongitudes()
This function returns a PvlGroup containing the longitude keywords that this projection uses,...
Definition: Equirectangular.cpp:322
Isis::Equirectangular::m_centerLongitude
double m_centerLongitude
The center longitude for the map projection.
Definition: Equirectangular.h:90
std
Namespace for the standard library.
Isis::Equirectangular::m_cosCenterLatitude
double m_cosCenterLatitude
Cosine of the center latitude.
Definition: Equirectangular.h:92
Isis::Equirectangular::IsEquatorialCylindrical
bool IsEquatorialCylindrical()
Indicates whether the projection is Equitorial Cylindrical.
Definition: Equirectangular.cpp:170
Isis::Equirectangular::XYRange
bool XYRange(double &minX, double &maxX, double &minY, double &maxY)
This method is used to determine the x/y range which completely covers the area of interest specified...
Definition: Equirectangular.cpp:267
Isis::TProjection::m_maximumLongitude
double m_maximumLongitude
Contains the maximum longitude for the entire ground range.
Definition: TProjection.h:360
Isis::TProjection::MappingLatitudes
virtual PvlGroup MappingLatitudes()
This function returns the latitude keywords that this projection uses.
Definition: TProjection.cpp:1723
Isis::Equirectangular::Version
QString Version() const
Returns the version of the map projection.
Definition: Equirectangular.cpp:151
Isis::TProjection::Mapping
virtual PvlGroup Mapping()
This function returns the keywords that this projection uses.
Definition: TProjection.cpp:1698
Isis::Projection::m_maximumY
double m_maximumY
See minimumX description.
Definition: Projection.h:328
Isis::Projection
Base class for Map Projections.
Definition: Projection.h:155
Isis::Projection::m_maximumX
double m_maximumX
See minimumX description.
Definition: Projection.h:326
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16