[postgis-users] Union of topologies (request for comment)

Christopher Mutel cmutel at gmail.com
Thu Oct 30 03:15:49 PDT 2014


After some work, I came up with the following, which is probably ugly
for those who actually know SQL; but it seems to work, and is quicker
and makes me feel safer than casting to geometry and back:

CREATE OR REPLACE FUNCTION PolygonTopoUnion(topo varchar, layer int,
topo1 topogeometry, topo2 topogeometry)
RETURNS topogeometry as $$
  SELECT CreateTopoGeom(topo, 3, layer, TopoElementArray_Agg(t2.element)) from (
      select distinct element from (
          (select GetTopoGeomElements(topo1) as element) union
          (select GetTopoGeomElements(topo2) as element)
      ) as t1
      order by t1.element  -- Not really necessary, but helpful in
testing correctness
  ) as t2
$$ language 'sql' volatile;

Note that this only applies to [multi]polygons (type 3), as I am
already at the limit of my capabilities.

I would appreciate any feedback or criticism.

Yours,
-Chris

On 13 October 2014 18:29, Christopher Mutel <cmutel at gmail.com> wrote:
> Dear all-
>
> Is there a way to create a new topology geometry as the union of two
> existing topology geometries without casting to a normal geometry and
> back? I have tried to write queries merging two TopoElementArrays, and
> then use CreateTopoGeom, but so far without success.
>
> Any help would be greatly appreciated.
>
> Yours,
> Chris
>
> --
> ############################
> Chris Mutel
> Technology Assessment Group, LEA
> Paul Scherrer Institut
> OHSA D22
> 5232 Villigen PSI
> Switzerland
> http://chris.mutel.org
> Telefon: +41 56 310 5787
> ############################



-- 
############################
Chris Mutel
Technology Assessment Group, LEA
Paul Scherrer Institut
OHSA D22
5232 Villigen PSI
Switzerland
http://chris.mutel.org
Telefon: +41 56 310 5787
############################


More information about the postgis-users mailing list