44 #ifdef CHECK_MEMORY_LEAKS 46 #endif // CHECK_MEMORY_LEAKS 65 myInverseProjection(0),
69 myGeoScale(pow(10, (double) - shift)),
70 myProjectionMethod(NONE),
71 myUseInverseProjection(inverse),
73 myConvBoundary(conv) {
76 }
else if (proj ==
"-") {
78 }
else if (proj ==
"UTM") {
80 }
else if (proj ==
"DHDN") {
82 }
else if (proj ==
"DHDN_UTM") {
87 myProjection = pj_init_plus(proj.c_str());
88 if (myProjection == 0) {
99 if (myProjection != 0) {
100 pj_free(myProjection);
102 if (myInverseProjection != 0) {
103 pj_free(myInverseProjection);
105 if (myGeoProjection != 0) {
106 pj_free(myInverseProjection);
122 if (myProjection != 0) {
123 pj_free(myProjection);
126 if (myInverseProjection != 0) {
127 pj_free(myInverseProjection);
128 myInverseProjection = 0;
130 if (myGeoProjection != 0) {
131 pj_free(myGeoProjection);
134 if (orig.myProjection != 0) {
137 if (orig.myInverseProjection != 0) {
138 myInverseProjection = pj_init_plus(pj_get_def(orig.myInverseProjection, 0));
140 if (orig.myGeoProjection != 0) {
141 myGeoProjection = pj_init_plus(pj_get_def(orig.myGeoProjection, 0));
150 std::string proj =
"!";
151 int shift = oc.
getInt(
"proj.scale");
153 bool inverse = oc.
exists(
"proj.inverse") && oc.
getBool(
"proj.inverse");
155 if (oc.
getBool(
"simple-projection")) {
161 WRITE_ERROR(
"Inverse projection works only with explicit proj parameters.");
165 if (numProjections > 1) {
166 WRITE_ERROR(
"The projection method needs to be uniquely defined.");
172 }
else if (oc.
getBool(
"proj.dhdn")) {
174 }
else if (oc.
getBool(
"proj.dhdnutm")) {
202 oc.
addSynonyme(
"simple-projection",
"proj.simple",
true);
203 oc.
addDescription(
"simple-projection",
"Projection",
"Uses a simple method for projection");
207 oc.
addDescription(
"proj.scale",
"Projection",
"Number of places to shift decimal point to right in geo-coordinates");
211 oc.
addDescription(
"proj.utm",
"Projection",
"Determine the UTM zone (for a universal transversal mercator projection based on the WGS84 ellipsoid)");
214 oc.
addDescription(
"proj.dhdn",
"Projection",
"Determine the DHDN zone (for a transversal mercator projection based on the bessel ellipsoid, \"Gauss-Krueger\")");
217 oc.
addDescription(
"proj",
"Projection",
"Uses STR as proj.4 definition for projection");
220 oc.
addDescription(
"proj.inverse",
"Projection",
"Inverses projection");
223 oc.
addDescription(
"proj.dhdnutm",
"Projection",
"Convert from Gauss-Krueger to UTM");
250 p = pj_inv(p, myProjection);
261 if (includeInBoundary) {
266 if (myProjection == 0) {
270 int zone = (int)((x - 500000.) / 1000000.);
271 if (zone < 1 || zone > 5) {
276 " +k=1 +x_0=" +
toString(zone * 1000000 + 500000) +
277 " +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
278 myInverseProjection = pj_init_plus(
myProjString.c_str());
279 myGeoProjection = pj_init_plus(
"+proj=latlong +datum=WGS84");
281 x = ((x - 500000.) / 1000000.) * 3;
284 int zone = (int)(x + 180) / 6 + 1;
286 " +ellps=WGS84 +datum=WGS84 +units=m +no_defs";
292 int zone = (int)(x / 3);
293 if (zone < 1 || zone > 5) {
298 " +k=1 +x_0=" +
toString(zone * 1000000 + 500000) +
299 " +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
308 if (myInverseProjection != 0) {
311 if (pj_transform(myInverseProjection, myGeoProjection, 1, 1, &x, &y, NULL)) {
320 if (includeInBoundary) {
337 if (x > 180.1 || x < -180.1) {
341 if (y > 90.1 || y < -90.1) {
346 if (myProjection != 0) {
348 p.u = x * DEG_TO_RAD;
349 p.v = y * DEG_TO_RAD;
350 p = pj_fwd(p, myProjection);
358 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.
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
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
~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...
#define GEO_OUTPUT_ACCURACY
bool x2cartesian(Position &from, bool includeInBoundary=true)
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
Boundary myOrigBoundary
The boundary before conversion (x2cartesian)
void setPrecision(int precision=OUTPUT_ACCURACY)
Sets the precison or resets it to default.
static void setLoaded(const GeoConvHelper &loaded)
sets the coordinate transformation loaded from a location element
const Boundary & getOrigBoundary() const
Returns the original boundary.
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 network offset.
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.
bool myUseInverseProjection
Information whether inverse projection shall be used.
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
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.
SUMOReal x() const
Returns the x-position.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
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, SUMOReal z=0)
Makes the boundary include the given coordinate.
void flipY()
flips ymin and ymax
A storage for options typed value containers)
void set(SUMOReal x, SUMOReal y)
void mul(SUMOReal val)
Multiplies both positions with the given value.
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()
Closes the most recently opened tag.
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.
SUMOReal y() const
Returns the y-position.
void moveby(SUMOReal x, SUMOReal y, SUMOReal z=0)
Moves the boundary by the given amount.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void lf()
writes a line feed if applicable
void moveConvertedBy(SUMOReal x, SUMOReal y)
Shifts the converted boundary by the given amounts.
GeoConvHelper & operator=(const GeoConvHelper &)
assignment operator.
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)