-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathdm2geojson
executable file
·61 lines (46 loc) · 901 Bytes
/
dm2geojson
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl
use strict;
print "{\n";
print "\"type\": \"FeatureCollection\",\n";
print "\"features\": [\n";
my $first = 1;
while (<>) {
my @lats = ();
my @lons = ();
my $meta = "";
while (s/^([0-9.-]+),([0-9.-]+) *//) {
push @lats, $1;
push @lons, $2;
}
if (/^[0-9]*:(-?[0-9.]+)/) {
$meta = $1;
}
if ($#lats >= 0) {
if ($first != 1) {
print ",\n";
}
$first = 0;
print "{ \"type\": \"Feature\", \"properties\": { ";
if ($meta ne "") {
print "\"meta\": $meta ";
}
print "}, \"geometry\": { ";
if ($#lats >= 1) {
print "\"type\": \"LineString\", \"coordinates\": [ ";
} else {
print "\"type\": \"Point\", \"coordinates\": ";
}
for (my $i = 0; $i <= $#lats; $i++) {
if ($i > 0) {
print ", ";
}
print "[ $lons[$i],$lats[$i] ]";
}
if ($#lats >= 1) {
print "] } }\n";
} else {
print "} }\n";
}
}
}
print "] }\n";