[GIS] How to use OGR Simplify in Python

ogrpython-2.7simplify

I am trying to simplify several polygons part of one shapefile using Python and OGR. However, I am stuck with how to use the simplify function as mentioned in the documentation:

http://www.gdal.org/classOGRGeometry.html#a0f4d7948332d9efd6548e1cf87bb6c8f

I tried this, for example:

data = ogr.Simplify(inData)

But then I get an AttributeError:

'module' object has no attribute 'Simplify'

Any tips?

Best Answer

If you look at the link you provided, you will see that Simplify is a method of the OGRGeometry class. In Python, Simplify is a method (member-function) of ogr.Geometry.

OGRGeometry * OGRGeometry::Simplify ( double  dTolerance ) const


#! /usr/bin/python
import ogr

shp = ogr.Open('input.shp', 0)
lyr = shp.GetLayer()
feat = lyr.GetFeature(0)
geom = feat.geometry()
simple = geom.Simplify(2.0)
Related Question