 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
51 const Boundary& orig,
const Boundary& conv,
double scale,
double rot,
bool inverse,
bool flatten):
54 myProjection(nullptr),
55 myInverseProjection(nullptr),
56 myGeoProjection(nullptr),
62 myProjectionMethod(NONE),
63 myUseInverseProjection(inverse),
66 myConvBoundary(conv) {
69 }
else if (proj ==
"-") {
71 }
else if (proj ==
"UTM") {
73 }
else if (proj ==
"DHDN") {
75 }
else if (proj ==
"DHDN_UTM") {
80 #ifdef PROJ_VERSION_MAJOR
81 myProjection = proj_create(PJ_DEFAULT_CTX, proj.c_str());
83 myProjection = pj_init_plus(proj.c_str());
85 if (myProjection ==
nullptr) {
96 if (myProjection !=
nullptr) {
97 #ifdef PROJ_VERSION_MAJOR
98 proj_destroy(myProjection);
100 pj_free(myProjection);
103 if (myInverseProjection !=
nullptr) {
104 #ifdef PROJ_VERSION_MAJOR
105 proj_destroy(myInverseProjection);
107 pj_free(myInverseProjection);
110 if (myGeoProjection !=
nullptr) {
111 #ifdef PROJ_VERSION_MAJOR
112 proj_destroy(myGeoProjection);
114 pj_free(myGeoProjection);
149 if (myProjection !=
nullptr) {
150 #ifdef PROJ_VERSION_MAJOR
151 proj_destroy(myProjection);
153 pj_free(myProjection);
155 myProjection =
nullptr;
157 if (myInverseProjection !=
nullptr) {
158 #ifdef PROJ_VERSION_MAJOR
159 proj_destroy(myInverseProjection);
161 pj_free(myInverseProjection);
163 myInverseProjection =
nullptr;
165 if (myGeoProjection !=
nullptr) {
166 #ifdef PROJ_VERSION_MAJOR
167 proj_destroy(myGeoProjection);
169 pj_free(myGeoProjection);
171 myGeoProjection =
nullptr;
173 if (orig.myProjection !=
nullptr) {
174 #ifdef PROJ_VERSION_MAJOR
175 myProjection = proj_create(PJ_DEFAULT_CTX, orig.
myProjString.c_str());
180 if (orig.myInverseProjection !=
nullptr) {
181 #ifdef PROJ_VERSION_MAJOR
182 myInverseProjection = orig.myInverseProjection;
184 myInverseProjection = pj_init_plus(pj_get_def(orig.myInverseProjection, 0));
187 if (orig.myGeoProjection !=
nullptr) {
188 #ifdef PROJ_VERSION_MAJOR
189 myGeoProjection = orig.myGeoProjection;
191 myGeoProjection = pj_init_plus(pj_get_def(orig.myGeoProjection, 0));
201 std::string proj =
"!";
202 double scale = oc.
getFloat(
"proj.scale");
203 double rot = oc.
getFloat(
"proj.rotate");
205 bool inverse = oc.
exists(
"proj.inverse") && oc.
getBool(
"proj.inverse");
206 bool flatten = oc.
exists(
"flatten") && oc.
getBool(
"flatten");
208 if (oc.
getBool(
"simple-projection")) {
214 WRITE_ERROR(
"Inverse projection works only with explicit proj parameters.");
218 if (numProjections > 1) {
219 WRITE_ERROR(
"The projection method needs to be uniquely defined.");
225 }
else if (oc.
getBool(
"proj.dhdn")) {
227 }
else if (oc.
getBool(
"proj.dhdnutm")) {
241 const Boundary& conv,
double scale) {
252 oc.
addSynonyme(
"simple-projection",
"proj.simple",
true);
253 oc.
addDescription(
"simple-projection",
"Projection",
"Uses a simple method for projection");
256 oc.
addDescription(
"proj.scale",
"Projection",
"Scaling factor for input coordinates");
259 oc.
addDescription(
"proj.rotate",
"Projection",
"Rotation (clockwise degrees) for input coordinates");
263 oc.
addDescription(
"proj.utm",
"Projection",
"Determine the UTM zone (for a universal transversal mercator projection based on the WGS84 ellipsoid)");
266 oc.
addDescription(
"proj.dhdn",
"Projection",
"Determine the DHDN zone (for a transversal mercator projection based on the bessel ellipsoid, \"Gauss-Krueger\")");
269 oc.
addDescription(
"proj",
"Projection",
"Uses STR as proj.4 definition for projection");
272 oc.
addDescription(
"proj.inverse",
"Projection",
"Inverses projection");
275 oc.
addDescription(
"proj.dhdnutm",
"Projection",
"Convert from Gauss-Krueger to UTM");
276 #endif // PROJ_API_FILE
299 const double y = cartesian.
y() / 111136.;
300 const double x = cartesian.
x() / 111320. / cos(
DEG2RAD(y));
305 #ifdef PROJ_VERSION_MAJOR
307 c.xy.x = cartesian.
x();
308 c.xy.y = cartesian.
y();
309 c = proj_trans(myProjection, PJ_INV, c);
310 cartesian.
set(proj_todeg(c.lp.lam), proj_todeg(c.lp.phi));
315 p = pj_inv(p, myProjection);
319 cartesian.
set((
double) p.u, (
double) p.v);
327 if (includeInBoundary) {
332 if (myProjection ==
nullptr) {
336 int zone = (int)((x - 500000.) / 1000000.);
337 if (zone < 1 || zone > 5) {
342 " +k=1 +x_0=" +
toString(zone * 1000000 + 500000) +
343 " +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
344 #ifdef PROJ_VERSION_MAJOR
345 myInverseProjection = proj_create(PJ_DEFAULT_CTX,
myProjString.c_str());
346 myGeoProjection = proj_create(PJ_DEFAULT_CTX,
"+proj=latlong +datum=WGS84");
348 myInverseProjection = pj_init_plus(
myProjString.c_str());
349 myGeoProjection = pj_init_plus(
"+proj=latlong +datum=WGS84");
351 x = ((x - 500000.) / 1000000.) * 3;
356 int zone = (int)(x + 180) / 6 + 1;
358 " +ellps=WGS84 +datum=WGS84 +units=m +no_defs";
359 #ifdef PROJ_VERSION_MAJOR
360 myProjection = proj_create(PJ_DEFAULT_CTX,
myProjString.c_str());
368 int zone = (int)(x / 3);
369 if (zone < 1 || zone > 5) {
374 " +k=1 +x_0=" +
toString(zone * 1000000 + 500000) +
375 " +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
376 #ifdef PROJ_VERSION_MAJOR
377 myProjection = proj_create(PJ_DEFAULT_CTX,
myProjString.c_str());
388 if (myInverseProjection !=
nullptr) {
389 #ifdef PROJ_VERSION_MAJOR
393 c = proj_trans(myInverseProjection, PJ_INV, c);
394 from.
set(proj_todeg(c.lp.lam), proj_todeg(c.lp.phi));
398 if (pj_transform(myInverseProjection, myGeoProjection, 1, 1, &x, &y,
nullptr)) {
401 from.
set(
double(x * RAD_TO_DEG),
double(y * RAD_TO_DEG));
408 if (includeInBoundary) {
427 if (x > 180.1 || x < -180.1) {
431 if (y > 90.1 || y < -90.1) {
436 if (myProjection !=
nullptr) {
437 #ifdef PROJ_VERSION_MAJOR
439 c.lp.lam = proj_torad(x);
440 c.lp.phi = proj_torad(y);
441 c = proj_trans(myProjection, PJ_FWD, c);
447 p.u = x * DEG_TO_RAD;
448 p.v = y * DEG_TO_RAD;
449 p = pj_fwd(p, myProjection);
457 x *= 111320. * cos(
DEG2RAD(y));
462 if (x > std::numeric_limits<double>::max() ||
463 y > std::numeric_limits<double>::max()) {
static void writeLocation(OutputDevice &into)
writes the location element
void moveby(double x, double y, double z=0)
Moves the boundary by the given amount.
#define WRITE_WARNING(msg)
const Boundary & getConvBoundary() const
Returns the converted boundary.
GeoConvHelper & operator=(const GeoConvHelper &)
make assignment operator private
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation.
Static storage of an output device and its base (abstract) implementation.
static void setLoaded(const GeoConvHelper &loaded)
sets the coordinate transformation loaded from a location element
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static GeoConvHelper myLoaded
coordinate transformation loaded from a location element
const Position getOffset() const
Returns the network offset.
static methods for processing the coordinates conversion for the current net
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
const std::string & getProjString() const
Returns the original projection definition.
Boundary myOrigBoundary
The boundary before conversion (x2cartesian)
@ SUMO_ATTR_ORIG_BOUNDARY
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void moveConvertedBy(double x, double y)
Shifts the converted boundary by the given amounts.
~GeoConvHelper()
Destructor.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Boundary myConvBoundary
The boundary after conversion (x2cartesian)
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
bool myUseInverseProjection
Information whether inverse projection shall be used.
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
void set(double x, double y)
set positions x and y
GeoConvHelper(OptionsCont &oc)
Constructor based on the stored options.
A class that stores a 2D geometrical boundary.
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
std::string myProjString
A proj options string describing the proj.4-projection to use.
const Boundary & getOrigBoundary() const
Returns the original boundary.
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
A point in 2D or 3D with translation and scaling methods.
double x() const
Returns the x-position.
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
void sub(double dx, double dy)
Substracts the given position from this one.
const Position getOffsetBase() const
Returns the network base.
A storage for options typed value containers)
void mul(double val)
Multiplies both positions with the given value.
bool myFlatten
whether to discard z-data
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool operator==(const GeoConvHelper &o) const
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
double y() const
Returns the y-position.
static int myNumLoaded
the numer of coordinate transformations loaded from location elements
@ SUMO_ATTR_CONV_BOUNDARY
double myGeoScale
The scaling to apply to geo-coordinates.
void lf()
writes a line feed if applicable
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 usingInverseGeoProjection() const
Returns the information whether an inverse transformation will happen.
static GeoConvHelper myFinal
coordinate transformation to use for writing the location element and for tracking the original coord...
void add(const Position &pos)
Adds the given position to this one.
ProjectionMethod myProjectionMethod
Information whether no projection shall be done.
void flipY()
flips ymin and ymax
void setz(double z)
set position z
static void resetLoaded()
resets loaded location elements
double mySin
The rotation to apply to geo-coordinates.
static GeoConvHelper myProcessing
coordinate transformation to use for input conversion and processing