changeset 2514:79f4a20e31c2

Introduce distance limit up to which axis linestrings are connected Before, e.g. a linestring representing a tributary with its mouth in the middle of another linestring, had been connected to the end of the latter.
author Tom Gottfried <tom@intevation.de>
date Tue, 05 Mar 2019 15:44:05 +0100
parents e958104be9a9
children ac61c250337b e199655809c1
files schema/isrs_functions.sql schema/tap_tests_data.sql
diffstat 2 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/schema/isrs_functions.sql	Tue Mar 05 09:59:06 2019 +0100
+++ b/schema/isrs_functions.sql	Tue Mar 05 15:44:05 2019 +0100
@@ -25,7 +25,11 @@
 -- Uses the table waterway.distance_marks_virtual to map ISRS location codes
 -- to their geo-location.
 -- Distance marks are assumed to be near the axis.
-CREATE OR REPLACE FUNCTION ISRSrange_axis(stretch isrsrange) RETURNS geometry
+CREATE OR REPLACE FUNCTION ISRSrange_axis(
+    stretch isrsrange,
+    tolerance float
+    -- in m, up to which linestrings will be connected at their boundary
+) RETURNS geometry
 AS $$
     WITH RECURSIVE
         -- Get coordinates of location codes
@@ -76,6 +80,8 @@
                     (SELECT ST_Collect(points.geom) AS pts
                         FROM points) AS points
                 WHERE id <> ALL(refids)
+                    AND ST_DWithin(
+                        ST_Boundary(refgeom), ST_Boundary(geom), tolerance)
                     AND NOT ST_Covers(ST_Buffer(refgeom, 0.0001), points.pts)
                 ORDER BY ST_Distance(ST_Boundary(refgeom), ST_Boundary(geom))
                 FETCH FIRST ROW ONLY)),
@@ -118,7 +124,7 @@
 AS $$
     WITH
         axis_substring AS (
-            SELECT ISRSrange_axis(stretch) AS line),
+            SELECT ISRSrange_axis(stretch, 5) AS line),
         utm_zone AS (
             SELECT best_utm(stretch) AS z),
         area_subset AS (
--- a/schema/tap_tests_data.sql	Tue Mar 05 09:59:06 2019 +0100
+++ b/schema/tap_tests_data.sql	Tue Mar 05 15:44:05 2019 +0100
@@ -94,7 +94,7 @@
     ST_SetSRID('LINESTRING(0.5 0.5, 1 1)'::geometry, 4326),
     'testriver'
 ), (
-    ST_SetSRID('LINESTRING(1.5 0.1, 2 0)'::geometry, 4326),
+    ST_SetSRID('LINESTRING(1.5 0.00001, 2 0)'::geometry, 4326),
     'testriver'
 );