I am new to GIS. I want to remove some smaller polygons and only leave the polygons with a larger areas in Python scripts. Like this:
Here is the source files Shape files: buildings. I am thinking whether I can set a threshold for the size of the areas then remove them, but I don't know how to do this in Python.
Using the help by @Iridium , then I am able to compute the area of the polygons by this link Calculate area of polygons using OGR in python script
from osgeo import ogr driver = ogr.GetDriverByName("ESRI Shapefile") dataSource = driver.Open(shapefile_to_be_used 1) layer = dataSource.GetLayer() new_field = ogr.FieldDefn("Area", ogr.OFTReal) new_field.SetWidth(32) new_field.SetPrecision(2) #added line to set precision layer.CreateField(new_field) for feature in layer: geom = feature.GetGeometryRef() area = geom.GetArea() print (area) feature.SetField("Area", area) layer.SetFeature(feature) dataSource = None
But how to filter out the polygons with small areas?