Monday, March 14, 2011

Removing holes from a polygon with gvSIG

I wanted to simplify a polygon of a LiDAR flight coverage strip by removing all the holes (inner polygons in gvSIG terminology) within the polygon. I could not find a ready function other than the Delete Vertex command. Using this would be very tedious for hundreds of holes. So I thought of using gvSIG's Geoprocessing Tools to do the job. The idea is (1) to decompose the polygon and its holes into lines, (2) to remove all the short lines except the longest line and optionally to simplify the line work, and (3)  to make a polygon from the remaining line.

Decompose the Polygon into Lines
  1. Start up gvSIG OADE 2010. Add a polygon with holes layer e.g. polygonholes.shp to the view.

  2. Select View | Geoprocessing Tools.

    The Geoprocessing tools dialog box appears.

  3. Expand the Geoprocessing tools node and select Topology | Reduce to lines.
  4. Click Open Tool.

    The Analysis tools dialog box appears.
  5. In the Input layer field, choose the polygon with holes layer e.g. polygonholes.shp.
  6. Click Choose and type in the name of the Output layer e.g. lines.shp.
  7. Click OK.

    The polygon and holes are reduced to lines in the output layer lines.shp.
Find and remove short lines
  1. In the legend (or table of contents in gvSIG terminology) pane, click the decomposed lines layer, e.g. lines.shp.

    The selected layer becomes the active layer.
  2. Select Layer | Start Editing.



    The layer name changes to bold red in the legend, and the console pane appears.
  3. Select Layer | Add Geometry Info.


    The Add geometry info dialog box appears.
  4. In the Select geometry information group box, select Length. Click the > button. Click OK.

    The length attribute field is created for the lines.shp layer.
  5. Select Layer | Show attribute table.

    The Table: Attribute table for lines.shp dialog box appears.
  6. Click the Length column header.
  7. Select Table | Sort descending.

    The table is sorted with the longest length in the first row.
  8. Select the second row. Scroll to the last row. Press SHIFT and click the last row.

    All the rows between the second row to the last row are selected.
  9. Press Delete on the keyboard.

    All the selected records are deleted.
  10. Close the table. Select Layer | Stop editing.

    The Save prompt message appears.
  11. Click Yes.

    The changes are saved.


Simplify the line work

  1. Select View | Geoprocessing tools.

    The Geoprocessing tools dialog box appears.
  2. Expand the Geoprocessing tools node. Select Computational Data conversion | Generalize.
  3. Click Open tool.

    The Analysis tools dialog box appears.
  4. In the Input layer field, select lines.shp.
  5. Toggle on Douglas-Peucker method.
  6. In the Distance tolerance field, type in a value e.g. 20.
  7. In the Output layer field, type in the path and name of the output file, e.g. c:\temp\generalize.shp.
  8. Click OK.

    The generalized line layer is created.
Convert the line work to a polygon
  1. Select View | Geoprocessing tools.

    The Geoprocessing tools dialog box appears.
  2. Expand the Geoprocessing tools node. Select Topology | Build polygons.

  3. Click Open tool.

    The Analysis tools dialog box appears.
  4. In the Input layer field, choose generalize.shp.
  5. In the Output layer field, choose or type in the path and name of the output layer e.g. C:\Temp\polygons.shp.
  6. Click OK.

    The polygon layer without holes is created.

No comments: