source: subversion/applications/utils/osm-extract/polygons/gpx2poly.pl

Last change on this file was 25032, checked in by rodo, 8 years ago

New script to create a polygon file from a gpx file.

  • Property svn:executable set to *
File size: 797 bytes
Line 
1#!/usr/bin/perl
2
3# script to convert a GPX file to a polygon file.
4#
5# written by Rodolphe Quiédeville <rodolphe@quiedeville.org>, GPL.
6# Most parts of code inspired from osm2poly.py by Frederik Ramm <frederik@remote.org>
7# GPX Files for relations could be obtained from http://ra.osmsurround.org/analyze.jsp
8#
9
10use strict;
11
12my $poly_id = -1;
13my $poly_file;
14my $polybuf;
15my $outbuf;
16my $id=0;
17
18while(<>) 
19{
20    if (/^\s*<trkpt.*\slon=["']([0-9.eE-]+)["'] lat=["']([0-9.eE-]+)["']/)
21    {
22        $polybuf .= sprintf "\t%f\t%f\n", $1,$2;
23    } 
24    elsif (/^\s*<trk>/) 
25    {
26        $polybuf = "";
27        $poly_id++;
28    }
29    elsif (/^\s*<\/trk>/) 
30    {
31        $outbuf .= "$poly_id\n$polybuf"."END\n";
32    }
33}
34
35$poly_file = "polygon" unless defined($poly_file);
36print "$poly_file\n$outbuf"."END\n";
Note: See TracBrowser for help on using the repository browser.