Skip to content

Commit

Permalink
Segementize bbox when reprojecting and intersect points
Browse files Browse the repository at this point in the history
  • Loading branch information
pka committed Nov 11, 2021
1 parent bc7ecf7 commit 0754098
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions t-rex-core/src/datasource/postgis_ds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl PostgisDatasource {
"POLYGON" | "MULTIPOLYGON" | "CURVEPOLYGON" => {
geom_expr = format!("ST_Buffer(ST_Intersection({},!bbox!), 0.0)", valid_geom);
}
"POINT" => {
"POINT" if layer_srid == grid_srid => {
// ST_Intersection not necessary - bbox query in WHERE clause is sufficient
}
_ => {
Expand Down Expand Up @@ -423,7 +423,10 @@ impl PostgisDatasource {
}
}
if layer_srid > 0 && layer_srid != env_srid && !layer.no_transform {
expr = format!("ST_Transform({},{})", expr, layer_srid);
expr = format!(
"ST_Transform(ST_Segmentize({}, ($3-$1)/512), {})",
expr, layer_srid
);
}
// Clip bbox to maximal extent of SRID
if layer.shift_longitude {
Expand Down
6 changes: 3 additions & 3 deletions t-rex-core/src/datasource/postgis_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,20 @@ fn test_feature_query() {
// reprojection
layer.srid = Some(2056);
assert_eq!(pg.build_query(&layer, 3857, 10, None).unwrap().sql,
"SELECT ST_Transform(geometry,3857) AS geometry FROM osm_place_point WHERE geometry && ST_Transform(ST_MakeEnvelope($1,$2,$3,$4,3857),2056)");
"SELECT ST_Transform(geometry,3857) AS geometry FROM osm_place_point WHERE geometry && ST_Transform(ST_Segmentize(ST_MakeEnvelope($1,$2,$3,$4,3857), ($3-$1)/512), 2056)");
layer.no_transform = true;
assert_eq!(pg.build_query(&layer, 3857, 10, None).unwrap().sql,
"SELECT ST_SetSRID(geometry,3857) AS geometry FROM osm_place_point WHERE geometry && ST_MakeEnvelope($1,$2,$3,$4,2056)");
layer.no_transform = false;
layer.srid = Some(4326);
assert_eq!(
pg.build_query(&layer, 3857, 10, None).unwrap().sql,
"SELECT ST_Transform(geometry,3857) AS geometry FROM osm_place_point WHERE geometry && ST_Transform(ST_MakeEnvelope($1,$2,$3,$4,3857),4326)"
"SELECT ST_Transform(geometry,3857) AS geometry FROM osm_place_point WHERE geometry && ST_Transform(ST_Segmentize(ST_MakeEnvelope($1,$2,$3,$4,3857), ($3-$1)/512), 4326)"
);
layer.shift_longitude = true;
assert_eq!(
pg.build_query(&layer, 3857, 10, None).unwrap().sql,
"SELECT ST_Transform(geometry,3857) AS geometry FROM osm_place_point WHERE geometry && ST_Shift_Longitude(ST_Transform(ST_MakeEnvelope($1,$2,$3,$4,3857),4326))"
"SELECT ST_Transform(geometry,3857) AS geometry FROM osm_place_point WHERE geometry && ST_Shift_Longitude(ST_Transform(ST_Segmentize(ST_MakeEnvelope($1,$2,$3,$4,3857), ($3-$1)/512), 4326))"
);
layer.shift_longitude = false;
layer.srid = Some(-1);
Expand Down

0 comments on commit 0754098

Please sign in to comment.