Mercurial > gemma
diff schema/tap_tests_data.sql @ 2398:8481e6266691
Fix corner case in area generation from stretch
In case orthogonal lines of arbitrary length at the ends of the axis between
two given distance marks cross the axis (e.g. because it describes a tight
turn), the result of ST_Buffer with endcap=flat is not well defined. Test
data have been amended to include such a case as well as appropriate data
to test correctness of a fix.
The fix includes construction of the afore mentioned orthogonal lines,
splitting the given area by these lines and constructing the end result
from those parts of the splitted area that intersect with the clipped axis.
Due to numerical inaccuracy, the parts might overlap slightly and
eventually cross the clipped axis where they should only touch. Therefore,
a small buffer was introduced before testing intersection and intersecting
parts are dissolved using ST_Union (which is necessary to revert splits
inside the resulting polygon anyhow).
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Wed, 27 Feb 2019 18:00:35 +0100 |
parents | 99274fed6f3d |
children | 4c16f5ad1905 |
line wrap: on
line diff
--- a/schema/tap_tests_data.sql Wed Feb 27 16:26:15 2019 +0100 +++ b/schema/tap_tests_data.sql Wed Feb 27 18:00:35 2019 +0100 @@ -80,7 +80,12 @@ INSERT INTO waterway.waterway_axis (wtwaxs, objnam) VALUES ( ST_SetSRID(ST_CurveToLine( - 'CIRCULARSTRING(0 0, 0.5 0.5, 1 0, 1.5 -0.2, 2 0)'::geometry), + 'CIRCULARSTRING(0 0, 0.5 0.5, 0.6 0.4)'), + 4326), + 'testriver' +), ( + ST_SetSRID(ST_CurveToLine( + 'CIRCULARSTRING(0.6 0.4, 1 0, 2 0)'), 4326), 'testriver' ), ( @@ -88,6 +93,24 @@ 'testriver' ); +-- Simulate waterway area as non-intersecting buffers around axis +WITH RECURSIVE +buffer AS ( + SELECT id, ST_Buffer(wtwaxs, 10000, 'endcap=flat')::geometry AS buf + FROM waterway.waterway_axis), +cleaned AS ( + (SELECT ARRAY[id] AS ids, buf AS cbuf, buf AS others + FROM buffer ORDER BY id FETCH FIRST ROW ONLY) + UNION + (SELECT ids || id, + ST_Difference(buf, others), + ST_Union(buf, others) + FROM cleaned, buffer + WHERE id <> ALL(ids) + ORDER BY id ASC, ids DESC + FETCH FIRST ROW ONLY)) +INSERT INTO waterway.waterway_area (area) SELECT cbuf FROM cleaned; + INSERT INTO users.templates (template_name, country, template_data) VALUES ('AT', 'AT', '\x'), ('RO', 'RO', '\x');