Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis 3 Programmer Reference
IProj.cpp
1
5
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "IProj.h"
8
9#include <proj.h>
10
11#include "IException.h"
12#include "TProjection.h"
13#include "Pvl.h"
14#include "PvlGroup.h"
15#include "PvlKeyword.h"
16
17using namespace std;
18
19namespace Isis {
20 IProj::IProj(Pvl &label, bool allowDefaults) :
21 TProjection::TProjection(label) {
22 PvlGroup &mapGroup = label.findGroup("Mapping", Pvl::Traverse);
23 if (!mapGroup.hasKeyword("ProjStr")) {
24 QString message = "No ProjStr keyword in mapping group, either add a ProjStr or select a different projection method";
25 throw IException(IException::User, message, _FILEINFO_);
26 }
27 m_C = proj_context_create();
28 proj_log_level(m_C, PJ_LOG_ERROR);
29
30 m_userOutputProjStr = new QString(mapGroup["ProjStr"]);
31
32 /* Create a projection. */
33 std::string projString = m_userOutputProjStr->toStdString();
34 m_outputProj = proj_create(m_C, projString.c_str());
35
36 if (!m_outputProj) {
37 QString msg = "Unable to create projection from [" + QString(projString.c_str()) + "]";
38 throw IException(IException::User, msg, _FILEINFO_);
39 }
40
41 // Read the radii information from the PROJ projection
42 PJ *ellipsoid = proj_get_ellipsoid(m_C, m_outputProj);
43
44 if (ellipsoid == nullptr) {
45 QString msg = "Unable to create ellipsoid from [" + *m_userOutputProjStr + "]";
46 throw IException(IException::User, msg, _FILEINFO_);
47 }
48
49 int res = proj_ellipsoid_get_parameters(m_C, ellipsoid,
50 &m_equatorialRadius,
51 &m_polarRadius,
52 nullptr,
53 nullptr);
54
55 proj_destroy(ellipsoid);
56
57 if (res == 0) {
58 QString msg = "Unable to get ellipsoid information from [" + *m_userOutputProjStr + "]";
59 throw IException(IException::User, msg, _FILEINFO_);
60 }
61
62 m_llaProj = proj_crs_get_geodetic_crs(m_C, m_outputProj);
63
64 if (0 == m_llaProj) {
65 QString msg = "Unable to create lla projection from [" + QString(projString.c_str()) + "]";
66 throw IException(IException::Programmer, msg, _FILEINFO_);
67 }
68
69 m_llaProj2outputProj = proj_create_crs_to_crs_from_pj(m_C, m_llaProj, m_outputProj, 0, 0);
70 if (0 == m_llaProj2outputProj) {
71 QString msg = "Unable to create transform from [" + QString(projString.c_str()) + "]";
72 throw IException(IException::User, msg, _FILEINFO_);
73 }
74 }
75
78 delete m_userOutputProjStr;
79 proj_destroy(m_llaProj);
80 proj_destroy(m_outputProj);
81 proj_destroy(m_llaProj2outputProj);
82 proj_context_destroy(m_C);
83 }
84
90 QString IProj::Name() const {
91 return "Proj";
92 }
93
101 PvlGroup IProj::Mapping() {
102 PvlGroup mapping = TProjection::Mapping();
103
104 mapping.addKeyword(PvlKeyword("EquatorialRadius", toString(m_equatorialRadius, 15), "meters"), PvlContainer::InsertMode::Replace);
105 mapping.addKeyword(PvlKeyword("PolarRadius", toString(m_polarRadius, 15), "meters"), PvlContainer::InsertMode::Replace);
106 mapping += PvlKeyword("ProjStr", *m_userOutputProjStr);
107
108 return mapping;
109 }
110
117 QString IProj::Version() const {
118 return "1.0";
119 }
120
121 bool IProj::SetGround(const double lat, const double lon) {
122 m_longitude = lon;
123 m_latitude = lat;
124
125 PJ_COORD c_in;
126 c_in.lpz.lam = m_longitude;
127 c_in.lpz.phi = m_latitude;
128
129 PJ_COORD c_out = proj_trans(m_llaProj2outputProj, PJ_FWD, c_in);
130 SetComputedXY(c_out.xy.x, c_out.xy.y);
131 m_good = true;
132 return m_good;
133 }
134
135 bool IProj::SetCoordinate(const double x, const double y) {
136 SetXY(x, y);
137
138 PJ_COORD c_in;
139 c_in.xy.x = x;
140 c_in.xy.y = y;
141
142 PJ_COORD c_out = proj_trans(m_llaProj2outputProj, PJ_INV, c_in);
143
144 m_longitude = c_out.lpz.lam;
145 m_latitude = c_out.lpz.phi;
146 m_good = true;
147 return m_good;
148 }
149
175 bool IProj::XYRange(double &minX, double &maxX,
176 double &minY, double &maxY) {
177 // Check the corners of the lat/lon range
182
183 // Make sure everything is ordered
184 if (m_minimumX >= m_maximumX) return false;
185 if (m_minimumY >= m_maximumY) return false;
186
187 // Return X/Y min/maxs
188 minX = m_minimumX;
189 maxX = m_maximumX;
190 minY = m_minimumY;
191 maxY = m_maximumY;
192 return true;
193 }
194
207 extern "C" Isis::TProjection *IProjPlugin(Isis::Pvl &lab,
208 bool allowDefaults)
209 {
210 return new Isis::IProj(lab, allowDefaults);
211 }
212}
Proj Map Projection.
Definition IProj.h:35
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 IProj.cpp:121
bool SetCoordinate(const double x, const double y)
This method is used to set the projection x/y.
Definition IProj.cpp:135
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 IProj.cpp:175
QString Version() const
Returns the version of the map projection.
Definition IProj.cpp:117
PvlGroup Mapping()
This function returns the keywords that this projection uses.
Definition IProj.cpp:101
QString Name() const
Returns the name of the map projection, "Proj".
Definition IProj.cpp:90
~IProj()
Destroys the IProj object.
Definition IProj.cpp:77
double m_maximumX
See minimumX description.
Definition Projection.h:325
bool m_good
Indicates if the contents of m_x, m_y, m_latitude, and m_longitude are valid.
Definition Projection.h:299
double m_minimumX
The data elements m_minimumX, m_minimumY, m_maximumX, and m_maximumY are convience data elements when...
Definition Projection.h:316
double m_minimumY
See minimumX description.
Definition Projection.h:326
void SetXY(double x, double y)
This protected method is a helper for derived classes.
double m_maximumY
See minimumX description.
Definition Projection.h:327
void SetComputedXY(double x, double y)
This protected method is a helper for derived classes.
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_polarRadius
Polar radius of the target.
double m_maximumLongitude
Contains the maximum longitude for the entire ground range.
double m_equatorialRadius
Polar radius of the target.
void XYRangeCheck(const double latitude, const double longitude)
This convience function is established to assist in the development of the XYRange virtual method.
double m_minimumLongitude
Contains the minimum longitude for the entire ground range.
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
Isis::TProjection * IProjPlugin(Isis::Pvl &lab, bool allowDefaults)
This is the function that is called in order to instantiate a Sinusoidal object.
Definition IProj.cpp:207
QString toString(const LinearAlgebra::Vector &vector, int precision)
A global function to format LinearAlgebra::Vector as a QString with the given precision.
Namespace for the standard library.