27 #include "../common/PlatformUtils.h" 
   28 #include "../common/Translator.h" 
   29 #include "../common/UnitsOfMeasureManager.h" 
   39 #include <boost/foreach.hpp> 
   40 #include <boost/property_tree/ptree.hpp> 
   41 #include <boost/property_tree/json_parser.hpp> 
   47   f.open(fileName.c_str());
 
   52   boost::property_tree::ptree pt;
 
   53   boost::property_tree::json_parser::read_json(f,pt);
 
   54   BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child(
"SRSs"))
 
   56     if (v.second.get<
unsigned int>(
"srid") > 100000)
 
   57       mger->
add(v.second.get<std::string>(
"name"), v.second.get<std::string>(
"pj4txt"),
 
   58           v.second.get<std::string>(
"wkt"), v.second.get<
unsigned int>(
"srid"), 
"USER");
 
   60       mger->
add(v.second.get<std::string>(
"name"), v.second.get<std::string>(
"pj4txt"),
 
   61           v.second.get<std::string>(
"wkt"), v.second.get<
unsigned int>(
"srid"));
 
   71   m_auth_name(auth_name),
 
   79   std::string ssrid = m_auth_name;
 
   81   ssrid += boost::lexical_cast<std::string>(m_auth_id);
 
   97     throw Exception(
TE_TR(
"The spatial reference system manager is already initialized!"));
 
  105     throw Exception(
TE_TR(
"Could not find srs.json!"));
 
  117   catch(boost::property_tree::json_parser::json_parser_error &je)
 
  119     std::string errmsg = 
"Error parsing: " + je.filename() + 
": " + je.message();
 
  120     te::srs::Exception ex(
TE_TR(errmsg));
 
  123   catch (std::exception 
const& e)
 
  125     std::cerr << e.what() << std::endl;
 
  132   std::string key = authName;
 
  134   key += boost::lexical_cast<std::string>(id);
 
  136   boost::multi_index::nth_index<srs_set,0>::type::iterator it = boost::multi_index::get<0>(
m_set).find(key);
 
  137   if (it != boost::multi_index::get<0>(
m_set).end())
 
  138     throw te::srs::Exception(
TE_TR(
"The CS identification already exists in the manager.")); 
 
  140   srs_desc record(name, 
id, authName, p4Txt, wkt);
 
  141   m_set.insert(record);
 
  146   std::string key = authName;
 
  148   key += boost::lexical_cast<std::string>(id);
 
  150   boost::multi_index::nth_index<srs_set,0>::type::iterator it = boost::multi_index::get<0>(
m_set).find(key);
 
  151   if (it == boost::multi_index::get<0>(
m_set).end())
 
  155     key += boost::lexical_cast<std::string>(id);
 
  156     it = boost::multi_index::get<0>(
m_set).find(key);
 
  157     return (it != boost::multi_index::get<0>(
m_set).end());
 
  165   std::string wkt = 
getWkt(
id,authName);
 
  167     return std::auto_ptr<te::srs::SpatialReferenceSystem>();
 
  175     throw te::srs::Exception(
TE_TR(
"Error parsing the registered CS WKT."));
 
  177   return std::auto_ptr<te::srs::SpatialReferenceSystem>();
 
  183   std::string key = authName;
 
  185   key += boost::lexical_cast<std::string>(id);
 
  187   boost::multi_index::nth_index<srs_set,0>::type::iterator it = boost::multi_index::get<0>(
m_set).find(key);
 
  188   if (it == boost::multi_index::get<0>(
m_set).end())
 
  192     key += boost::lexical_cast<std::string>(id);
 
  193     it = boost::multi_index::get<0>(
m_set).find(key);
 
  194     if (it!=boost::multi_index::get<0>(
m_set).end())
 
  205   std::string key = authName;
 
  207   key += boost::lexical_cast<std::string>(id);
 
  209   boost::multi_index::nth_index<srs_set,0>::type::iterator it = boost::multi_index::get<0>(
m_set).find(key);
 
  210   if (it==boost::multi_index::get<0>(
m_set).end())
 
  214     key += boost::lexical_cast<std::string>(id);
 
  215     it = boost::multi_index::get<0>(
m_set).find(key);
 
  216     if (it!=boost::multi_index::get<0>(
m_set).end())
 
  227   std::string key = authName;
 
  229   key += boost::lexical_cast<std::string>(id);
 
  231   boost::multi_index::nth_index<srs_set,0>::type::iterator it = boost::multi_index::get<0>(
m_set).find(key);
 
  232   if (it==boost::multi_index::get<0>(
m_set).end())
 
  236     key += boost::lexical_cast<std::string>(id);
 
  237     it = boost::multi_index::get<0>(
m_set).find(key);
 
  238     if (it!=boost::multi_index::get<0>(
m_set).end())
 
  249   boost::multi_index::nth_index<srs_set,1>::type::iterator it = boost::multi_index::get<1>(
m_set).find(name);
 
  250   if (it==boost::multi_index::get<1>(
m_set).end()) 
 
  251     throw te::srs::Exception(
TE_TR(
"CS name not recognized."));
 
  253   return std::pair<std::string,unsigned int>(it->m_auth_name, it->m_auth_id);
 
  259   boost::multi_index::nth_index<srs_set,2>::type::iterator it = boost::multi_index::get<2>(
m_set).find(p4Txt);
 
  260   if (it==boost::multi_index::get<2>(
m_set).end()) 
 
  261     throw te::srs::Exception(
TE_TR(
"CS name not recognized."));
 
  263   return std::pair<std::string,unsigned int>(it->m_auth_name, it->m_auth_id);
 
  268   boost::multi_index::nth_index<srs_set,3>::type::iterator it = boost::multi_index::get<3>(
m_set).find(wkt);
 
  269   if (it==boost::multi_index::get<3>(
m_set).end()) 
 
  270     throw te::srs::Exception(
TE_TR(
"CS name not recognized."));
 
  272   return std::pair<std::string,unsigned int>(it->m_auth_name, it->m_auth_id);
 
  277   std::string key = authName;
 
  279   key += boost::lexical_cast<std::string>(id);
 
  281   boost::multi_index::nth_index<srs_set,0>::type::iterator it = boost::multi_index::get<0>(
m_set).find(key);
 
  282   if (it==boost::multi_index::get<0>(
m_set).end())
 
  286     key += boost::lexical_cast<std::string>(id);
 
  287     it = boost::multi_index::get<0>(
m_set).find(key);
 
  288     if (it!=boost::multi_index::get<0>(
m_set).end())
 
  300 std::pair<te::srs::SpatialReferenceSystemManager::iterator,te::srs::SpatialReferenceSystemManager::iterator> 
 
  304                    te::srs::SpatialReferenceSystemManager::iterator>(boost::multi_index::get<0>(
m_set).begin(), boost::multi_index::get<0>(
m_set).end());
 
  314   std::string unitName= 
