43 #ifdef CHECK_MEMORY_LEAKS
45 #endif // CHECK_MEMORY_LEAKS
64 myInverseProjection(0),
68 myGeoScale(pow(10, (double) - shift)),
69 myProjectionMethod(NONE),
70 myUseInverseProjection(inverse),
72 myConvBoundary(conv) {
75 }
else if (proj ==
"-") {
77 }
else if (proj ==
"UTM") {
79 }
else if (proj ==
"DHDN") {
81 }
else if (proj ==
"DHDN_UTM") {
86 myProjection = pj_init_plus(proj.c_str());
87 if (myProjection == 0) {
98 if (myProjection != 0) {
99 pj_free(myProjection);
101 if (myInverseProjection != 0) {
102 pj_free(myInverseProjection);
104 if (myGeoProjection != 0) {
105 pj_free(myInverseProjection);
121 if (myProjection != 0) {
122 pj_free(myProjection);
125 if (myInverseProjection != 0) {
126 pj_free(myInverseProjection);
127 myInverseProjection = 0;
129 if (myGeoProjection != 0) {
130 pj_free(myGeoProjection);
133 if (orig.myProjection != 0) {
136 if (orig.myInverseProjection != 0) {
137 myInverseProjection = pj_init_plus(pj_get_def(orig.myInverseProjection, 0));
139 if (orig.myGeoProjection != 0) {
140 myGeoProjection = pj_init_plus(pj_get_def(orig.myGeoProjection, 0));
149 std::string proj =
"!";
150 int shift = oc.
getInt(
"proj.scale");
152 bool inverse = oc.
exists(
"proj.inverse") && oc.
getBool(
"proj.inverse");
154 if (oc.
getBool(
"simple-projection")) {
160 WRITE_ERROR(
"Inverse projection works only with explicit proj parameters.");
164 if (numProjections > 1) {
165 WRITE_ERROR(
"The projection method needs to be uniquely defined.");
171 }
else if (oc.
getBool(
"proj.dhdn")) {
173 }
else if (oc.
getBool(
"proj.dhdnutm")) {
201 oc.
addSynonyme(
"simple-projection",
"proj.simple",
true);
202 oc.
addDescription(
"simple-projection",
"Projection",
"Uses a simple method for projection");
206 oc.
addDescription(
"proj.scale",
"Projection",
"Number of places to shift decimal point to right in geo-coordinates");
210 oc.
addDescription(
"proj.utm",
"Projection",
"Determine the UTM zone (for a universal transversal mercator projection based on the WGS84 ellipsoid)");
213 oc.
addDescription(
"proj.dhdn",
"Projection",
"Determine the DHDN zone (for a transversal mercator projection based on the bessel ellipsoid, \"Gauss-Krueger\")");
216 oc.
addDescription(
"proj",
"Projection",
"Uses STR as proj.4 definition for projection");
219 oc.
addDescription(
"proj.inverse",
"Projection",
"Inverses projection");
222 oc.
addDescription(
"proj.dhdnutm",
"Projection",
"Convert from Gauss-Krueger to UTM");
249 p = pj_inv(p, myProjection);
260 if (includeInBoundary) {
265 if (myProjection == 0) {
269 int zone = (
int)((x - 500000.) / 1000000.);
270 if (zone < 1 || zone > 5) {
275 " +k=1 +x_0=" +
toString(zone * 1000000 + 500000) +
276 " +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
277 myInverseProjection = pj_init_plus(
myProjString.c_str());
278 myGeoProjection = pj_init_plus(
"+proj=latlong +datum=WGS84");
280 x = ((x - 500000.) / 1000000.) * 3;
283 int zone = (
int)(x + 180) / 6 + 1;
285 " +ellps=WGS84 +datum=WGS84 +units=m +no_defs";
291 int zone = (
int)(x / 3);
292 if (zone < 1 || zone > 5) {
297 " +k=1 +x_0=" +
toString(zone * 1000000 + 500000) +
298 " +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
307 if (myInverseProjection != 0) {
310 if (pj_transform(myInverseProjection, myGeoProjection, 1, 1, &x, &y, NULL)) {
319 if (includeInBoundary) {
336 if (x > 180.1 || x < -180.1 || y > 90.1 || y < -90.1) {
340 if (myProjection != 0) {
342 p.u = x * DEG_TO_RAD;
343 p.v = y * DEG_TO_RAD;
344 p = pj_fwd(p, myProjection);
352 x *= 111320. * cos(
DEG2RAD(ys));
void sub(SUMOReal dx, SUMOReal dy)
Substracts the given position from this one.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
static GeoConvHelper myProcessing
coordinate transformation to use for input conversion and processing
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation. ...
~GeoConvHelper()
Destructor.
void add(const Position &pos)
Adds the given position to this one.
Position myOffset
The offset to apply.
bool x2cartesian(Position &from, bool includeInBoundary=true)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Boundary myOrigBoundary
The boundary before conversion (x2cartesian)
static void setLoaded(const GeoConvHelper &loaded)
sets the coordinate transformation loaded from a location element
static GeoConvHelper myLoaded
coordinate transformation loaded from a location element
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
static void resetLoaded()
resets loaded location elements
bool myUseInverseProjection
Information whether inverse projection shall be used.
SUMOReal x() const
Returns the x-position.
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)
double myGeoScale
The scaling to apply to geo-coordinates.
static void computeFinal()
compute the location attributes which will be used for output based on the loaded location data...
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
static methods for processing the coordinates conversion for the current net
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.
const std::string & getProjString() const
Returns the network offset.
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.
const Position getOffsetBase() const
Returns the network base.
const Boundary & getConvBoundary() const
Returns the converted boundary.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
GeoConvHelper(OptionsCont &oc)
Constructor based on the stored options.
Boundary myConvBoundary
The boundary after conversion (x2cartesian)
static int myNumLoaded
the numer of coordinate transformations loaded from location elements
void add(SUMOReal x, SUMOReal y)
Makes the boundary include the given coordinate.
SUMOReal y() const
Returns the y-position.
A storage for options typed value containers)
void set(SUMOReal x, SUMOReal y)
const Position getOffset() const
Returns the network offset.
const Boundary & getOrigBoundary() const
Returns the original boundary.
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void moveby(SUMOReal x, SUMOReal y)
Moves the boundary by the given amount.
bool usingInverseGeoProjection() const
Returns the information whether an inverse transformation will happen.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
void moveConvertedBy(SUMOReal x, SUMOReal y)
Shifts the converted boundary by the given amounts.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
GeoConvHelper & operator=(const GeoConvHelper &)
assignment operator.