Hi Chris, On Thu, Oct 30, 2014 at 11:15:49AM +0100, Christopher Mutel wrote: > 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.
Your function is ok, as long as the two input TopoGeometry objects are in the same topology and the output layer type is compatible with the union of the input layer types. Should actually also work for any other combination of input types, for non-hierarchical TopoGeometries. --strk; _______________________________________________ postgis-users mailing list [email protected] http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
