25 #include "terralib_config.h" 
   26 #include "../common/Translator.h" 
   33 #ifdef TERRALIB_PROJ4_ENABLED 
   43 #include <boost/thread/mutex.hpp> 
   48   m_sourcePj4Handler(0),
 
   54   m_targetSRID(targetSRID),
 
   55   m_sourceSRID(sourceSRID),
 
   56   m_sourcePj4Handler(0),
 
   59 #ifdef TERRALIB_PROJ4_ENABLED   
   61   if (description.empty())
 
   62     throw te::srs::Exception(
TE_TR(
"Source SRS ID not recognized."));
 
   67     std::string exceptionTxt = 
TE_TR(
"Source SRS description is not valid: ");
 
   68     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
   69     exceptionTxt += std::string(pjError);
 
   70     throw te::srs::Exception(exceptionTxt);
 
   74   if ( description.empty())
 
   75       throw te::srs::Exception(
TE_TR(
"Target SRS ID not recognized."));
 
   80     std::string exceptionTxt = 
TE_TR(
"Target SRS description is not valid: ");
 
   81     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
   82     exceptionTxt += std::string(pjError);
 
   83     throw te::srs::Exception(exceptionTxt);
 
   93 #ifdef TERRALIB_PROJ4_ENABLED  
   94   if (m_sourcePj4Handler)
 
   95     pj_free(m_sourcePj4Handler);
 
   97   if (m_targetPj4Handler)
 
   98     pj_free(m_targetPj4Handler);
 
  100   m_sourcePj4Handler = 0;
 
  101   m_targetPj4Handler = 0;
 
  109 #ifdef TERRALIB_PROJ4_ENABLED  
  110   if (m_sourcePj4Handler)
 
  112     pj_free(m_sourcePj4Handler);
 
  113     m_sourcePj4Handler = 0;
 
  117   if (description.empty())
 
  121     throw te::srs::Exception(
TE_TR(
"Source SRS ID not recognized."));
 
  124   m_sourcePj4Handler = pj_init_plus(description.c_str());
 
  125   if (!m_sourcePj4Handler)
 
  127     std::string exceptionTxt = 
TE_TR(
"Source SRS description is not valid: ");
 
  128     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
  129     exceptionTxt += std::string(pjError);
 
  134     throw te::srs::Exception(exceptionTxt);
 
  137   m_sourceSRID = sourceSRID;
 
  145   assert(!pj4txt.empty());
 
  147 #ifdef TERRALIB_PROJ4_ENABLED  
  148   if (m_sourcePj4Handler)
 
  150     pj_free(m_sourcePj4Handler);
 
  151     m_sourcePj4Handler = 0;
 
  154   m_sourcePj4Handler = pj_init_plus(pj4txt.c_str());
 
  155   if (!m_sourcePj4Handler)
 
  157     std::string exceptionTxt = 
TE_TR(
"Source SRS PROJ4 description is not valid: ");
 
  158     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
  159     exceptionTxt += std::string(pjError);
 
  160     throw te::srs::Exception(exceptionTxt);
 
  177 #ifdef TERRALIB_PROJ4_ENABLED  
  178   if (m_targetPj4Handler)
 
  180     pj_free(m_targetPj4Handler);
 
  181     m_targetPj4Handler = 0;
 
  185   if (description.empty())
 
  190     throw te::srs::Exception(
TE_TR(
"Target SRS ID not recognized."));
 
  193   m_targetPj4Handler = pj_init_plus(description.c_str());
 
  194   if (!m_targetPj4Handler)
 
  196     std::string exceptionTxt = 
