#include <GeoConvHelper.h>
Definition at line 55 of file GeoConvHelper.h.
Static Public Member Functions | |
| static void | addProjectionOptions (OptionsCont &oc) |
| Adds projection options to the given container. | |
| static void | cartesian2geo (Position2D &cartesian) |
| Converts the given cartesian (shifted) position to its geo (lat/long) representation. | |
| static void | close () |
| Closes the subsystem. | |
| static const Boundary & | getConvBoundary () |
| Returns the converted boundary. | |
| static const Position2D | getOffsetBase () |
| Returns the network base. | |
| static const Boundary & | getOrigBoundary () |
| Returns the original boundary. | |
| static const std::string & | getProjString () |
| Returns the network offset. | |
| static bool | init (const std::string &proj, const Position2D &offset, const Boundary &orig, const Boundary &conv) |
| Initialises the subsystem using the given proj.4-definition and complete network parameter. | |
| static bool | init (const std::string &proj, const int shift=0, bool inverse=false) |
| Initialises the subsystem using the given proj.4-definition and a network offset. | |
| static bool | init (OptionsCont &oc) |
| Initialises the subsystem using the given options. | |
| static void | moveConvertedBy (SUMOReal x, SUMOReal y) |
| Shifts the converted boundary by the given amounts. | |
| static bool | usingGeoProjection () |
| Returns whether a transformation from geo to metric coordinates will be performed. | |
| static bool | usingInverseGeoProjection () |
| Returns the information whether an inverse transformation will happen. | |
| static bool | x2cartesian (Position2D &from, bool includeInBoundary=true, double x=-1, double y=-1) |
| Converts the given coordinate into a cartesian using the previous initialisation. | |
Private Types | |
| enum | ProjectionMethod { NONE, SIMPLE, UTM, DHDN, PROJ } |
Static Private Attributes | |
| static bool | myBaseFound = false |
| Information whether the first node conversion was done. | |
| static double | myBaseX = 0 |
| The initial x/y-coordinates for a very simple geocoordinates conversion. | |
| static double | myBaseY = 0 |
| static Boundary | myConvBoundary |
| The boundary after conversion (x2cartesian). | |
| static double | myGeoScale = 1.f |
| The scaling to apply to geo-coordinates. | |
| static Position2D | myOffset |
| The offset to apply. | |
| static Boundary | myOrigBoundary |
| The boundary before conversion (x2cartesian). | |
| static ProjectionMethod | myProjectionMethod = NONE |
| Information whether no projection shall be done. | |
| static std::string | myProjString = "!" |
| A proj options string describing the proj.4-projection to use. | |
| static bool | myUseInverseProjection = false |
| Information whether inverse projection shall be used. | |
enum GeoConvHelper::ProjectionMethod [private] |
| void GeoConvHelper::addProjectionOptions | ( | OptionsCont & | oc | ) | [static] |
Adds projection options to the given container.
| [in] | oc | The options container to add the options to |
Definition at line 69 of file GeoConvHelper.cpp.
References OptionsCont::addDescription(), OptionsCont::addOptionSubTopic(), and OptionsCont::doRegister().
Referenced by fillOptions(), and NIOptionsIO::fillOptions().
00069 { 00070 oc.addOptionSubTopic("Projection"); 00071 00072 oc.doRegister("proj.simple", new Option_Bool(false)); 00073 oc.addDescription("proj.simple", "Projection", "Uses a simple method for projection"); 00074 00075 oc.doRegister("proj.shift", new Option_Integer(0)); 00076 oc.addDescription("proj.shift", "Projection", "Number of places to shift decimal point to right in geo-coordinates"); 00077 00078 #ifdef HAVE_PROJ 00079 oc.doRegister("proj.utm", new Option_Bool(false)); 00080 oc.addDescription("proj.utm", "Projection", "Determine the UTM zone (for a universal transversal mercator projection based on the WGS84 ellipsoid)"); 00081 00082 oc.doRegister("proj.dhdn", new Option_Bool(false)); 00083 oc.addDescription("proj.dhdn", "Projection", "Determine the DHDN zone (for a transversal mercator projection based on the bessel ellipsoid)"); 00084 00085 oc.doRegister("proj", new Option_String("!")); 00086 oc.addDescription("proj", "Projection", "Uses STR as proj.4 definition for projection"); 00087 00088 oc.doRegister("proj.inverse", new Option_Bool(false)); 00089 oc.addDescription("proj.inverse", "Projection", "Inverses projection"); 00090 #endif 00091 }
| void GeoConvHelper::cartesian2geo | ( | Position2D & | cartesian | ) | [static] |
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
Definition at line 201 of file GeoConvHelper.cpp.
References myOffset, myProjectionMethod, NONE, Position2D::set(), Position2D::sub(), SUMOReal, Position2D::x(), and Position2D::y().
Referenced by MSVTypeProbe::execute(), GUISUMOAbstractView::updatePositionInformation(), and x2cartesian().
00201 { 00202 cartesian.sub(myOffset); 00203 if (myProjectionMethod == NONE) { 00204 return; 00205 } 00206 #ifdef HAVE_PROJ 00207 projUV p; 00208 p.u = cartesian.x(); 00209 p.v = cartesian.y(); 00210 p = pj_inv(p, myProjection); 00212 p.u *= RAD_TO_DEG; 00213 p.v *= RAD_TO_DEG; 00214 cartesian.set((SUMOReal) p.u, (SUMOReal) p.v); 00215 #endif 00216 }
| void GeoConvHelper::close | ( | ) | [static] |
Closes the subsystem.
Definition at line 178 of file GeoConvHelper.cpp.
Referenced by init(), and MSNet::~MSNet().
00178 { 00179 #ifdef HAVE_PROJ 00180 if (myProjection != 0) { 00181 pj_free(myProjection); 00182 } 00183 myProjection = 0; 00184 #endif 00185 }
| const Boundary & GeoConvHelper::getConvBoundary | ( | ) | [static] |
Returns the converted boundary.
Definition at line 319 of file GeoConvHelper.cpp.
References myConvBoundary.
Referenced by NBNetBuilder::compute(), and NBNetBuilder::save().
00319 { 00320 return myConvBoundary; 00321 }
| const Position2D GeoConvHelper::getOffsetBase | ( | ) | [static] |
Returns the network base.
Definition at line 325 of file GeoConvHelper.cpp.
References myBaseX, myBaseY, myOffset, Position2D::x(), and Position2D::y().
Referenced by NBNetBuilder::compute(), and NBNetBuilder::save().
| const Boundary & GeoConvHelper::getOrigBoundary | ( | ) | [static] |
Returns the original boundary.
Definition at line 313 of file GeoConvHelper.cpp.
References myOrigBoundary.
Referenced by NBNetBuilder::compute(), and NBNetBuilder::save().
00313 { 00314 return myOrigBoundary; 00315 }
| const std::string & GeoConvHelper::getProjString | ( | ) | [static] |
Returns the network offset.
Definition at line 331 of file GeoConvHelper.cpp.
References myProjString.
Referenced by NILoader::load(), and NBNetBuilder::save().
00331 { 00332 return myProjString; 00333 }
| bool GeoConvHelper::init | ( | const std::string & | proj, | |
| const Position2D & | offset, | |||
| const Boundary & | orig, | |||
| const Boundary & | conv | |||
| ) | [static] |
Initialises the subsystem using the given proj.4-definition and complete network parameter.
Definition at line 165 of file GeoConvHelper.cpp.
References Boundary::add(), init(), myConvBoundary, myOffset, and myOrigBoundary.
00168 { 00169 bool ret = init(proj); 00170 myOffset = offset; 00171 myOrigBoundary.add(orig); 00172 myConvBoundary.add(conv); 00173 return ret; 00174 }
| bool GeoConvHelper::init | ( | const std::string & | proj, | |
| const int | shift = 0, |
|||
| bool | inverse = false | |||
| ) | [static] |
Initialises the subsystem using the given proj.4-definition and a network offset.
Definition at line 131 of file GeoConvHelper.cpp.
References close(), myBaseFound, myConvBoundary, myGeoScale, myOrigBoundary, myProjectionMethod, myProjString, myUseInverseProjection, NONE, PROJ, Boundary::reset(), and SIMPLE.
00133 { 00134 myProjString = proj; 00135 myGeoScale = pow(10, (double)-shift); 00136 myUseInverseProjection = inverse; 00137 close(); 00138 myBaseFound = false; 00139 myOrigBoundary.reset(); 00140 myConvBoundary.reset(); 00141 if (proj=="!") { 00142 myProjectionMethod = NONE; 00143 return true; 00144 } 00145 if (proj=="-") { 00146 myProjectionMethod = SIMPLE; 00147 return true; 00148 } 00149 if (proj==".") { 00150 return true; 00151 } 00152 #ifdef HAVE_PROJ 00153 myProjection = pj_init_plus(proj.c_str()); 00154 // !!! check pj_errno 00155 if (myProjection != 0) { 00156 myProjectionMethod = PROJ; 00157 return true; 00158 } 00159 #endif 00160 return false; 00161 }
| bool GeoConvHelper::init | ( | OptionsCont & | oc | ) | [static] |
Initialises the subsystem using the given options.
Definition at line 95 of file GeoConvHelper.cpp.
References DHDN, OptionsCont::exists(), OptionsCont::getBool(), MsgHandler::getErrorInstance(), OptionsCont::getFloat(), OptionsCont::getInt(), OptionsCont::getString(), MsgHandler::inform(), OptionsCont::isDefault(), myBaseFound, myOffset, myProjectionMethod, and UTM.
Referenced by init(), NILoader::load(), main(), NLHandler::myCharacters(), and NLHandler::setLocation().
00095 { 00096 #ifdef HAVE_PROJ 00097 if (oc.getBool("proj.inverse") && oc.getString("proj") == "!") { 00098 MsgHandler::getErrorInstance()->inform("Inverse projection works only with explicit proj parameters."); 00099 return false; 00100 } 00101 unsigned numProjections = oc.getBool("proj.simple") + oc.getBool("proj.utm") + oc.getBool("proj.dhdn") + (oc.getString("proj").length() > 1); 00102 if (numProjections > 1) { 00103 MsgHandler::getErrorInstance()->inform("The projection method needs to be uniquely defined."); 00104 return false; 00105 } 00106 #endif 00107 myOffset = Position2D(oc.getFloat("x-offset-to-apply"), oc.getFloat("y-offset-to-apply")); 00108 if (oc.getBool("proj.simple")) { 00109 return init("-", oc.getInt("proj.shift")); 00110 } 00111 bool ret = true; 00112 #ifdef HAVE_PROJ 00113 if (oc.getBool("proj.utm")) { 00114 myProjectionMethod = UTM; 00115 ret = init(".", oc.getInt("proj.shift")); 00116 } else if (oc.getBool("proj.dhdn")) { 00117 myProjectionMethod = DHDN; 00118 ret = init(".", oc.getInt("proj.shift")); 00119 } else { 00120 ret = init(oc.getString("proj"), oc.getInt("proj.shift"), oc.getBool("proj.inverse")); 00121 } 00122 #endif 00123 if (!oc.exists("disable-normalize-node-positions") || oc.getBool("disable-normalize-node-positions") || !oc.isDefault("x-offset-to-apply") || !oc.isDefault("y-offset-to-apply")) { 00124 myBaseFound = true; 00125 } 00126 return ret; 00127 }
| void GeoConvHelper::moveConvertedBy | ( | SUMOReal | x, | |
| SUMOReal | y | |||
| ) | [static] |
Shifts the converted boundary by the given amounts.
Definition at line 306 of file GeoConvHelper.cpp.
References Position2D::add(), Boundary::moveby(), myConvBoundary, and myOffset.
Referenced by NBNetBuilder::compute().
00306 { 00307 myOffset.add(x, y); 00308 myConvBoundary.moveby(x, y); 00309 }
| bool GeoConvHelper::usingGeoProjection | ( | ) | [static] |
Returns whether a transformation from geo to metric coordinates will be performed.
Definition at line 189 of file GeoConvHelper.cpp.
References myProjectionMethod, and NONE.
Referenced by MSVTypeProbe::execute(), NILoader::load(), NBNetBuilder::save(), and GUISUMOAbstractView::updatePositionInformation().
00189 { 00190 return myProjectionMethod != NONE; 00191 }
| bool GeoConvHelper::usingInverseGeoProjection | ( | ) | [static] |
Returns the information whether an inverse transformation will happen.
Definition at line 195 of file GeoConvHelper.cpp.
References myUseInverseProjection.
Referenced by NBNodeCont::savePlain().
00195 { 00196 return myUseInverseProjection; 00197 }
| bool GeoConvHelper::x2cartesian | ( | Position2D & | from, | |
| bool | includeInBoundary = true, |
|||
| double | x = -1, |
|||
| double | y = -1 | |||
| ) | [static] |
Converts the given coordinate into a cartesian using the previous initialisation.
!! recheck whether the axes are mirrored
Definition at line 220 of file GeoConvHelper.cpp.
References Position2D::add(), Boundary::add(), cartesian2geo(), DHDN, myBaseFound, myBaseX, myBaseY, myConvBoundary, myGeoScale, myOffset, myOrigBoundary, myProjectionMethod, myProjString, myUseInverseProjection, NONE, PI, Position2D::set(), SIMPLE, SUMOReal, toString(), UTM, Position2D::x(), and Position2D::y().
Referenced by NIImporter_SUMO::addJunction(), NGNode::buildNBNode(), NIImporter_OpenDrive::computeShapes(), NIImporter_OpenStreetMap::insertEdge(), NIImporter_OpenStreetMap::insertNodeChecking(), PCLoaderVisum::load(), PCLoaderArcView::load(), NIImporter_ArcView::load(), PCLoaderOSM::loadIfSet(), NIImporter_RobocupRescue::loadNodes(), PCLoaderDlrNavteq::loadPOIFile(), PCLoaderDlrNavteq::loadPolyFile(), PCLoaderXML::myCharacters(), PCLoaderXML::myStartElement(), NIXMLNodesHandler::myStartElement(), NIVissimAbstractEdge::NIVissimAbstractEdge(), NIImporter_VISUM::parse_Districts(), NIImporter_VISUM::parse_EdgePolys(), NIImporter_VISUM::parse_Nodes(), NIImporter_VISUM::parse_Point(), NIImporter_DlrNavteq::NodesHandler::report(), NIXMLEdgesHandler::setNodes(), and NIXMLEdgesHandler::tryGetShape().
00220 { 00221 myOrigBoundary.add(from); 00222 if (x == -1 && y == -1) { 00223 x = from.x(); 00224 y = from.y(); 00225 } 00226 if (myProjectionMethod == NONE) { 00227 from.add(myOffset); 00228 } else if (myUseInverseProjection) { 00229 cartesian2geo(from); 00230 } else { 00231 x *= myGeoScale; 00232 y *= myGeoScale; 00233 if (x > 180.1 || x < -180.1 || y > 90.1 || y < -90.1) { 00234 return false; 00235 } 00236 #ifdef HAVE_PROJ 00237 if (myProjection==0) { 00238 if (myProjectionMethod == UTM) { 00239 int zone = (int)(x + 180) / 6 + 1; 00240 myProjString = "+proj=utm +zone=" + toString(zone) + 00241 " +ellps=WGS84 +datum=WGS84 +units=m +no_defs"; 00242 myProjection = pj_init_plus(myProjString.c_str()); 00244 } 00245 if (myProjectionMethod == DHDN) { 00246 int zone = (int)(x / 3); 00247 if (zone < 1 || zone > 5) { 00248 return false; 00249 } 00250 myProjString = "+proj=tmerc +lat_0=0 +lon_0=" + toString(3*zone) + 00251 " +k=1 +x_0=" + toString(zone * 1000000 + 500000) + 00252 " +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs"; 00253 myProjection = pj_init_plus(myProjString.c_str()); 00255 } 00256 } 00257 if (myProjection!=0) { 00258 projUV p; 00259 p.u = x * DEG_TO_RAD; 00260 p.v = y * DEG_TO_RAD; 00261 p = pj_fwd(p, myProjection); 00263 x = p.u; 00264 y = p.v; 00265 } 00266 #endif 00267 if (myProjectionMethod == SIMPLE) { 00268 double ys = y; 00269 if (!myBaseFound) { 00270 myBaseX = x; 00271 myBaseY = y; 00272 myBaseFound = true; 00273 } 00274 x -= myBaseX; 00275 y -= myBaseY; 00276 x *= 111320. * cos(ys*PI/180.0); 00277 y *= 111136.; 00278 from.set((SUMOReal)x, (SUMOReal)y); 00280 from.add(myOffset); 00281 } 00282 } 00283 if (myProjectionMethod != SIMPLE) { 00284 if (!myBaseFound) { 00285 if (x > 100000 || y > 100000) { 00286 myBaseX = x; 00287 myBaseY = y; 00288 } 00289 myBaseFound = true; 00290 } 00291 if (myBaseFound) { 00292 x -= myBaseX; 00293 y -= myBaseY; 00294 } 00295 from.set((SUMOReal)x, (SUMOReal)y); 00296 from.add(myOffset); 00297 } 00298 if (includeInBoundary) { 00299 myConvBoundary.add(from); 00300 } 00301 return true; 00302 }
bool GeoConvHelper::myBaseFound = false [static, private] |
Information whether the first node conversion was done.
Definition at line 138 of file GeoConvHelper.h.
Referenced by init(), and x2cartesian().
double GeoConvHelper::myBaseX = 0 [static, private] |
The initial x/y-coordinates for a very simple geocoordinates conversion.
Definition at line 141 of file GeoConvHelper.h.
Referenced by getOffsetBase(), and x2cartesian().
double GeoConvHelper::myBaseY = 0 [static, private] |
Boundary GeoConvHelper::myConvBoundary [static, private] |
The boundary after conversion (x2cartesian).
Definition at line 147 of file GeoConvHelper.h.
Referenced by getConvBoundary(), init(), moveConvertedBy(), and x2cartesian().
double GeoConvHelper::myGeoScale = 1.f [static, private] |
The scaling to apply to geo-coordinates.
Definition at line 129 of file GeoConvHelper.h.
Referenced by init(), and x2cartesian().
Position2D GeoConvHelper::myOffset [static, private] |
The offset to apply.
Definition at line 126 of file GeoConvHelper.h.
Referenced by cartesian2geo(), getOffsetBase(), init(), moveConvertedBy(), and x2cartesian().
Boundary GeoConvHelper::myOrigBoundary [static, private] |
The boundary before conversion (x2cartesian).
Definition at line 144 of file GeoConvHelper.h.
Referenced by getOrigBoundary(), init(), and x2cartesian().
GeoConvHelper::ProjectionMethod GeoConvHelper::myProjectionMethod = NONE [static, private] |
Information whether no projection shall be done.
Definition at line 132 of file GeoConvHelper.h.
Referenced by cartesian2geo(), init(), usingGeoProjection(), and x2cartesian().
std::string GeoConvHelper::myProjString = "!" [static, private] |
A proj options string describing the proj.4-projection to use.
Definition at line 118 of file GeoConvHelper.h.
Referenced by getProjString(), init(), and x2cartesian().
bool GeoConvHelper::myUseInverseProjection = false [static, private] |
Information whether inverse projection shall be used.
Definition at line 135 of file GeoConvHelper.h.
Referenced by init(), usingInverseGeoProjection(), and x2cartesian().
1.5.6