From 89b76857641f3f5202f638e625e0fb744d1c65ae Mon Sep 17 00:00:00 2001 From: Michael Reichert Date: Wed, 29 Jul 2026 17:01:50 +0200 Subject: [PATCH] Transform all estimated extents to EPSG:3857 If the database table contains geometries in EPGS:4326, ST_EstimateExtent would return a wrong extent for tile-based processing. --- src/gen/osm2pgsql-gen.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/gen/osm2pgsql-gen.cpp b/src/gen/osm2pgsql-gen.cpp index 4a5bc49af..c90a96067 100644 --- a/src/gen/osm2pgsql-gen.cpp +++ b/src/gen/osm2pgsql-gen.cpp @@ -114,14 +114,21 @@ tile_extent get_extent_from_db(pg_conn_t const &db_connection, result = db_connection.exec( "SELECT ST_XMin(extent), ST_YMin(extent)," " ST_XMax(extent), ST_YMax(extent)" - " FROM raster_columns WHERE r_table_schema='{}'" - " AND r_table_name='{}' AND r_raster_column = '{}'", + " FROM (" + " SELECT ST_Transform(extent, 3857) AS extent" + " FROM raster_columns WHERE r_table_schema='{}'" + " AND r_table_name='{}' AND r_raster_column = '{}'" + " ) a", schema, table, column); } else { result = db_connection.exec( "SELECT ST_XMin(e), ST_YMin(e), ST_XMax(e), ST_YMax(e)" - " FROM ST_EstimatedExtent('{}', '{}', '{}') AS e", - schema, table, column); + " FROM ST_Transform(" + " ST_SetSRID(" + " ST_EstimatedExtent('{}', '{}', '{}'), " + " (SELECT ST_SRID(way) FROM {} LIMIT 1)" + " ), 3857) e", + schema, table, column, qualified_name(schema, table)); } if (result.num_tuples() == 0 || result.is_null(0, 0)) {