25 #include "../common/Translator.h" 
   32 #ifdef TERRALIB_PROJ4_ENABLED 
   44   m_sourcePj4Handler(0),
 
   50   m_targetSRID(targetSRID),
 
   51   m_sourceSRID(sourceSRID),
 
   52   m_sourcePj4Handler(0),
 
   55 #ifdef TERRALIB_PROJ4_ENABLED   
   57   if (description.empty())
 
   58     throw te::srs::Exception(
TE_TR(
"Source SRS ID not recognized."));
 
   63     std::string exceptionTxt = 
TE_TR(
"Source SRS description is not valid: ");
 
   64     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
   65     exceptionTxt += std::string(pjError);
 
   66     throw te::srs::Exception(exceptionTxt);
 
   70   if ( description.empty())
 
   71       throw te::srs::Exception(
TE_TR(
"Target SRS ID not recognized."));
 
   76     std::string exceptionTxt = 
TE_TR(
"Target SRS description is not valid: ");
 
   77     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
   78     exceptionTxt += std::string(pjError);
 
   79     throw te::srs::Exception(exceptionTxt);
 
   89 #ifdef TERRALIB_PROJ4_ENABLED  
   90   if (m_sourcePj4Handler)
 
   91     pj_free(m_sourcePj4Handler);
 
   93   if (m_targetPj4Handler)
 
   94     pj_free(m_targetPj4Handler);
 
   96   m_sourcePj4Handler = 0;
 
   97   m_targetPj4Handler = 0;
 
  103 #ifdef TERRALIB_PROJ4_ENABLED  
  104   if (m_sourcePj4Handler)
 
  106     pj_free(m_sourcePj4Handler);
 
  107     m_sourcePj4Handler = 0;
 
  111   if ( description.empty())
 
  112       throw te::srs::Exception(
TE_TR(
"Source SRS ID not recognized."));
 
  114   m_sourcePj4Handler = pj_init_plus(description.c_str());
 
  115   if (!m_sourcePj4Handler)
 
  117     std::string exceptionTxt = 
TE_TR(
"Source SRS description is not valid: ");
 
  118     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
  119     exceptionTxt += std::string(pjError);
 
  120     throw te::srs::Exception(exceptionTxt);
 
  123   m_sourceSRID = sourceSRID;  
 
  128   assert(!pj4txt.empty());
 
  130 #ifdef TERRALIB_PROJ4_ENABLED  
  131   if (m_sourcePj4Handler)
 
  133     pj_free(m_sourcePj4Handler);
 
  134     m_sourcePj4Handler = 0;
 
  137   m_sourcePj4Handler = pj_init_plus(pj4txt.c_str());
 
  138   if (!m_sourcePj4Handler)
 
  140     std::string exceptionTxt = 
TE_TR(
"Source SRS PROJ4 description is not valid: ");
 
  141     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
  142     exceptionTxt += std::string(pjError);
 
  143     throw te::srs::Exception(exceptionTxt);
 
  158 #ifdef TERRALIB_PROJ4_ENABLED  
  159   if (m_targetPj4Handler)
 
  161     pj_free(m_targetPj4Handler);
 
  162     m_targetPj4Handler = 0;
 
  166   if ( description.empty())
 
  167       throw te::srs::Exception(
TE_TR(
"Target SRS ID not recognized."));
 
  169   m_targetPj4Handler = pj_init_plus(description.c_str());
 
  170   if (!m_targetPj4Handler)
 
  172     std::string exceptionTxt = 
TE_TR(
"Target SRS description is not valid: ");
 
  173     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
  174     exceptionTxt += std::string(pjError);
 
  175     throw te::srs::Exception(exceptionTxt);
 
  178   m_targetSRID = targetSRID;  
 
  183   assert(!pj4txt.empty());
 
  185 #ifdef TERRALIB_PROJ4_ENABLED  
  186   if (m_targetPj4Handler)
 
  188     pj_free(m_targetPj4Handler);
 
  189     m_targetPj4Handler = 0;
 
  192   m_targetPj4Handler = pj_init_plus(pj4txt.c_str());
 
  193   if (!m_targetPj4Handler)
 
  195     std::string exceptionTxt = 
