Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
wiki:documentation:devguide:srs_module [2016/01/20 10:12] lubia [SRS Representation] |
wiki:documentation:devguide:srs_module [2016/01/20 11:00] lubia [Coordinate Transformation] |
||
---|---|---|---|
Line 29: | Line 29: | ||
std::string myname = te::srs::SpatialReferenceSystemManager::getInstance().getName(4326); | std::string myname = te::srs::SpatialReferenceSystemManager::getInstance().getName(4326); | ||
std::cout << "EPSG:4326 => " << myname << std::endl; | std::cout << "EPSG:4326 => " << myname << std::endl; | ||
- | |||
} | } | ||
</code> | </code> | ||
- | |||
===== Coordinate Transformation ===== | ===== Coordinate Transformation ===== | ||
- | TerraLib uses the [[https://github.com/OSGeo/proj.4/wiki|PROJ.4]] library to implement coordinate transformations. The simplest way to do it is by creating an object of the class ''Converter'', that will be responsible by transforming coordinates from a source SRS Id to a target SRS ID, both represented by an unique integer identifier. The SRSID should exist in the SRSManager described above. | + | TerraLib uses the [[https://github.com/OSGeo/proj.4/wiki|PROJ.4]] library to implement coordinate transformations. The access and call to PROJ.4 is encapsulated in the class ''Converter'', that will be responsible by transforming coordinates from a source SRS Id to a target SRS ID, both represented by an unique integer identifier or SRID. The SRID should exist in the SRSManager described above. |
The code snippet below shows how an application can request a ''Converter'' to convert some coordinates. | The code snippet below shows how an application can request a ''Converter'' to convert some coordinates. | ||
Line 41: | Line 39: | ||
{ | { | ||
// ... | // ... | ||
- | // requesting a pointer to a converter | + | te::srs::Converter converter; |
- | std::auto_ptr<te::srs::Converter> converter(new te::srs::Converter()); | + | |
- | converter->setSourceSRS(4326); // the SRS id for geographic coordinates over a WGS84 datum | + | converter.setSourceSRID(4326); // the SRS id for geographic coordinates over a WGS84 datum |
- | converter->setTargetSRS(31985); // the SRS id for projected coordinates of UTM / WGS84 datum, Zone 17 South | + | converter.setTargetSRID(32723); // the SRS id for projected coordinates of UTM / WGS84 datum, Zone 23 South |
// Converting a single coordinate | // Converting a single coordinate | ||
- | double llX = -45.5; | + | double llX = -45.0; |
- | double llY = -23.0; | + | double llY = 0.0; |
double xyX; | double xyX; | ||
double xyY; | double xyY; | ||
- | converter->convert(llX,llY,xyX,xyY); | + | converter.convert(llX,llY,xyX,xyY); |
- | converter->invert(xyX,xyY,llX,llY); | + | |
- | + | ||
- | // Converting a list of coordinates | + | |
- | double* xs = new double[3]; | + | |
- | double* ys = new double[3]; | + | |
- | xs[0] = -45.5; | + | std::cout.precision(10); |
- | xs[1] = -45.6; | + | std::cout << "EPSG:4326 (" << llX << "," << llY << ") => "; |
- | xs[2] = -45.7; | + | std::cout << "EPSG:32723 (" << xyX << "," << xyY << ")\n"; |
- | ys[0] = -23.0; | + | llX = -44.0; |
- | ys[1] = -23.1; | + | llY = 0.0; |
- | ys[2] = -23.2; | + | converter.convert(llX,llY,xyX,xyY); |
- | converter->convert(xs,ys,3,1); | + | std::cout.precision(10); |
+ | std::cout << "EPSG:4326 (" << llX << "," << llY << ") => "; | ||
+ | std::cout << "EPSG:32723 (" << xyX << "," << xyY << ")\n"; | ||
// ... | // ... | ||
} | } |