Skip to content

Instantly share code, notes, and snippets.

@caged
Created April 1, 2020 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caged/1e418bc5c048fed5ef2604a1902eb735 to your computer and use it in GitHub Desktop.
Save caged/1e418bc5c048fed5ef2604a1902eb735 to your computer and use it in GitHub Desktop.
WITH
bad_geometries AS (SELECT
(a.p_geom).path[1] AS path,
(a.p_geom).geom
FROM
(
SELECT
st_dump(shape) AS p_geom
FROM
us_district_court_jurisdictions
WHERE
fid = 57
) a),
good_geometries AS (
SELECT shape AS geom
FROM us_district_court_jurisdictions
WHERE
fid = 58
),
movable_polygon AS (SELECT * FROM bad_geometries WHERE path = 1),
retained_polygon AS (SELECT * FROM bad_geometries WHERE path = 2)
UPDATE us_district_court_jurisdictions set shape = CASE
WHEN fid = 58 THEN st_multi(st_union(shape, m.geom))
WHEN fid = 57 THEN st_multi(r.geom)
END
FROM movable_polygon m, retained_polygon r
WHERE fid IN (57, 58)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment