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
19using namespace std;
20namespace 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
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
344extern "C" Isis::Projection *EquirectangularPlugin(Isis::Pvl &lab,
345 bool allowDefaults) {
346 return new Isis::Equirectangular(lab, allowDefaults);
347}
348
Equirectangular Map Projection.
virtual PvlGroup MappingLatitudes()
This function returns a PvlGroup containing the latitude keywords that this projection uses,...
virtual PvlGroup Mapping()
This function returns a PvlGroup containing the keywords that this projection uses,...
QString Version() const
Returns the version of the map projection.
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...
bool IsEquatorialCylindrical()
Indicates whether the projection is Equitorial Cylindrical.
~Equirectangular()
Destroys the Equirectangular object.
bool SetGround(const double lat, const double lon)
This method is used to set the latitude/longitude (assumed to be of the correct LatitudeType,...
double m_cosCenterLatitude
Cosine of the center latitude.
double m_clatRadius
The radius of the target planet at the center latitude.
double m_centerLongitude
The center longitude for the map projection.
virtual PvlGroup MappingLongitudes()
This function returns a PvlGroup containing the longitude keywords that this projection uses,...
bool SetCoordinate(const double x, const double y)
This method is used to set the projection x/y.
bool operator==(const Projection &proj)
Compares two Projection objects to see if they are equal.
double TrueScaleLatitude() const
Returns the latitude of true scale, in degrees.
QString Name() const
Returns the name of the map projection, "Equirectangular".
Equirectangular(Pvl &label, bool allowDefaults=false)
Constructs a Equirectangular object.
double m_centerLatitude
The center latitude for the map projection.
Isis exception class.
Definition IException.h:91
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition IException.h:118
@ Io
A type of error that occurred when performing an actual I/O operation.
Definition IException.h:155
Base class for Map Projections.
Definition Projection.h:155
double m_maximumX
See minimumX description.
Definition Projection.h:326
double GetX() const
Calculates the unrotated form of current x value.
bool m_good
Indicates if the contents of m_x, m_y, m_latitude, and m_longitude are valid.
Definition Projection.h:300
double m_minimumX
The data elements m_minimumX, m_minimumY, m_maximumX, and m_maximumY are convience data elements when...
Definition Projection.h:317
PvlGroup m_mappingGrp
Mapping group that created this projection.
Definition Projection.h:329
double m_minimumY
See minimumX description.
Definition Projection.h:327
double GetY() const
Calculates the unrotated form of the current y value.
void SetXY(double x, double y)
This protected method is a helper for derived classes.
double m_maximumY
See minimumX description.
Definition Projection.h:328
void SetComputedXY(double x, double y)
This protected method is a helper for derived classes.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
A single keyword-value pair.
Definition PvlKeyword.h:87
@ Traverse
Search child objects.
Definition PvlObject.h:158
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition PvlObject.h:129
Base class for Map TProjections.
double m_longitude
This contains the currently set longitude value.
double m_minimumLatitude
Contains the minimum latitude for the entire ground range.
double m_maximumLongitude
Contains the maximum longitude for the entire ground range.
LongitudeDirection m_longitudeDirection
An enumerated type indicating the LongitudeDirection read from the labels.
virtual PvlGroup MappingLongitudes()
This function returns the longitude keywords that this projection uses.
double LocalRadius() const
This method returns the local radius in meters at the current latitude position.
void XYRangeCheck(const double latitude, const double longitude)
This convience function is established to assist in the development of the XYRange virtual method.
virtual PvlGroup MappingLatitudes()
This function returns the latitude keywords that this projection uses.
double m_minimumLongitude
Contains the minimum longitude for the entire ground range.
@ PositiveWest
Longitude values increase in the westerly direction.
double m_maximumLatitude
Contains the maximum latitude for the entire ground range.
virtual PvlGroup Mapping()
This function returns the keywords that this projection uses.
double m_latitude
This contains the currently set latitude value.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
const double HALFPI
The mathematical constant PI/2.
Definition Constants.h:41
const double PI
The mathematical constant PI.
Definition Constants.h:40
Namespace for the standard library.