52 const Boundary& orig,
const Boundary& conv,
double scale,
double rot,
bool inverse,
bool flatten):
55 myProjection(nullptr),
56 myInverseProjection(nullptr),
57 myGeoProjection(nullptr),
63 myProjectionMethod(NONE),
64 myUseInverseProjection(inverse),
67 myConvBoundary(conv) {
70 }
else if (proj ==
"-") {
72 }
else if (proj ==
"UTM") {
74 }
else if (proj ==
"DHDN") {
76 }
else if (proj ==
"DHDN_UTM") {
81 #ifdef PROJ_VERSION_MAJOR 82 myProjection = proj_create(PJ_DEFAULT_CTX, proj.c_str());
84 myProjection = pj_init_plus(proj.c_str());
86 if (myProjection ==
nullptr) {
97 if (myProjection !=
nullptr) {
98 #ifdef PROJ_VERSION_MAJOR 99 proj_destroy(myProjection);
101 pj_free(myProjection);
104 if (myInverseProjection !=
nullptr) {
105 #ifdef PROJ_VERSION_MAJOR 106 proj_destroy(myInverseProjection);
108 pj_free(myInverseProjection);
111 if (myGeoProjection !=
nullptr) {
112 #ifdef PROJ_VERSION_MAJOR 113 proj_destroy(myGeoProjection);
115 pj_free(myGeoProjection);
150 if (myProjection !=
nullptr) {
151 #ifdef PROJ_VERSION_MAJOR 152 proj_destroy(myProjection);
154 pj_free(myProjection);
156 myProjection =
nullptr;
158 if (myInverseProjection !=
nullptr) {
159 #ifdef PROJ_VERSION_MAJOR 160 proj_destroy(myInverseProjection);
162 pj_free(myInverseProjection);
164 myInverseProjection =
nullptr;
166 if (myGeoProjection !=
nullptr) {
167 #ifdef PROJ_VERSION_MAJOR 168 proj_destroy(myGeoProjection);
170 pj_free(myGeoProjection);
172 myGeoProjection =
nullptr;
174 if (orig.myProjection !=
nullptr) {
175 #ifdef PROJ_VERSION_MAJOR 176 myProjection = proj_create(PJ_DEFAULT_CTX, orig.
myProjString.c_str());
181 if (orig.myInverseProjection !=
nullptr) {
182 #ifdef PROJ_VERSION_MAJOR 183 myInverseProjection = orig.myInverseProjection;
185 myInverseProjection = pj_init_plus(pj_get_def(orig.myInverseProjection, 0));
188 if (orig.myGeoProjection !=
nullptr) {
189 #ifdef PROJ_VERSION_MAJOR 190 myGeoProjection = orig.myGeoProjection;
192 myGeoProjection = pj_init_plus(pj_get_def(orig.myGeoProjection, 0));
202 std::string proj =
"!";
203 double scale = oc.
getFloat(
"proj.scale");
204 double rot = oc.
getFloat(
"proj.rotate");
206 bool inverse = oc.
exists(
"proj.inverse") && oc.
getBool(
"proj.inverse");
207 bool flatten = oc.
exists(
"flatten") && oc.
getBool(
"flatten");
209 if (oc.
getBool(
"simple-projection")) {
215 WRITE_ERROR(
"Inverse projection works only with explicit proj parameters.");
219 if (numProjections > 1) {
220 WRITE_ERROR(
"The projection method needs to be uniquely defined.");
226 }
else if (oc.
getBool(
"proj.dhdn")) {
228 }
else if (oc.
getBool(
"proj.dhdnutm")) {
242 const Boundary& conv,
double scale) {
253 oc.
addSynonyme(
"simple-projection",
"proj.simple",
true);
254 oc.
addDescription(
"simple-projection",
"Projection",
"Uses a simple method for projection");
257 oc.
addDescription(
"proj.scale",
"Projection",
"Scaling factor for input coordinates");
260 oc.
addDescription(
"proj.rotate",
"Projection",
"Rotation (clockwise degrees) for input coordinates");
264 oc.
addDescription(
"proj.utm",
"Projection",
"Determine the UTM zone (for a universal transversal mercator projection based on the WGS84 ellipsoid)");
267 oc.
addDescription(
"proj.dhdn",
"Projection",
"Determine the DHDN zone (for a transversal mercator projection based on the bessel ellipsoid, \"Gauss-Krueger\")");
270 oc.
addDescription(
"proj",
"Projection",
"Uses STR as proj.4 definition for projection");
273 oc.
addDescription(
"proj.inverse",
"Projection",
"Inverses projection");
276 oc.
addDescription(
"proj.dhdnutm",
"Projection",
"Convert from Gauss-Krueger to UTM");
277 #endif // PROJ_API_FILE 300 const double y = cartesian.
y() / 111136.;
301 const double x = cartesian.
x() / 111320. / cos(
DEG2RAD(y));
306 #ifdef PROJ_VERSION_MAJOR 308 c.xy.x = cartesian.
x();
309 c.xy.y = cartesian.
y();
310 c = proj_trans(myProjection, PJ_INV, c);
311 cartesian.
set(proj_todeg(c.lp.lam), proj_todeg(c.lp.phi));
316 p = pj_inv(p, myProjection);
320 cartesian.
set((
double) p.u, (
double) p.v);
328 if (includeInBoundary) {
333 if (myProjection ==
nullptr) {
337 int zone = (int)((x - 500000.) / 1000000.);
338 if (zone < 1 || zone > 5) {
343 " +k=1 +x_0=" +
toString(zone * 1000000 + 500000) +
344 " +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
345 #ifdef PROJ_VERSION_MAJOR 346 myInverseProjection = proj_create(PJ_DEFAULT_CTX,
myProjString.c_str());
347 myGeoProjection = proj_create(PJ_DEFAULT_CTX,
"+proj=latlong +datum=WGS84");
349 myInverseProjection = pj_init_plus(
myProjString.c_str());
350 myGeoProjection = pj_init_plus(
"+proj=latlong +datum=WGS84");
352 x = ((x - 500000.) / 1000000.) * 3;
357 int zone = (int)(x + 180) / 6 + 1;
359 " +ellps=WGS84 +datum=WGS84 +units=m +no_defs";
360 #ifdef PROJ_VERSION_MAJOR 361 myProjection = proj_create(PJ_DEFAULT_CTX,
myProjString.c_str());
369 int zone = (int)(x / 3);
370 if (zone < 1 || zone > 5) {
375 " +k=1 +x_0=" +
toString(zone * 1000000 + 500000) +
376 " +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
377 #ifdef PROJ_VERSION_MAJOR 378 myProjection = proj_create(PJ_DEFAULT_CTX,
myProjString.c_str());
389 if (myInverseProjection !=
nullptr) {
390 #ifdef PROJ_VERSION_MAJOR 394 c = proj_trans(myInverseProjection, PJ_INV, c);
395 from.
set(proj_todeg(c.lp.lam), proj_todeg(c.lp.phi));
399 if (pj_transform(myInverseProjection, myGeoProjection, 1, 1, &x, &y,
nullptr)) {
402 from.
set(
double(x * RAD_TO_DEG),
double(y * RAD_TO_DEG));
409 if (includeInBoundary) {
422 double y = x2 * mySin + y2 *
myCos;
428 if (x > 180.1 || x < -180.1) {
432 if (y > 90.1 || y < -90.1) {
437 if (myProjection !=
nullptr) {
438 #ifdef PROJ_VERSION_MAJOR 440 c.lp.lam = proj_torad(x);
441 c.lp.phi = proj_torad(y);
442 c = proj_trans(myProjection, PJ_FWD, c);
448 p.u = x * DEG_TO_RAD;
449 p.v = y * DEG_TO_RAD;
450 p = pj_fwd(p, myProjection);
458 x *= 111320. * cos(
DEG2RAD(y));
463 if (x > std::numeric_limits<double>::max() ||
464 y > std::numeric_limits<double>::max()) {
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
static void writeLocation(OutputDevice &into)
writes the location element
static GeoConvHelper myProcessing
coordinate transformation to use for input conversion and processing
~GeoConvHelper()
Destructor.
const Boundary & getConvBoundary() const
Returns the converted boundary.
void add(const Position &pos)
Adds the given position to this one.
Position myOffset
The offset to apply.
static void computeFinal(bool lefthand=false)
compute the location attributes which will be used for output based on the loaded location data...
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
double y() const
Returns the y-position.
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
void moveby(double x, double y, double z=0)
Moves the boundary by the given amount.
double mySin
The rotation to apply to geo-coordinates.
Boundary myOrigBoundary
The boundary before conversion (x2cartesian)
static void setLoaded(const GeoConvHelper &loaded)
sets the coordinate transformation loaded from a location element
double x() const
Returns the x-position.
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
const Boundary & getOrigBoundary() const
Returns the original boundary.
bool myFlatten
whether to discard z-data
static GeoConvHelper myLoaded
coordinate transformation loaded from a location element
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string & getProjString() const
Returns the original projection definition.
static void resetLoaded()
resets loaded location elements
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
void set(double x, double y)
set positions x and y
bool myUseInverseProjection
Information whether inverse projection shall be used.
void moveConvertedBy(double x, double y)
Shifts the converted boundary by the given amounts.
A class that stores a 2D geometrical boundary.
#define WRITE_WARNING(msg)
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
double myGeoScale
The scaling to apply to geo-coordinates.
static methods for processing the coordinates conversion for the current net
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static GeoConvHelper myFinal
coordinate transformation to use for writing the location element and for tracking the original coord...
A point in 2D or 3D with translation and scaling methods.
ProjectionMethod myProjectionMethod
Information whether no projection shall be done.
std::string myProjString
A proj options string describing the proj.4-projection to use.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool exists(const std::string &name) const
Returns the information whether the named option is known.
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
GeoConvHelper(OptionsCont &oc)
Constructor based on the stored options.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
Boundary myConvBoundary
The boundary after conversion (x2cartesian)
static int myNumLoaded
the numer of coordinate transformations loaded from location elements
bool operator==(const GeoConvHelper &o) const
void flipY()
flips ymin and ymax
A storage for options typed value containers)
bool usingInverseGeoProjection() const
Returns the information whether an inverse transformation will happen.
const Position getOffsetBase() const
Returns the network base.
Static storage of an output device and its base (abstract) implementation.
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation. ...
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void mul(double val)
Multiplies both positions with the given value.
const Position getOffset() const
Returns the network offset.
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void lf()
writes a line feed if applicable
GeoConvHelper & operator=(const GeoConvHelper &)
make assignment operator private
void setz(double z)
set position z
void sub(double dx, double dy)
Substracts the given position from this one.