31 #ifndef DRAIN_PROJ6_H_
32 #define DRAIN_PROJ6_H_
42 #include "Dictionary.h"
84 Projector(
const std::string & projDef =
"", CRS_mode crs=ACCEPT_CRS) : pjContext(proj_context_create()), pj(nullptr), epsg(0){
87 projDefs = {{ORIG,
""}, {MODIFIED,
""}, {PROJ4,
""}, {PROJ5,
""}, {SIMPLE,
""}};
95 Projector(PJ_CONTEXT *pjContext,
const std::string & projDef =
"", CRS_mode crs=ACCEPT_CRS) : pjContext(pjContext), pj(nullptr), epsg(0){
97 projDefs = {{ORIG,
""}, {MODIFIED,
""}, {PROJ4,
""}, {PROJ5,
""}, {SIMPLE,
""}};
105 Projector(
const Projector & pr) :
106 pjContext(proj_context_clone(pr.pjContext)),
110 pj(proj_clone(pjContext, pr.pj)),
122 proj_context_destroy(pjContext);
126 void getProjDefDict(
const std::string & str, ProjDef & dict);
130 int extractEPSG(
const ProjDef & projDefDict);
133 void getProjDefStr(
const ProjDef & dict, std::stringstream & sstr,
const std::set<std::string> & excludeKeys = {
"+type"});
143 projDefs = {{ORIG,
""}, {MODIFIED,
""}, {PROJ4,
""}, {PROJ5,
""}, {SIMPLE,
""}};
155 void setProjection(
const std::string &str, CRS_mode crs=FORCE_CRS);
164 void updateProjectionDefs(CRS_mode crs);
169 return (pj !=
nullptr);
174 bool isLongLat()
const {
176 return isLongLat(pj);
180 int getEPSG()
const {
192 void info(std::ostream & ostr = std::cout,
int wkt = -1){
194 for (
const auto & entry: projDefs){
195 ostr << entry.first <<
": '" << entry.second <<
"'\n";
201 std::string getErrorString()
const {
202 int err = proj_context_errno(pjContext);
203 return proj_errno_string(err);
210 void info(PJ *pj, std::ostream & ostr = std::cout,
int wkt = -1);
218 std::map<PROJDEF_variant,std::string> projDefs;
229 bool isLongLat(
const PJ *prj);
231 PJ_CONTEXT *pjContext;
268 const std::string & getProjVersion();
279 void setProjectionSrc(
const std::string & projDef, Projector::CRS_mode crs=Projector::FORCE_CRS){
286 void setProjectionDst(
const std::string & projDef, Projector::CRS_mode crs=Projector::FORCE_CRS){
293 void setProjections(
const std::string & projDefSrc,
const std::string & projDefDst){
311 return src.getProjDef();
316 const std::string & getProjectionDst()
const {
317 return dst.getProjDef();
322 const Projector & getSrc()
const {
327 const Projector & getDst()
const {
338 <PJ_DIRECTION D,
class POINT_XY>
343 proj_trans_generic(proj, D, &point.x,
sizeof(POINT_XY), 1, &point.y,
sizeof(POINT_XY), 1, 0, 0, 0, 0, 0, 0);
349 void project(
double & x,
double & y)
const {
351 proj_trans_generic(proj, D, &x,
sizeof(
double), 1, &y,
sizeof(
double), 1, 0, 0, 0, 0, 0, 0);
360 project<PJ_FWD>(x,y);
365 void projectFwd(
double x,
double y,
double & x2,
double & y2)
const {
368 project<PJ_FWD>(x2,y2);
374 project<PJ_FWD>(point);
379 void projectInv(
double & x,
double & y)
const {
380 project<PJ_INV>(x,y);
385 void projectInv(
double x,
double y,
double & x2,
double & y2)
const {
388 project<PJ_INV>(x2,y2);
394 project<PJ_INV>(point);
467 void debug(std::ostream & ostr = std::cout,
int wkt = -1){
483 return dst.isLongLat();
492 std::string getErrorString()
const {
494 return proj_errno_string(err);
521 void setMapping(
bool lenient);
529 DRAIN_TYPENAME(
Proj6);
531 std::ostream & operator<<(std::ostream & ostr,
const Proj6 &p);
void setProjectionDst(const std::string &projDef, Projector::CRS_mode crs=Projector::FORCE_CRS)
Sets destination projection.
Definition: Proj6.h:286
void setProjectionSrc(const std::string &projDef, Projector::CRS_mode crs=Projector::FORCE_CRS)
Sets source projection.
Definition: Proj6.h:279
PJ_CONTEXT * pjContext
Detect EPSG code from "+init=epsg:EPSG" argument.
Definition: Proj6.h:517
bool isLongLat() const
Check if destination projection is longitude-latitude degrees.
Definition: Proj6.h:482
void setProjections(const std::string &projDefSrc, const std::string &projDefDst)
Sets source and destination projection.
Definition: Proj6.h:293
void projectFwd(double x, double y, double &x2, double &y2) const
Forward projection.
Definition: Proj6.h:365
void project(POINT_XY &point) const
Definition: Proj6.h:340
void debug(std::ostream &ostr=std::cout, int wkt=-1)
Forward projection.
Definition: Proj6.h:467
void projectFwd(double &x, double &y) const
Forward projection (in-place)
Definition: Proj6.h:359
void projectFwd(drain::Point2D< double > &point) const
Forward projection. Example implementation of project<>() .
Definition: Proj6.h:373
const std::string & getProjectionSrc() const
Returns the projection std::string applied by the last setProjection call.
Definition: Proj6.h:310
void info(std::ostream &ostr=std::cout, int wkt=-1)
Prunes "+init=epsg:<...>" and optionally "+type=crs" codes.
Definition: Proj6.h:192
bool isSet() const
Returns true, if PJ object has been set.
Definition: Proj6.h:168
PROJDEF_variant
Each projector has three (3) versions of project definition.
Definition: Proj6.h:73
void setProjection(const std::string &str, CRS_mode crs=FORCE_CRS)
Sets projection defined as Proj string.
Definition: Proj6.cpp:70
void clear()
Deletes projection object and clears all the metadata.
Definition: Proj6.h:142
Definition: DataSelector.cpp:1277
Definition: Sprinter.h:137