[postgis-users] CleanGeometry plpgsql function

Dane Springmeyer blake at hailmail.net
Thu Sep 4 19:08:50 PDT 2008


Hi David,

I grabbed a copy previously and here it is:

-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
--  
-- $Id: cleanGeometry.sql 2008-04-24 10:30Z Dr. Horst Duester $
--
-- cleanGeometry - remove self- and ring-selfintersections from  
--                 input Polygon geometries  
-- http://www.sogis.ch
-- Copyright 2008 SO!GIS Koordination, Kanton Solothurn, Switzerland
-- Version 1.0
-- contact: horst dot duester at bd dot so dot ch
--
-- This is free software; you can redistribute and/or modify it under
-- the terms of the GNU General Public Licence. See the COPYING file.
-- This software is without any warrenty and you use it at your own risk
--   
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


CREATE OR REPLACE FUNCTION cleanGeometry(geometry)
   RETURNS geometry AS
$BODY$DECLARE
   inGeom ALIAS for $1;
   outGeom geometry;
   tmpLinestring geometry;
   tmpPolygon geometry;
   Pk geometry;
   Pi geometry;
   nGeometries integer;
   nGeom integer;
   intRingPi geometry;
   nIntRings integer;
   extRingPk geometry;
   isHole boolean;

Begin

   outGeom := NULL;

-- Clean Process for Polygon  
   IF (GeometryType(inGeom) = 'POLYGON' OR GeometryType(inGeom) =  
'MULTIPOLYGON') THEN

-- Only process if geometry is not valid, 
-- otherwise put out without change
     if not isValid(inGeom) THEN

-- create nodes at all self-intersecting lines by union the polygon  
boundaries
-- with the startingpoint of the boundary.  
       tmpLinestring :=  
st_union(st_multi(st_boundary(inGeom)),st_pointn(boundary(inGeom),1));
       outGeom = buildarea(tmpLinestring);
       RETURN st_multi(outGeom);
     else
       RETURN st_multi(inGeom);
     END IF;


------------------------------------------------------------------------------
-- Clean Process for LINESTRINGS, self-intersecting parts of  
linestrings 
-- will be divided into multiparts of the mentioned linestring 
------------------------------------------------------------------------------
   ELSIF (GeometryType(inGeom) = 'LINESTRING' OR GeometryType(inGeom)  
= 'MULTILINESTRING') THEN

-- create nodes at all self-intersecting lines by union the linestrings
-- with the startingpoint of the linestring.  
     outGeom := st_union(st_multi(inGeom),st_pointn(inGeom,1));
     RETURN outGeom;
   ELSE
     RAISE EXCEPTION 'The input type % is not  
supported',GeometryType(inGeom);
   END IF;	
End;$BODY$
   LANGUAGE 'plpgsql' VOLATILE;




On Sep 4, 2008, at 6:51 PM, David Jantzen wrote:

> Does anyone have a definition of cleanGeometry that they could post?
> The wiki page at
>
> http://postgis.refractions.net/support/wiki/index.php?full=geometry
>
> references the following unresponsive link:
>
> http://www.sogis1.so.ch/sogis/dl/postgis/cleanGeometry.sql
>
> Thanks,
> David
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users




More information about the postgis-users mailing list