25 #include "../core/translator/Translator.h" 32 #ifdef TERRALIB_PROJ4_ENABLED 42 #include <boost/thread/mutex.hpp> 47 m_sourcePj4Handler(nullptr),
48 m_targetPj4Handler(nullptr)
58 #ifdef TERRALIB_PROJ4_ENABLED 60 if (description.empty())
61 throw te::srs::Exception(
TE_TR(
"Source SRS ID not recognized."));
66 std::string exceptionTxt =
TE_TR(
"Source SRS description is not valid: ");
67 char* pjError = pj_strerrno(*(pj_get_errno_ref()));
68 exceptionTxt += std::string(pjError);
69 throw te::srs::Exception(exceptionTxt);
73 if ( description.empty())
74 throw te::srs::Exception(
TE_TR(
"Target SRS ID not recognized."));
79 std::string exceptionTxt =
TE_TR(
"Target SRS description is not valid: ");
80 char* pjError = pj_strerrno(*(pj_get_errno_ref()));
81 exceptionTxt += std::string(pjError);
82 throw te::srs::Exception(exceptionTxt);
92 #ifdef TERRALIB_PROJ4_ENABLED 108 #ifdef TERRALIB_PROJ4_ENABLED 116 if (description.empty())
120 throw te::srs::Exception(
TE_TR(
"Source SRS ID not recognized."));
126 std::string exceptionTxt =
TE_TR(
"Source SRS description is not valid: ");
127 char* pjError = pj_strerrno(*(pj_get_errno_ref()));
128 exceptionTxt += std::string(pjError);
133 throw te::srs::Exception(exceptionTxt);
144 assert(!pj4txt.empty());
146 #ifdef TERRALIB_PROJ4_ENABLED 156 std::string exceptionTxt =
TE_TR(
"Source SRS PROJ4 description is not valid: ");
157 char* pjError = pj_strerrno(*(pj_get_errno_ref()));
158 exceptionTxt += std::string(pjError);
159 throw te::srs::Exception(exceptionTxt);
176 #ifdef TERRALIB_PROJ4_ENABLED 184 if (description.empty())
189 throw te::srs::Exception(
TE_TR(
"Target SRS ID not recognized."));
195 std::string exceptionTxt =
TE_TR(
"Target SRS description is not valid: ");
196 char* pjError = pj_strerrno(*(pj_get_errno_ref()));
197 exceptionTxt += std::string(pjError);
202 throw te::srs::Exception(exceptionTxt);
213 assert(!pj4txt.empty());
215 #ifdef TERRALIB_PROJ4_ENABLED 225 std::string exceptionTxt =
TE_TR(
"Target SRS PROJ4 description is not valid: ");
226 char* pjError = pj_strerrno(*(pj_get_errno_ref()));
227 exceptionTxt += std::string(pjError);
228 throw te::srs::Exception(exceptionTxt);
243 #ifdef TERRALIB_PROJ4_ENABLED 247 memcpy(xOut, xIn, numCoord*
sizeof(
double));
248 memcpy(yOut, yIn, numCoord*
sizeof(
double));
251 for (
long i=0; i<numCoord; xOut[i*coordOffset]*=DEG_TO_RAD, yOut[i*coordOffset]*=DEG_TO_RAD, ++i);
256 for (
long i=0; i<numCoord; xOut[i*coordOffset]*=RAD_TO_DEG,yOut[i*coordOffset]*=RAD_TO_DEG, ++i);
260 throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
267 #ifdef TERRALIB_PROJ4_ENABLED 272 for (
long i=0; i<numCoord; x[i*coordOffset]*=DEG_TO_RAD, y[i*coordOffset]*=DEG_TO_RAD, ++i);
277 for (
long i=0; i<numCoord; x[i*coordOffset]*=RAD_TO_DEG,y[i*coordOffset]*=RAD_TO_DEG, ++i);
281 throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
288 #ifdef TERRALIB_PROJ4_ENABLED 310 throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
317 #ifdef TERRALIB_PROJ4_ENABLED 336 throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
343 #ifdef TERRALIB_PROJ4_ENABLED 347 memcpy(xOut, xIn, numCoord*
sizeof(
double));
348 memcpy(yOut, yIn, numCoord*
sizeof(
double));
351 for (
long i=0; i<numCoord; xOut[i*coordOffset]*=DEG_TO_RAD, yOut[i*coordOffset]*=DEG_TO_RAD, ++i);
356 for (
long i=0; i<numCoord; xOut[i*coordOffset]*=RAD_TO_DEG, yOut[i*coordOffset]*=RAD_TO_DEG, ++i);
360 throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
367 #ifdef TERRALIB_PROJ4_ENABLED 372 for (
long i=0; i<numCoord; x[i*coordOffset]*=DEG_TO_RAD, y[i]*=DEG_TO_RAD, ++i);
377 for (
long i=0; i<numCoord; x[i*coordOffset]*=RAD_TO_DEG, y[i]*=RAD_TO_DEG, ++i);
381 throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
388 #ifdef TERRALIB_PROJ4_ENABLED 411 throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
418 #ifdef TERRALIB_PROJ4_ENABLED 438 throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinates conversion."));
446 #ifdef TERRALIB_PROJ4_ENABLED 449 if (description.empty())
452 projPJ pjhProj = pj_init_plus(description.c_str());
455 std::string exceptionTxt =
TE_TR(
"srs Source SRS description is not valid: ");
456 char* pjError = pj_strerrno(*(pj_get_errno_ref()));
457 exceptionTxt += std::string(pjError);
461 if (pj_is_latlong(pjhProj))
467 projPJ pjhGeog = pj_latlong_from_proj(pjhProj);
468 int res = pj_transform(pjhProj, pjhGeog, 1, 1, &x, &y,
nullptr);
480 throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
486 #ifdef TERRALIB_PROJ4_ENABLED 488 if (description.empty())
489 throw te::srs::Exception(
TE_TR(
"Source SRS ID not recognized."));
491 projPJ pjhProj = pj_init_plus(description.c_str());
494 std::string exceptionTxt =
TE_TR(
"Source SRS description is not valid: ");
495 char* pjError = pj_strerrno(*(pj_get_errno_ref()));
496 exceptionTxt += std::string(pjError);
499 projPJ pjhGeog = pj_latlong_from_proj(pjhProj);
503 int res = pj_transform(pjhGeog, pjhProj, 1, 1, &lon, &lat,
nullptr);
510 throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
bool convertToGeographic(double &x, double &y, int SRID) const
Converts a coordinate from a projected SRS to its underlying geographic SRS (same Datum)...
bool convert(double *xIn, double *yIn, double *xOut, double *yOut, long numCoord, int coordOffset=1) const
Converts a vector of coordinates from source SRS to target SRS.
bool convertToProjected(double &lon, double &lat, int SRID) const
Converts a coordinate from a geographic SRS to a projected SRS based on the same Datum.
void setTargetPJ4txt(const std::string &pj4txt)
Sets the target SRS PROJ4 description.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
A class to manage Coordinate Systems representations.
bool invert(double *xIn, double *yIn, double *xOut, double *yOut, long numCoord, int coordOffset=1) const
Inverts a vector of coordinates from target SRS to dource SRS.
An exception class for the SRS module.
#define TE_TR(message)
It marks a string in order to get translated.
void setSourcePJ4txt(const std::string &pj4txt)
Sets the source SRS PROJ4 description.
void setSourceSRID(int sourceSRID)
Sets the source SRS identifier.
void * m_sourcePj4Handler
int getSourceSRID() const
Gets source SRS identifier.
int getTargetSRID() const
Gets target SRS identifier.
static SpatialReferenceSystemManager & getInstance()
It returns a reference to the singleton instance.
void setTargetSRID(int targetSRID)
Sets the target SRS identifier.
Converter()
Default empty constructor.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
void * m_targetPj4Handler
This file contains the support to convert coordinates from a SRS to another.
TESRSEXPORT boost::mutex & getStaticMutex()
Returns a reference to a static mutex initialized when this module is initialized.