[postgis-users] Cleaning non valid multipolygon
Simon Greener
simon at spatialdbadvisor.com
Mon Feb 2 22:19:58 PST 2009
Yves,
I don't know if this helps. In Oracle, to fix self-intersecting polygons one can do a "self-union".
I looked to see if this would work for PostGIS and, from what I can tell from my simple testing, it does:
drop table crap;
create table crap (oid serial);
SELECT AddGeometryColumn('public', 'crap', 'geom', -1, 'MULTIPOLYGON', 2);
alter TABLE crap DROP CONSTRAINT enforce_geotype_geom;
alter TABLE crap ADD CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) IN ('MULTIPOLYGON'::text,'POLYGON'::text) OR geom IS NULL);
insert into crap (geom) values(st_geomfromtext('MULTIPOLYGON(((
376249.7830234 8717655.6050357,
376268.0818048 8717666.0116082,
376265.2666038 8717670.5117466,
376247.812391 8717660.3864341,
376249.7830234 8717655.6050357,
376247.812391 8717660.3864341,
376265.2666038 8717670.5117466,
376268.0818048 8717666.0116082,
376249.7830234 8717655.6050357)))'));
insert into crap (geom)
select ST_AsText(st_makepolygon(st_linemerge(st_union(geom,geom))))
from (select st_geomfromtext('MULTIPOLYGON(((
376249.7830234 8717655.6050357,
376268.0818048 8717666.0116082,
376265.2666038 8717670.5117466,
376247.812391 8717660.3864341,
376249.7830234 8717655.6050357,
376247.812391 8717660.3864341,
376265.2666038 8717670.5117466,
376268.0818048 8717666.0116082,
376249.7830234 8717655.6050357)))') as geom) as a;
This may help. But I am sure more experienced experts have a better solution.
S
On Tue, 03 Feb 2009 06:00:18 +1100, Yves Moisan <yves.moisan at boreal-is.com> wrote:
> Hi All,
>
> I have some data from an AutoCAD file (dwg) for which some of the
> multipolygon elements are not valid geometries. The pattern is pretty
> simple : some polygons display the origin vertex 3 times as though one
> started digitizing going clockwise to close the polygon and then came
> back counterclockwise not necessarily exactly on the same vertices and
> closed again. An example :
>
> "MULTIPOLYGON(((
> 376249.7830234 8717655.6050357,
> 376268.0818048 8717666.0116082,
> 376265.2666038 8717670.5117466,
> 376247.812391 8717660.3864341,
> 376249.7830234 8717655.6050357,
> 376247.812391 8717660.3864341,
> 376265.2666038 8717670.5117466,
> 376268.0818048 8717666.0116082,
> 376249.7830234 8717655.6050357)))"
>
> Deleting the last 4 lines on that geometry and shoving it back in does
> the job. I tried to find an automated way of doing this (buffer,
> st_geometry ...) and but didn't find anything. Any pointer to an
> automated way of doing that, short of writing my own function, which I
> would need pointers for examples too :-),
>
> TIA,
>
> Yves Moisan
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
--
SpatialDB Advice and Design, Solutions Architecture and Programming,
Oracle Database 10g Administrator Certified Associate; Oracle Database 10g SQL Certified Professional
Oracle Spatial, SQL Server, PostGIS, MySQL, ArcSDE, Manifold GIS, Radius Topology and Studio Specialist.
39 Cliff View Drive, Allens Rivulet, 7150, Tasmania, Australia.
Website: www.spatialdbadvisor.com
Email: simon at spatialdbadvisor.com
Voice: +613 9016 3910
Mobile: +61 418 396391
Skype: sggreener
Longitude: 147.20515 (147° 12' 18" E)
Latitude: -43.01530 (43° 00' 55" S)
NAC:W80CK 7SWP3
More information about the postgis-users
mailing list