TE_TR(
"Target SRS PROJ4 description is not valid: ");
 
  196     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
  197     exceptionTxt += std::string(pjError);
 
  198     throw te::srs::Exception(exceptionTxt);
 
  213 #ifdef TERRALIB_PROJ4_ENABLED  
  214   assert(m_sourcePj4Handler);
 
  215   assert(m_targetPj4Handler);
 
  217   memcpy(xOut, xIn, numCoord*
sizeof(
double));
 
  218   memcpy(yOut, yIn, numCoord*
sizeof(
double));
 
  220   if (pj_is_latlong(m_sourcePj4Handler))
 
  221     for (
long i=0; i<numCoord; xOut[i*coordOffset]*=DEG_TO_RAD, yOut[i*coordOffset]*=DEG_TO_RAD,  ++i);
 
  223   int res = pj_transform(m_sourcePj4Handler, m_targetPj4Handler,  numCoord, coordOffset, xOut, yOut, 0);
 
  225   if (res==0 && pj_is_latlong(m_targetPj4Handler))
 
  226     for (
long i=0; i<numCoord; xOut[i*coordOffset]*=RAD_TO_DEG,yOut[i*coordOffset]*=RAD_TO_DEG, ++i);
 
  230   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  237 #ifdef TERRALIB_PROJ4_ENABLED  
  238   assert(m_sourcePj4Handler);
 
  239   assert(m_targetPj4Handler);
 
  241   if (pj_is_latlong(m_sourcePj4Handler))
 
  242     for (
long i=0; i<numCoord; x[i*coordOffset]*=DEG_TO_RAD, y[i*coordOffset]*=DEG_TO_RAD,  ++i);
 
  244   int res = pj_transform(m_sourcePj4Handler, m_targetPj4Handler,  numCoord, coordOffset, x, y, 0);
 
  246   if (res==0 && pj_is_latlong(m_targetPj4Handler))
 
  247     for (
long i=0; i<numCoord; x[i*coordOffset]*=RAD_TO_DEG,y[i*coordOffset]*=RAD_TO_DEG, ++i);
 
  251   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  258 #ifdef TERRALIB_PROJ4_ENABLED  
  259   assert(m_sourcePj4Handler);
 
  260   assert(m_targetPj4Handler);
 
  265   if (pj_is_latlong(m_sourcePj4Handler))
 
  271   int res = pj_transform(m_sourcePj4Handler, m_targetPj4Handler,  1, 1, &xOut, &yOut, 0);
 
  273   if (pj_is_latlong(m_targetPj4Handler))
 
  280   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  287 #ifdef TERRALIB_PROJ4_ENABLED  
  288   assert(m_sourcePj4Handler);
 
  289   assert(m_targetPj4Handler);
 
  291   if (pj_is_latlong(m_sourcePj4Handler))
 
  297   int res = pj_transform(m_sourcePj4Handler, m_targetPj4Handler,  1, 1, &x, &y, 0);
 
  299   if (pj_is_latlong(m_targetPj4Handler))
 
  306   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  313 #ifdef TERRALIB_PROJ4_ENABLED  
  314   assert(m_sourcePj4Handler);
 
  315   assert(m_targetPj4Handler);
 
  317   memcpy(xOut, xIn, numCoord*
sizeof(
double));
 
  318   memcpy(yOut, yIn, numCoord*
sizeof(
double));
 
  320   if (pj_is_latlong(m_targetPj4Handler))
 
  321     for (
long i=0; i<numCoord; xOut[i*coordOffset]*=DEG_TO_RAD, yOut[i*coordOffset]*=DEG_TO_RAD, ++i);
 
  323   int res = pj_transform(m_targetPj4Handler, m_sourcePj4Handler,  numCoord, coordOffset, xOut, yOut, 0);
 
  325   if (res==0 && pj_is_latlong(m_sourcePj4Handler))
 
  326     for (
long i=0; i<numCoord; xOut[i*coordOffset]*=RAD_TO_DEG, yOut[i*coordOffset]*=RAD_TO_DEG, ++i);
 
  330   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  337 #ifdef TERRALIB_PROJ4_ENABLED  
  338   assert(m_sourcePj4Handler);
 
  339   assert(m_targetPj4Handler);
 
  341   if (pj_is_latlong(m_targetPj4Handler))
 
  342     for (
long i=0; i<numCoord; x[i*coordOffset]*=DEG_TO_RAD, y[i]*=DEG_TO_RAD, ++i);
 
  344   int res = pj_transform(m_targetPj4Handler, m_sourcePj4Handler,  numCoord, coordOffset, x, y, 0);
 
  346   if (res==0 && pj_is_latlong(m_sourcePj4Handler))
 
  347     for (
long i=0; i<numCoord; x[i*coordOffset]*=RAD_TO_DEG, y[i]*=RAD_TO_DEG, ++i);
 
  351   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  358 #ifdef TERRALIB_PROJ4_ENABLED  
  359   assert(m_sourcePj4Handler);
 
  360   assert(m_targetPj4Handler);
 
  365   if (pj_is_latlong(m_targetPj4Handler))
 
  371   int res = pj_transform(m_targetPj4Handler, m_sourcePj4Handler,  1, 1, &xOut, &yOut, 0);
 
  373   if (res==0 && pj_is_latlong(m_sourcePj4Handler))
 
  381   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  388 #ifdef TERRALIB_PROJ4_ENABLED  
  389   assert(m_sourcePj4Handler);
 
  390   assert(m_targetPj4Handler);
 
  392   if (pj_is_latlong(m_targetPj4Handler))
 
  398   int res = pj_transform(m_targetPj4Handler, m_sourcePj4Handler,  1, 1, &x, &y, 0);
 
  400   if (res==0 && pj_is_latlong(m_sourcePj4Handler))
 
  408   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinates conversion."));
 
  416 #ifdef TERRALIB_PROJ4_ENABLED  
  419   if (description.empty())
 
  422   projPJ pjhProj = pj_init_plus(description.c_str());
 
  425     std::string exceptionTxt = 
TE_TR(
"srs Source SRS description is not valid: ");
 
  426     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
  427     exceptionTxt += std::string(pjError);
 
  431   if (pj_is_latlong(pjhProj))
 
  437   projPJ pjhGeog = pj_latlong_from_proj(pjhProj);
 
  438   int res = pj_transform(pjhProj, pjhGeog, 1, 1, &x, &y, 0);
 
  450   throw te::srs::Exception(
TE_TR(
"PROJ4 library has to be enabled in order to support coordinate conversion."));
 
  456 #ifdef TERRALIB_PROJ4_ENABLED  
  458   if (description.empty())
 
  459     throw te::srs::Exception(
TE_TR(
"Source SRS ID not recognized."));
 
  461   projPJ pjhProj = pj_init_plus(description.c_str());
 
  464     std::string exceptionTxt = 
TE_TR(
"Source SRS description is not valid: ");
 
  465     char* pjError = pj_strerrno(*(pj_get_errno_ref()));
 
  466     exceptionTxt += std::string(pjError);
 
  469   projPJ pjhGeog = pj_latlong_from_proj(pjhProj);
 
  473   int res = pj_transform(pjhGeog, pjhProj, 1, 1, &lon, &lat, 0);
 
  480   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.