38 #pragma GCC diagnostic push
39 #pragma GCC diagnostic ignored "-Wpedantic"
41 #include <ogrsf_frmts.h>
43 #include <gdal_priv.h>
45 #pragma GCC diagnostic pop
84 WRITE_WARNING(
"Cannot supply height since no height data was loaded");
88 const Boundary& boundary = item.first;
89 int16_t* raster = item.second;
91 if (boundary.
around(geo)) {
96 corners.push_back(
Position(floor(normX) + 0.5, floor(normY) + 0.5, raster[(
int)normY * xSize + (
int)normX]));
97 if (normX - floor(normX) > 0.5) {
98 corners.push_back(
Position(floor(normX) + 1.5, floor(normY) + 0.5, raster[(
int)normY * xSize + (
int)normX + 1]));
100 corners.push_back(
Position(floor(normX) - 0.5, floor(normY) + 0.5, raster[(
int)normY * xSize + (
int)normX - 1]));
102 if (normY - floor(normY) > 0.5) {
103 corners.push_back(
Position(floor(normX) + 0.5, floor(normY) + 1.5, raster[((
int)normY + 1) * xSize + (
int)normX]));
105 corners.push_back(
Position(floor(normX) + 0.5, floor(normY) - 0.5, raster[((
int)normY - 1) * xSize + (
int)normX]));
109 if (result > -1e5 && result < 1e5) {
116 minB[0] = (float)geo.
x() - 0.00001f;
117 minB[1] = (float)geo.
y() - 0.00001f;
118 maxB[0] = (float)geo.
x() + 0.00001f;
119 maxB[1] = (float)geo.
y() + 0.00001f;
121 int hits =
myRTree.Search(minB, maxB, queryResult);
123 assert(hits == (
int)result.size());
126 for (Triangles::iterator it = result.begin(); it != result.end(); it++) {
129 return triangle->
getZ(geo);
142 const float cmin[2] = {(float) b.
xmin(), (float) b.
ymin()};
143 const float cmax[2] = {(float) b.
xmax(), (float) b.
ymax()};
144 myRTree.Insert(cmin, cmax, triangle);
150 if (oc.
isSet(
"heightmap.geotiff")) {
152 std::vector<std::string> files = oc.
getStringVector(
"heightmap.geotiff");
153 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
157 " done (parsed " +
toString(numFeatures) +
161 if (oc.
isSet(
"heightmap.shapefiles")) {
163 std::vector<std::string> files = oc.
getStringVector(
"heightmap.shapefiles");
164 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
168 " done (parsed " +
toString(numFeatures) +
178 #if GDAL_VERSION_MAJOR < 2
180 OGRDataSource* ds = OGRSFDriverRegistrar::Open(file.c_str(), FALSE);
183 GDALDataset* ds = (GDALDataset*)GDALOpenEx(file.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
186 throw ProcessError(
"Could not open shape file '" + file +
"'.");
190 OGRLayer* layer = ds->GetLayer(0);
191 layer->ResetReading();
195 OGRSpatialReference* sr_src = layer->GetSpatialRef();
196 OGRSpatialReference sr_dest;
197 sr_dest.SetWellKnownGeogCS(
"WGS84");
198 OGRCoordinateTransformation* toWGS84 = OGRCreateCoordinateTransformation(sr_src, &sr_dest);
200 WRITE_WARNING(
"Could not create geocoordinates converter; check whether proj.4 is installed.");
205 layer->ResetReading();
206 while ((feature = layer->GetNextFeature()) != NULL) {
207 OGRGeometry* geom = feature->GetGeometryRef();
211 assert(std::string(geom->getGeometryName()) == std::string(
"POLYGON"));
213 geom->transform(toWGS84);
214 OGRLinearRing* cgeom = ((OGRPolygon*) geom)->getExteriorRing();
216 assert(cgeom->getNumPoints() == 4);
218 for (
int j = 0; j < 3; j++) {
219 Position pos((
double) cgeom->getX(j), (double) cgeom->getY(j), (double) cgeom->getZ(j));
220 corners.push_back(pos);
257 OGRFeature::DestroyFeature(feature);
259 #if GDAL_VERSION_MAJOR < 2
260 OGRDataSource::DestroyDataSource(ds);
264 OCTDestroyCoordinateTransformation(reinterpret_cast<OGRCoordinateTransformationH>(toWGS84));
269 WRITE_ERROR(
"Cannot load shape file since SUMO was compiled without GDAL support.");
279 GDALDataset* poDataset = (GDALDataset*)GDALOpen(file.c_str(), GA_ReadOnly);
280 if (poDataset == 0) {
285 const int xSize = poDataset->GetRasterXSize();
286 const int ySize = poDataset->GetRasterYSize();
287 double adfGeoTransform[6];
288 if (poDataset->GetGeoTransform(adfGeoTransform) == CE_None) {
289 Position topLeft(adfGeoTransform[0], adfGeoTransform[3]);
293 boundary.
add(topLeft);
294 boundary.
add(topLeft.
x() + horizontalSize, topLeft.
y() + verticalSize);
296 WRITE_ERROR(
"Could not parse geo information from " + file +
".");
299 const int picSize = xSize * ySize;
300 int16_t* raster = (int16_t*)CPLMalloc(
sizeof(int16_t) * picSize);
301 for (
int i = 1; i <= poDataset->GetRasterCount(); i++) {
302 GDALRasterBand* poBand = poDataset->GetRasterBand(i);
303 if (poBand->GetColorInterpretation() != GCI_GrayIndex) {
304 WRITE_ERROR(
"Unknown color band in " + file +
".");
308 if (poBand->GetRasterDataType() != GDT_Int16) {
313 assert(xSize == poBand->GetXSize() && ySize == poBand->GetYSize());
314 if (poBand->RasterIO(GF_Read, 0, 0, xSize, ySize, raster, xSize, ySize, GDT_Int16, 0, 0) == CE_Failure) {
320 GDALClose(poDataset);
321 myRasters.push_back(std::make_pair(boundary, raster));
325 WRITE_ERROR(
"Cannot load GeoTIFF file since SUMO was compiled without GDAL support.");
339 CPLFree(item.second);
365 return myCorners.around(pos);
383 Position side1 = myCorners[1] - myCorners[0];
384 Position side2 = myCorners[2] - myCorners[0];