"metre";
 
  318   std::string pjstr = 
getP4Txt(
id,authName);
 
  322   std::size_t found = pjstr.find(
"+units=");
 
  323   if (found!=std::string::npos)
 
  325     std::size_t aux = pjstr.find(
" ", found);
 
  326     std::string unitsymbol = pjstr.substr(found+7,aux-(found+7));
 
  336   std::string pjstr = 
getP4Txt(
id,authName);
 
  337   return (pjstr.find(
"+proj=longlat")!=std::string::npos); 
 
std::pair< std::string, unsigned int > getIdFromWkt(const std::string &wkt) const 
Returns a coordinate system identification given a WKT description. 
 
TECOMMONEXPORT std::string FindInTerraLibPath(const std::string &p)
Returns the path relative to a directory or file in the context of TerraLib. 
 
A class to manage Coordinate Systems representations. 
 
SpatialReferenceSystemManager()
Constructor. 
 
std::pair< te::srs::SpatialReferenceSystemManager::iterator, te::srs::SpatialReferenceSystemManager::iterator > getIterators() const 
Returns an iterator mechanism over the coordinate system descriptions in the manager. 
 
size_t size() const 
Returns the number of objects in the manager. 
 
UnitOfMeasurePtr findBySymbol(const std::string &symbol) const 
Returns a unit of measure identified by its symbol. 
 
void add(const std::string &name, const std::string &p4Txt, const std::string &wkt, unsigned int id, const std::string &authName="EPSG")
Adds a  to the manager. 
 
void clear()
Removes all coordinate system representations from the manager. 
 
bool isGeographic(unsigned int id, const std::string &authName)
Checks if a SRS with a given id refers to a geographic spatial reference system. 
 
boost::multi_index::nth_index< srs_set, 0 >::type::iterator iterator
An iterator by 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. 
 
static SpatialReferenceSystem * read(const char *wkt)
It returns a valid SRS from a given WKT. 
 
static UnitsOfMeasureManager & getInstance()
It returns a reference to the singleton instance. 
 
std::pair< std::string, unsigned int > getIdFromName(const std::string &name) const 
Returns a coordinate system identification given a name. 
 
te::common::UnitOfMeasurePtr getUnit(unsigned int id, const std::string &authName="EPSG")
Returns the unit of measure for a SRS with a given id. 
 
srs_desc(const std::string &name, unsigned int auth_id, const std::string &auth_name, const std::string &p4txt, const std::string &wkt)
 
A class to manage Coordinate Systems representations within TerraLib environment. ...
 
void remove(unsigned int id, const std::string &authName="EPSG")
Removes a coordinate system representation from the manager, given its identification. 
 
bool recognizes(unsigned int id, const std::string &authName="EPSG") const 
Returns true is a pair  is recognized by the manager. 
 
~SpatialReferenceSystemManager()
Destructor. 
 
void init()
Inializes the manager from a JSON file containing instances of SRSs. 
 
std::string getName(unsigned int id, const std::string &authName="EPSG") const 
Returns a coordinate system name given an identification. 
 
boost::shared_ptr< UnitOfMeasure > UnitOfMeasurePtr
 
std::string getWkt(unsigned int id, const std::string &authName="EPSG") const 
Returns a coordinate system WKT description given an id. 
 
void LoadSpatialReferenceSystemManager(const std::string fileName, te::srs::SpatialReferenceSystemManager *mger)
 
UnitOfMeasurePtr find(unsigned int id) const 
Returns a unit of measure identified by its identificaton. 
 
SpatialReferenceSystemPtr getSpatialReferenceSystem(unsigned int id, const std::string &authName="EPSG") const 
Returns a pointer to a coordinate system given an identification. 
 
std::pair< std::string, unsigned int > getIdFromP4Txt(const std::string &p4Txt) const 
Returns a coordinate system identification given a PROJ4 description.