45 #include <ogrsf_frmts.h>
49 #ifdef CHECK_MEMORY_LEAKS
51 #endif // CHECK_MEMORY_LEAKS
89 WRITE_WARNING(
"Cannot supply height since no height data was loaded");
95 minB[0] = (float)geo.
x() - 0.00001f;
96 minB[1] = (float)geo.
y() - 0.00001f;
97 maxB[0] = (float)geo.
x() + 0.00001f;
98 maxB[1] = (float)geo.
y() + 0.00001f;
100 int hits =
myRTree.Search(minB, maxB, queryResult);
102 assert(hits == (
int)result.size());
105 for (Triangles::iterator it = result.begin(); it != result.end(); it++) {
108 return triangle->
getZ(geo);
121 const float cmin[2] = {(float) b.
xmin(), (float) b.
ymin()};
122 const float cmax[2] = {(float) b.
xmax(), (float) b.
ymax()};
123 myRTree.Insert(cmin, cmax, triangle);
129 if (oc.
isSet(
"heightmap.shapefiles")) {
131 std::vector<std::string> files = oc.
getStringVector(
"heightmap.shapefiles");
132 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
136 " done (parsed " +
toString(numFeatures) +
147 WRITE_ERROR(
"Cannot load shape file since SUMO was compiled without GDAL support.");
151 OGRDataSource* ds = OGRSFDriverRegistrar::Open(file.c_str(), FALSE);
153 throw ProcessError(
"Could not open shape file '" + file +
"'.");
157 OGRLayer* layer = ds->GetLayer(0);
158 layer->ResetReading();
162 OGRSpatialReference* sr_src = layer->GetSpatialRef();
163 OGRSpatialReference sr_dest;
164 sr_dest.SetWellKnownGeogCS(
"WGS84");
165 OGRCoordinateTransformation* toWGS84 = OGRCreateCoordinateTransformation(sr_src, &sr_dest);
167 WRITE_WARNING(
"Could not create geocoordinates converter; check whether proj.4 is installed.");
171 layer->ResetReading();
172 while ((feature = layer->GetNextFeature()) != NULL) {
173 OGRGeometry* geom = feature->GetGeometryRef();
177 assert(std::string(geom->getGeometryName()) == std::string(
"POLYGON"));
179 geom->transform(toWGS84);
180 OGRLinearRing* cgeom = ((OGRPolygon*) geom)->getExteriorRing();
182 assert(cgeom->getNumPoints() == 4);
184 for (
int j = 0; j < 3; j++) {
186 corners.push_back(pos);
223 OGRFeature::DestroyFeature(feature);
225 OGRDataSource::DestroyDataSource(ds);
226 OCTDestroyCoordinateTransformation(toWGS84);
261 return myCorners.around(pos);
279 Position side1 = myCorners[1] - myCorners[0];
280 Position side2 = myCorners[2] - myCorners[0];
void sub(SUMOReal dx, SUMOReal dy)
Substracts the given position from this one.
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
SUMOReal getZ(const Position &geo) const
returns the projection of the give geoCoordinate (WGS84) onto triangle plane
bool ready() const
returns whether the NBHeightMapper has data
Position normalVector() const
returns the normal vector for this triangles plane
int loadShapeFile(const std::string &file)
load height data from Arcgis-shape file and returns the number of
SUMOReal getZ(const Position &geo) const
returns height for the given geo coordinate (WGS84)
SUMOReal ymin() const
Returns minimum y-coordinate.
SUMOReal xmin() const
Returns minimum x-coordinate.
Triangle(const PositionVector &corners)
void addTriangle(PositionVector corners)
adds one triangles worth of height data
void clearData()
clears loaded data
static NBHeightMapper Singleton
the singleton instance
NBHeightMapper()
private constructor and destructor (Singleton)
SUMOReal x() const
Returns the x-position.
#define UNUSED_PARAMETER(x)
SUMOReal xmax() const
Returns maximum x-coordinate.
A class that stores a 2D geometrical boundary.
#define WRITE_WARNING(msg)
static const NBHeightMapper & get()
return the singleton instance (maybe 0)
class for cirumventing the const-restriction of RTree::Search-context
static void loadIfSet(OptionsCont &oc)
loads heigh map data if any loading options are set
TRIANGLE_RTREE_QUAL myRTree
The RTree for spatial queries.
Position crossProduct(const Position &pos)
returns the cross product between this point and the second one
A point in 2D or 3D with translation and scaling methods.
std::vector< const Triangle * > Triangles
#define PROGRESS_BEGIN_MESSAGE(msg)
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
bool contains(const Position &pos) const
checks whether pos lies within triangle (only checks x,y)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Boundary myBoundary
convex boundary of all known triangles;
void add(SUMOReal x, SUMOReal y)
Makes the boundary include the given coordinate.
void reset()
Resets the boundary.
SUMOReal dotProduct(const Position &pos)
returns the dot product (scalar product) between this point and the second one
SUMOReal y() const
Returns the y-position.
PositionVector myCorners
the corners of the triangle
A storage for options typed value containers)
void addSelf(const QueryResult &queryResult) const
callback for RTree search
SUMOReal ymax() const
Returns maximum y-coordinate.
const Boundary & getBoundary()
returns the convex boundary of all known triangles
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Set z-values for all network positions based on data from a height map.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
void endProcessMsg(std::string msg)
Ends a process information.