From f9548e03033f528156f79433bbce380e37d31fee Mon Sep 17 00:00:00 2001 From: Pirmin Kalberer Date: Sun, 6 Dec 2020 23:29:56 +0100 Subject: [PATCH] Apply ST_Buffer on ST_SnapToGrid output to fix exception in ST_MakeValid --- t-rex-core/src/datasource/postgis_ds.rs | 2 +- t-rex-core/src/datasource/postgis_test.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/t-rex-core/src/datasource/postgis_ds.rs b/t-rex-core/src/datasource/postgis_ds.rs index 4e1243a4..58f9de2a 100644 --- a/t-rex-core/src/datasource/postgis_ds.rs +++ b/t-rex-core/src/datasource/postgis_ds.rs @@ -329,7 +329,7 @@ impl PostgisDatasource { ), "POLYGON" | "MULTIPOLYGON" | "CURVEPOLYGON" => { format!( - "ST_CollectionExtract(ST_MakeValid(ST_SnapToGrid({}, {})),3)::geometry(MULTIPOLYGON,{})", + "ST_CollectionExtract(ST_MakeValid(ST_Multi(ST_Buffer(ST_SnapToGrid({}, {}), 0.0))),3)::geometry(MULTIPOLYGON,{})", geom_expr, layer.tolerance(zoom), layer_srid diff --git a/t-rex-core/src/datasource/postgis_test.rs b/t-rex-core/src/datasource/postgis_test.rs index b8fe3dd8..6e94326e 100644 --- a/t-rex-core/src/datasource/postgis_test.rs +++ b/t-rex-core/src/datasource/postgis_test.rs @@ -181,7 +181,7 @@ fn test_feature_query() { layer.simplify = true; layer.tolerance = "!pixel_width!/2".to_string(); assert_eq!(pg.build_query(&layer, 3857, 10, None).unwrap().sql, - "SELECT COALESCE(ST_MakeValid(ST_SnapToGrid(ST_Multi(geometry), $5::FLOAT8/2)),ST_GeomFromText(\'MULTIPOLYGON EMPTY\',3857))::geometry(MULTIPOLYGON,3857) AS geometry FROM osm_place_point WHERE geometry && ST_MakeEnvelope($1,$2,$3,$4,3857)"); + "SELECT ST_CollectionExtract(ST_MakeValid(ST_Multi(ST_Buffer(ST_SnapToGrid(ST_Multi(geometry), $5::FLOAT8/2), 0.0))),3)::geometry(MULTIPOLYGON,3857) AS geometry FROM osm_place_point WHERE geometry && ST_MakeEnvelope($1,$2,$3,$4,3857)"); layer.geometry_type = Some("LINESTRING".to_string()); assert_eq!(pg.build_query(&layer, 3857, 10, None).unwrap().sql, "SELECT ST_Multi(ST_SimplifyPreserveTopology(ST_Multi(geometry),$5::FLOAT8/2)) AS geometry FROM osm_place_point WHERE geometry && ST_MakeEnvelope($1,$2,$3,$4,3857)");