1

I am trying to remove sliver polygons under a certain area. I need to do this in a stand alone Python script, and not from within the GUI.

Is this possible? In standalone python I was trying a piece of code base on processing.run("qgis:eliminateselectedpolygons",\

but that is not available from an external script. Eliminate works great if I'm in the GUI.

3
  • Are you looking for an automated way to detect and remove sliver polygons, or just remove polygons/records that you've already identified? – Ryan Dec 23 '19 at 19:04
  • I want to remove polygons that I identify. Using a combination of area of the polygon combined with another value. ie area < 10000 and forested = 'no' – Mark McGirr Dec 24 '19 at 18:40
  • I need these 'selected' polygons to be merged with other polygons. Not to just be deleted holes. It looked like 'eliminate' worked in earlier QgisV2 versions, but it does not seem to be accessable outside the GUI in Ver3 – Mark McGirr Dec 24 '19 at 19:06
0

For working with spatial data outside of QGIS, I recommend GeoPandas. Not sure exactly how your data is stored (DB vs. files,) but here is an example of reading in a shapefile, selecting data to keep, and then saving results:

import geopandas as gpd

# Read in data
df = gpd.read_file('example.shp')
# Select data to keep
df_keep = df[(df.area >= 10000) & (df.forested != 'no')]
# Save data
df_keep.to_file('example-keep.shp')

Not the answer you're looking for? Browse other questions tagged or ask your own question.