[gdal-dev] validate/clean geometry with OGR?

Stephen Woodbridge woodbri at swoodbridge.com
Wed Apr 27 10:55:06 EDT 2011


On 4/27/2011 10:36 AM, Elijah Robison wrote:
> Hey devs, is anyone aware of an OGR approach to validate/clean
> geometries, for instance, as they are being converted from SHP to
> PostGRESql?
> It's not uncommon to have a handful of invalid geometries (usually
> self-intersecting polygons) in a parcel dataset, and it's impractical to
> correct them manually. In most situations I use the "Clean Geometries"
> function in ArcGIS, which does fix the problem. However this one
> functionality is my main reason to retain Arc in my primary tool chain.
>
> I've never found a scripting approach by trolling the search engines so
> I thought I'd ask here.

This would be an interesting tool and you might want to check the 
postgis list as I think there have been some tools posted there to clean 
check tables in the database.

Since I use the shp2pgsql data loader, my standard check and clean is:

update mytable set the_geom=buffer(the_geom, 0.0) where not 
isvalid(the_geom);

-- at this point anything that is not valid probably need to be looked
-- at or needs something like a dump the polygon as line segments and
-- then st_build_area() on the line segments.

select count(*) from mytable where not isvalid(the_geom);
select gid from mytable where not isvalid(the_geom);

But this is all postgis related and not GEOS related, but you might be 
able to do the same thing directly in GEOS if you know what strategies 
work in postgis.

-Steve W


More information about the gdal-dev mailing list