[postgis-users] Problems with GeomUnion

Bill Binko bill at binko.net
Fri Apr 8 08:08:59 PDT 2005


On Thu, 7 Apr 2005, Martin Davis wrote:

> > Now I need a way to fix self-intersecting shapes.  
> 
> If you do a buffer(0) on the shapes as you load them (or after you load
> them), that will convert them to valid geometry while preserving their
> outline.
> 

I'm having some issues with that solution (and I was very excited to hear 
such a simple one!).  When I run this:

update parcels set parcel_shape = buffer(parcel_shape, 0);

I get:

ERROR:  new row for relation "parcels" violates check constraint "enforce_geotype_parcelShape"

that constraint looks like:

Check constraints:
    "enforce_dims_parcelShape" CHECK (ndims(parcel_shape) = 2)

I thought I'd check which ones weren't of dimension 2, so I ran:

SELECT oid from parcels where ndims(buffer(parcel_shape, 0)) != 2)

That gives me:

NOTICE:  IllegalArgumentException: points must form a closed linestring
NOTICE:  IllegalArgumentException: geometries must not contain null elements

ERROR:  POSTGIS2GEOS conversion failed

So, obviously, I have some real issues in this data.

I thought I might get to the bottom of it with this query:

gis=# select oid from (select oid, isvalid(buffer(parcel_shape, 0)) as valid from parcels) as foo where valid = false;

But I got:

ERROR:  invalid memory alloc request size 0

That can't be good. :-(

Anyway, I'm still plugging at it, so any help is fabulous.


> > I wonder why I didn't get errors when loading the shapefiles into the
> database!
> 
> Shapefiles are notoriously tolerant of invalid geometry topology.  For
> different reasons, so is PostGIS.  Sometimes it's nice to be able to
> load invalid geometry and then clean it up in a subsequent step.  If
> PostGIS refused to load your bad shape, you might have no way of knowing
> what the bad linework was or what the error was.
> 

Understood: I'll just have to learn how to clean it up :)

Bill



More information about the postgis-users mailing list