Skip to content

Commit

Permalink
Make isochrone geotiff serialization use "north up" geotransform (val…
Browse files Browse the repository at this point in the history
  • Loading branch information
saranrapjs authored and ianthetechie committed Feb 7, 2025
1 parent bd2f3f9 commit 23eed9f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* FIXED: update CircleCI runners to Ubuntu 24.04 [#5002](https://github.com/valhalla/valhalla/pull/5002)
* FIXED: Fixed a typo in the (previously undocumented) matrix-APIs responses `algorithm` field: `timedistancbssematrix` is now `timedistancebssmatrix` [#5000](https://github.com/valhalla/valhalla/pull/5000).
* FIXED: More trivial cases in `CostMatrix` [#5001](https://github.com/valhalla/valhalla/pull/5001)
* FIXED: Make isochrone geotiff serialization use "north up" geotransform [#5019](https://github.com/valhalla/valhalla/pull/5019)
* **Enhancement**
* ADDED: Consider smoothness in all profiles that use surface [#4949](https://github.com/valhalla/valhalla/pull/4949)
* ADDED: `admin_crossings` request parameter for `/route` [#4941](https://github.com/valhalla/valhalla/pull/4941)
Expand Down
8 changes: 4 additions & 4 deletions src/tyr/isochrone_serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,9 @@ std::string serializeGeoTIFF(Api& request, const std::shared_ptr<const GriddedDa
double geo_transform[6] = {isogrid->TileBounds(isogrid->TileId(box[0], box[1])).minx(), // minx
isogrid->TileSize(),
0,
isogrid->TileBounds(isogrid->TileId(box[0], box[1])).miny(), // miny
isogrid->TileBounds(isogrid->TileId(box[0], box[3])).maxy(), // maxy
0,
isogrid->TileSize()};

-isogrid->TileSize()};
geotiff_dataset->SetGeoTransform(geo_transform);
geotiff_dataset->SetSpatialRef(const_cast<OGRSpatialReference*>(&spatial_ref));

Expand All @@ -214,10 +213,11 @@ std::string serializeGeoTIFF(Api& request, const std::shared_ptr<const GriddedDa
for (int32_t i = 0; i < ext_y; ++i) {
for (int32_t j = 0; j < ext_x; ++j) {
auto tileid = isogrid->TileId(j + box[0], i + box[1]);
data[i * ext_x + j] =
data[(ext_y - 1 - i) * ext_x + j] =
static_cast<uint16_t>(isogrid->DataAt(tileid, metric_idx) * scale_factor);
}
}

auto band = geotiff_dataset->GetRasterBand(nbands == 2 ? (metric_idx + 1) : 1);
band->SetNoDataValue(std::numeric_limits<uint16_t>::max());
band->SetDescription(metric_idx == 0 ? "Time (seconds)" : "Distance (10m)");
Expand Down
25 changes: 25 additions & 0 deletions test/isochrone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,31 @@ TEST(Isochrones, test_geotiff_output_time_distance) {
}
VSIFCloseL(handle);
}
TEST(Isochrones, test_geotiff_vertical_orientation) {
loki_worker_t loki_worker(cfg);
thor_worker_t thor_worker(cfg);

const auto request =
R"({"costing":"auto","locations":[{"lon":5.042799,"lat":52.093199}],"contours":[{"distance":1}], "format": "geotiff"})";
Api request_pbf;
ParseApi(request, Options::isochrone, request_pbf);
loki_worker.isochrones(request_pbf);
std::string geotiff = thor_worker.isochrones(request_pbf);

std::string name = "/vsimem/test_isogrid_geotiff_d.tif";
unsigned char buffer[geotiff.length()];
std::copy(geotiff.cbegin(), geotiff.cend(), buffer);
auto handle = VSIFileFromMemBuffer(name.c_str(), buffer, static_cast<int>(geotiff.size()), 0);
auto geotiff_dataset = GDALDataset::FromHandle(GDALOpen(name.c_str(), GA_ReadOnly));
int y = geotiff_dataset->GetRasterYSize();
double geoTransform[6];
geotiff_dataset->GetGeoTransform(geoTransform);
double topY = geoTransform[3] + 0 * geoTransform[4] + 0 * geoTransform[5];
double bottomY = geoTransform[3] + 0 * geoTransform[4] + y * geoTransform[5];
ASSERT_TRUE(topY > bottomY);

VSIFCloseL(handle);
}
#endif

} // namespace
Expand Down

0 comments on commit 23eed9f

Please # to comment.