alex_bn_lee

导航

[992] Remove holes within polygons in a shapefile

To remove holes within polygons in a shapefile, you can use the geopandas library in Python. Here's how you can do it:

import geopandas as gpd

# Read the shapefile
gdf = gpd.read_file('path_to_shapefile.shp')

# Remove holes within polygons
gdf['geometry'] = gdf['geometry'].apply(lambda x: x.exterior)

# Save the modified GeoDataFrame to a new shapefile
gdf.to_file('path_to_output_shapefile.shp')

In this code:

  • Replace 'path_to_shapefile.shp' with the path to your input shapefile.
  • The gdf['geometry'].apply(lambda x: x.exterior) line removes the interior rings (holes) from each polygon in the GeoDataFrame. It keeps only the exterior boundary of each polygon.
  • The modified GeoDataFrame is then saved to a new shapefile using to_file() function.

Make sure to replace 'path_to_output_shapefile.shp' with the desired path for the output shapefile. This process will remove the holes within the polygons of your shapefile and save the modified shapefile with the holes removed.


In ArcGIS Pro, you can remove holes within polygons using the "Eliminate Polygon Part" tool. Here's how you can do it:

  1. Open ArcGIS Pro and add your shapefile to the map.

  2. In the Catalog pane, navigate to the toolboxes and find the "Data Management Tools" toolbox.

  3. Expand the "Features" toolbox and then double-click on "Eliminate Polygon Part" tool to open it.

  4. In the "Eliminate Polygon Part" tool dialog, select your input shapefile as the "Input Features".

  5. Specify an output location and name for the modified shapefile in the "Output Feature Class" field.

  6. Choose the appropriate elimination method. For removing holes within polygons, select the "DELETE_PART" method.

  7. Optionally, you can set additional parameters such as the selection criteria and XY tolerance.

  8. Click on the "Run" button to execute the tool.

  9. Once the tool finishes running, you will see a new shapefile created with the holes removed.

By following these steps, you can easily remove holes within polygons in ArcGIS Pro using the "Eliminate Polygon Part" tool.


In QGIS, you can remove holes within polygons using the "Delete Holes" tool. Here's how you can do it:

  1. Open QGIS and load your shapefile into the project.

  2. In the QGIS toolbar, go to Vector > Geometry Tools > Delete Holes.

  3. In the "Delete Holes" dialog box, select your input shapefile as the "Input layer".

  4. Specify an output location and name for the modified shapefile in the "Output shapefile" field.

  5. Click on the "Run" button to execute the tool.

  6. Once the tool finishes running, you will see a new shapefile created with the holes removed.

By following these steps, you can easily remove holes within polygons in QGIS using the "Delete Holes" tool.

posted on 2024-05-06 13:22  McDelfino  阅读(16)  评论(0编辑  收藏  举报