TE_TR(
"Target SRS description is not valid: ");
 
  197     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
  198     exceptionTxt += std::string(pjError);
 
  203     throw te::srs::Exception(exceptionTxt);
 
  206   m_targetSRID = targetSRID;  
 
  214   assert(!pj4txt.empty());
 
  216 #ifdef TERRALIB_PROJ4_ENABLED  
  217   if (m_targetPj4Handler)
 
  219     pj_free(m_targetPj4Handler);
 
  220     m_targetPj4Handler = 0;
 
  223   m_targetPj4Handler = pj_init_plus(pj4txt.c_str());
 
  224   if (!m_targetPj4Handler)
 
  226     std::string exceptionTxt = 
TE_TR(
"Target SRS PROJ4 description is not valid: ");
 
  227     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
  228     exceptionTxt += std::string(pjError);
 
  229     throw te::srs::Exception(exceptionTxt);
 
  244 #ifdef TERRALIB_PROJ4_ENABLED  
  245   assert(m_sourcePj4Handler);
 
  246   assert(m_targetPj4Handler);
 
  248   memcpy(xOut, xIn, numCoord*
sizeof(
double));
 
  249   memcpy(yOut, yIn, numCoord*
sizeof(
double));
 
  251   if (pj_is_latlong(m_sourcePj4Handler))
 
  252     for (
long i=0; i<numCoord; xOut[i*coordOffset]*=DEG_TO_RAD, yOut[i*coordOffset]*=DEG_TO_RAD,  ++i);
 
  254   int res = pj_transform(m_sourcePj4Handler, m_targetPj4Handler,  numCoord, coordOffset, xOut, yOut, 0);
 
  256   if (res==0 && pj_is_latlong(m_targetPj4Handler))
 
  257     for (
long i=0; i<numCoord; xOut[i*coordOffset]*=RAD_TO_DEG,yOut[i*coordOffset]*=RAD_TO_DEG, ++i);
 
  261   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  268 #ifdef TERRALIB_PROJ4_ENABLED  
  269   assert(m_sourcePj4Handler);
 
  270   assert(m_targetPj4Handler);
 
  272   if (pj_is_latlong(m_sourcePj4Handler))
 
  273     for (
long i=0; i<numCoord; x[i*coordOffset]*=DEG_TO_RAD, y[i*coordOffset]*=DEG_TO_RAD,  ++i);
 
  275   int res = pj_transform(m_sourcePj4Handler, m_targetPj4Handler,  numCoord, coordOffset, x, y, 0);
 
  277   if (res==0 && pj_is_latlong(m_targetPj4Handler))
 
  278     for (
long i=0; i<numCoord; x[i*coordOffset]*=RAD_TO_DEG,y[i*coordOffset]*=RAD_TO_DEG, ++i);
 
  282   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  289 #ifdef TERRALIB_PROJ4_ENABLED  
  290   assert(m_sourcePj4Handler);
 
  291   assert(m_targetPj4Handler);
 
  296   if (pj_is_latlong(m_sourcePj4Handler))
 
  302   int res = pj_transform(m_sourcePj4Handler, m_targetPj4Handler,  1, 1, &xOut, &yOut, 0);
 
  304   if (pj_is_latlong(m_targetPj4Handler))
 
  311   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  318 #ifdef TERRALIB_PROJ4_ENABLED  
  319   assert(m_sourcePj4Handler);
 
  320   assert(m_targetPj4Handler);
 
  322   if (pj_is_latlong(m_sourcePj4Handler))
 
  328   int res = pj_transform(m_sourcePj4Handler, m_targetPj4Handler,  1, 1, &x, &y, 0);
 
  330   if (pj_is_latlong(m_targetPj4Handler))
 
  337   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  344 #ifdef TERRALIB_PROJ4_ENABLED  
  345   assert(m_sourcePj4Handler);
 
  346   assert(m_targetPj4Handler);
 
  348   memcpy(xOut, xIn, numCoord*
sizeof(
double));
 
  349   memcpy(yOut, yIn, numCoord*
sizeof(
double));
 
  351   if (pj_is_latlong(m_targetPj4Handler))
 
  352     for (
long i=0; i<numCoord; xOut[i*coordOffset]*=DEG_TO_RAD, yOut[i*coordOffset]*=DEG_TO_RAD, ++i);
 
  354   int res = pj_transform(m_targetPj4Handler, m_sourcePj4Handler,  numCoord, coordOffset, xOut, yOut, 0);
 
  356   if (res==0 && pj_is_latlong(m_sourcePj4Handler))
 
  357     for (
long i=0; i<numCoord; xOut[i*coordOffset]*=RAD_TO_DEG, yOut[i*coordOffset]*=RAD_TO_DEG, ++i);
 
  361   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  368 #ifdef TERRALIB_PROJ4_ENABLED  
  369   assert(m_sourcePj4Handler);
 
  370   assert(m_targetPj4Handler);
 
  372   if (pj_is_latlong(m_targetPj4Handler))
 
  373     for (
long i=0; i<numCoord; x[i*coordOffset]*=DEG_TO_RAD, y[i]*=DEG_TO_RAD, ++i);
 
  375   int res = pj_transform(m_targetPj4Handler, m_sourcePj4Handler,  numCoord, coordOffset, x, y, 0);
 
  377   if (res==0 && pj_is_latlong(m_sourcePj4Handler))
 
  378     for (
long i=0; i<numCoord; x[i*coordOffset]*=RAD_TO_DEG, y[i]*=RAD_TO_DEG, ++i);
 
  382   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  389 #ifdef TERRALIB_PROJ4_ENABLED  
  390   assert(m_sourcePj4Handler);
 
  391   assert(m_targetPj4Handler);
 
  396   if (pj_is_latlong(m_targetPj4Handler))
 
  402   int res = pj_transform(m_targetPj4Handler, m_sourcePj4Handler,  1, 1, &xOut, &yOut, 0);
 
  404   if (res==0 && pj_is_latlong(m_sourcePj4Handler))
 
  412   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  419 #ifdef TERRALIB_PROJ4_ENABLED  
  420   assert(m_sourcePj4Handler);
 
  421   assert(m_targetPj4Handler);
 
  423   if (pj_is_latlong(m_targetPj4Handler))
 
  429   int res = pj_transform(m_targetPj4Handler, m_sourcePj4Handler,  1, 1, &x, &y, 0);
 
  431   if (res==0 && pj_is_latlong(m_sourcePj4Handler))
 
  439   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinates conversion."));
 
  447 #ifdef TERRALIB_PROJ4_ENABLED  
  450   if (description.empty())
 
  453   projPJ pjhProj = pj_init_plus(description.c_str());
 
  456     std::string exceptionTxt = 
