Point-to-line conversion

Initially presented in Conversions from points to lines: which methods? (published 2010-11-12) and Conversione da punti a linee: come? (published 2010-11-09).

Aim

This Python script converts a point shapefile to a line shapefile. Points are assigned to a specific line based on a common numeric identifier. For each line, the algorithm first removes duplicated points and then creates a distance matrix storing the distances between each point pair. It assumes line extremes are represented by the pair having the largest distance and picks the first point of this pair as the initial point of a new line. Starting from this point, a line is created by repetitively adding the nearest point to each previously selected point.

This script was created due to the need of converting point data for which the available tools in GIS software were not effective because of duplicated points and unpredictable point sequences. This version is still experimental and should be applied only to linear features with a simple, almost straight geometry. While successfully working in some practical cases, its results cannot guaranteed to be correct in general cases.

Implementation

Language: Python 2.6
Version: 2010-11-08
Source: pt2line_05.py

Required Python modules are numpy and ogr. The script was created using Python(x,y), which already incorporates these modules. The FWTools software has the older Numeric module instead of the recent numpy. Therefore, the script should not work in FWTools, or you should modify from numpy to Numeric terminology. Other Python distributions with numpy ogr and could work without problems.

Created and tested with Python(x,y) 2.6.5.1 under Windows Vista.

Program input

The input is a point shapefile with an integer field representing line identifiers.
The script run from the shell using the following command line:
   python pt2line_05.py par.txt
where pt2line_05.py is the script name and par.txt is the text file that contains required parameters. An example of a parameter file content is:
   flt_pts.shp #name of the input point shapefile
   flt_lines.shp #name of the output line shapefile
   flt_id #numeric identifier of each line

Program output

The output data consists of a line shapefile. Apart from the id field, a field stores the number of points that consitute each created line.

Example

The Python script was used to successfully convert a set of points representing faults in the Valnerina zone near Piedipaterno (Umbria, Italy). The below figures illustrate the data set prior and after conversion by the script. The geometry of converted lines is quite simple and this explains the success of the algorithm. Data and code can be freely downloaded.

Points representing faults in Valnerina zone (Umbria, Italy)
Fault data in Valnerina zone, represented by a point shapefile.


Lines representing faults in Valnerina zone (Umbria, Italy)
The same data, converted into a line shapefile by the script.

About

My name is Mauro Alberti. I'm a Gis and scientific programmer. My primary specializations are in scientific and GIS programming (OS tools, mainly Python, R, Fortran and C++), Earth Sciences (structural geology, Polar Sciences), geostatistical analysis. About me

Contact

Mauro Alberti

alberti.m65@gmail.com

mobile: +39 338 8022247
skype: mauro.alberti.siena
Address: Via Canonica 32,
Milano (MI) 20100, Italy

P.I. 01292740527