 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
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) {
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()) {
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)
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
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