Skip to content

Commit

Permalink
Apply ST_Buffer on ST_SnapToGrid output to fix exception in ST_MakeValid
Browse files Browse the repository at this point in the history
  • Loading branch information
pka committed Dec 6, 2020
1 parent 248dfc5 commit f9548e0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion t-rex-core/src/datasource/postgis_ds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion t-rex-core/src/datasource/postgis_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down

0 comments on commit f9548e0

Please sign in to comment.