TE_TR(
"srs Source SRS description is not valid: ");
 
  457     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
  458     exceptionTxt += std::string(pjError);
 
  462   if (pj_is_latlong(pjhProj))
 
  468   projPJ pjhGeog = pj_latlong_from_proj(pjhProj);
 
  469   int res = pj_transform(pjhProj, pjhGeog, 1, 1, &x, &y, 0);
 
  481   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  487 #ifdef TERRALIB_PROJ4_ENABLED  
  489   if (description.empty())
 
  490     throw te::srs::Exception(
TE_TR(
"Source SRS ID not recognized."));
 
  492   projPJ pjhProj = pj_init_plus(description.c_str());
 
  495     std::string exceptionTxt = 
TE_TR(
"Source SRS description is not valid: ");
 
  496     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
  497     exceptionTxt += std::string(pjError);
 
  500   projPJ pjhGeog = pj_latlong_from_proj(pjhProj);
 
  504   int res = pj_transform(pjhGeog, pjhProj, 1, 1, &lon, &lat, 0);
 
  511   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. 
 
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. 
 
std::string getP4Txt(unsigned int id, const std::string &authName="EPSG") const 
Returns a coordinate system PROJ4 description given an identification. 
 
#define TE_TR(message)
It marks a string in order to get translated. 
 
An exception class for the SRS module. 
 
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. 
 
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib. 
 
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.