Mercurial > gemma
changeset 2649:9b6a02923bb4
Allow sys_admin to import waterway axis and area without clipping
In passing, introduced an ST_Node in the axis import to repair non-simple
linestrings analogously to ST_MakeValid for the area.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 14 Mar 2019 14:37:28 +0100 |
parents | c52bf6f994c0 |
children | a308baa7e7af |
files | pkg/imports/wa.go pkg/imports/wx.go |
diffstat | 2 files changed, 32 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/imports/wa.go Thu Mar 14 14:07:25 2019 +0100 +++ b/pkg/imports/wa.go Thu Mar 14 14:37:28 2019 +0100 @@ -4,12 +4,13 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // License-Filename: LICENSES/AGPL-3.0.txt // -// Copyright (C) 2018 by via donau +// Copyright (C) 2018, 2019 by via donau // – Österreichische Wasserstraßen-Gesellschaft mbH // Software engineering by Intevation GmbH // // Author(s): // * Sascha L. Teichmann <sascha.teichmann@intevation.de> +// * Tom Gottfried <tom.gottfried@intevation.de> package imports @@ -82,9 +83,9 @@ WHERE country = users.current_user_country() ) DELETE FROM waterway.waterway_area -WHERE ST_Covers( - (SELECT a FROM resp), - ST_Transform(area::geometry, (SELECT t FROM resp))) +WHERE pg_has_role('sys_admin', 'MEMBER') + OR ST_Covers((SELECT a FROM resp), + ST_Transform(area::geometry, (SELECT t FROM resp))) ` insertWaterwayAreaSQL = ` WITH resp AS ( @@ -94,18 +95,17 @@ WHERE country = users.current_user_country() ) INSERT INTO waterway.waterway_area (area, catccl, dirimp) -SELECT ST_Transform(clipped.geom, 4326)::geography, $3, $4 FROM ( - SELECT (ST_Dump( - ST_Intersection( - (SELECT ST_Buffer(a, 0.0001) FROM resp), - ST_CollectionExtract(ST_MakeValid(ST_Transform( - ST_GeomFromWKB($1, $2::integer), - (SELECT t FROM resp) - )),3) - ) - )).geom AS geom - ) AS clipped - WHERE clipped.geom IS NOT NULL +SELECT ST_Transform(clipped.geom, 4326)::geography, $3, $4 + FROM resp, + ST_CollectionExtract(ST_MakeValid(ST_Transform( + ST_GeomFromWKB($1, $2::integer), t)), 3) AS new_area (new_area), + LATERAL (SELECT (ST_Dump( + CASE WHEN pg_has_role('sys_admin', 'MEMBER') + THEN new_area + ELSE ST_Intersection(a, new_area) + END + )).geom AS geom + ) AS clipped ` )
--- a/pkg/imports/wx.go Thu Mar 14 14:07:25 2019 +0100 +++ b/pkg/imports/wx.go Thu Mar 14 14:37:28 2019 +0100 @@ -4,12 +4,13 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // License-Filename: LICENSES/AGPL-3.0.txt // -// Copyright (C) 2018 by via donau +// Copyright (C) 2018, 2019 by via donau // – Österreichische Wasserstraßen-Gesellschaft mbH // Software engineering by Intevation GmbH // // Author(s): // * Sascha L. Teichmann <sascha.teichmann@intevation.de> +// * Tom Gottfried <tom.gottfried@intevation.de> package imports @@ -81,9 +82,9 @@ WHERE country = users.current_user_country() ) DELETE FROM waterway.waterway_axis -WHERE ST_Covers( - (SELECT a FROM resp), - ST_Transform(wtwaxs::geometry, (SELECT t FROM resp))) +WHERE pg_has_role('sys_admin', 'MEMBER') + OR ST_Covers((SELECT a FROM resp), + ST_Transform(wtwaxs::geometry, (SELECT t FROM resp))) ` insertWaterwayAxisSQL = ` @@ -94,18 +95,17 @@ WHERE country = users.current_user_country() ) INSERT INTO waterway.waterway_axis (wtwaxs, objnam, nobjnam) -SELECT ST_Transform(clipped.geom, 4326)::geography, $3, $4 FROM ( - SELECT (ST_Dump( - ST_Intersection( - (SELECT a FROM resp), - ST_Transform( - ST_GeomFromWKB($1, $2::integer), - (SELECT t FROM resp) - ) - ) - )).geom AS geom - ) AS clipped - WHERE clipped.geom IS NOT NULL +SELECT ST_Transform(clipped.geom, 4326)::geography, $3, $4 + FROM resp, + ST_Node(ST_Transform( + ST_GeomFromWKB($1, $2::integer), t)) AS new_line (new_line), + LATERAL (SELECT (ST_Dump( + CASE WHEN pg_has_role('sys_admin', 'MEMBER') + THEN new_line + ELSE ST_Intersection(a, new_line) + END + )).geom AS geom + ) AS clipped ` )