Line parsing


This script attempts to simplify the internal geometrical structure of a line shapefile. It can be applied to shapefile with features consisting of MultiLineString (i.e., what we see as a single line is in fact composed by one or more lines, even disconnected) in order to convert them to simpler LineString features (i.e. lines are really single, connected features).

Two elements of a MultiLineString feature will be joined if their vertices are within a threshold distance (set by the user). This script can also be useful for recovering line shapefiles containing corrupted line features (e.g., lines with zero length and so on). The number of unrecovered corrupted features is listed by the script at the end of the elaboration as unprocessed features.


Language: Python 2.6
Required modules: ogr, sys, os
Created and tested with: FWTools
Version: 2010-03-01
Developed with M. Radivojevic for the processing of Antarctic megadune traces.

Working within the FWTools shell, an example command line is:
python inputshape.shp outputshape.shp 20
where the last number represents the threshold distance (in the distance unit of the input shapefile, e.g., meters)

Program input

A line shapefile and the distance threshold to join disconnected lines within a MultiLineSTring.

Program output

A line shapefile with MultiLineStrings coverted to LineString when their elements have vertices within the distance threshold. Using for instance OpenJump you can check which features were not converted (i.e., they are still MultiLineStrings in the attribute table of the shapefile) and edit them manually.


Mauro Alberti