/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs

« back to all changes in this revision

Viewing changes to Methods/Mapping/scripts/srtm2osm/mkcntr.pl

  • Committer: Suren A. Chilingaryan
  • Date: 2009-04-09 03:21:08 UTC
  • Revision ID: csa@dside.dyndns.org-20090409032108-w4edamdh4adrgdu3
import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl 
 
2
 
 
3
open ASC, "$ARGV[0]";
 
4
 
 
5
for($i=0;$i<6;$i++){
 
6
    $head[$i]=<ASC>;
 
7
    chomp $head[$i];
 
8
    $head[$i]=~s/[a-zA-Z]//g;
 
9
}
 
10
 
 
11
$ncols = $head[0];
 
12
$nrows = $head[1];
 
13
$xllcorner = $head[2];
 
14
$yllcorner = $head[3];
 
15
$cellsize = $head[4];
 
16
$NULL = $head[5];
 
17
$l=$ARGV[1];
 
18
 
 
19
system("tail -n +7 $ARGV[0] > tmp");
 
20
print STDERR "Invoking gnuplot to generate contours at $l intervals\n";
 
21
open GNUPLOT, "|gnuplot";
 
22
print GNUPLOT "set terminal table
 
23
unset surface
 
24
set contour
 
25
set cntrparam level incremental -500, $l, 9000
 
26
set output 'tmp.cnt'
 
27
splot 'tmp' matrix w l
 
28
";
 
29
 
 
30
close GNUPLOT;
 
31
open CNT, "tmp.cnt";
 
32
 
 
33
$nid0 = 0;
 
34
$lastnode = 1000050000;
 
35
$lastway = 1000050000;
 
36
$prefix = "";
 
37
 
 
38
print "<?xml version='1.0' encoding='UTF-8'?>
 
39
<osm version='0.5' generator='mkcntr'>
 
40
<bound box='-90,-180,90,180' origin='mkcntr'/>
 
41
";
 
42
 
 
43
foreach (<CNT>){
 
44
    next if (/^\#/);
 
45
    if (/^[^0-9]*$/) {
 
46
        if($nid0 && $nid0!=$nidF){
 
47
            way($z, @nodes);
 
48
        }
 
49
        undef @nodes;
 
50
        $nid0 = 0;
 
51
        $nidF = 0;
 
52
        next;
 
53
    }
 
54
    chomp;
 
55
    ($i, $j, $z) = split;
 
56
    $nid1 = node($i, $j);
 
57
    if($nid0>0) {
 
58
        push @nodes, $nid1;
 
59
    } else {
 
60
        push @nodes, $nid1;
 
61
        $nidF = $nid1;
 
62
    }
 
63
    $nid0=$nid1;
 
64
}
 
65
 
 
66
print "</osm>\n";
 
67
 
 
68
sub node {
 
69
    $lon = $xllcorner+$cellsize*$_[0];
 
70
    $lat = $yllcorner+$cellsize*($nrows-$_[1]);
 
71
    $id = $lastnode++;
 
72
    print "<node id='$prefix$id' timestamp='0001-01-01T00:00:00' lat='$lat' lon='$lon' />\n";
 
73
    return $id;
 
74
}
 
75
 
 
76
sub way {
 
77
    $id = $lastway++;
 
78
    $z = shift @_;
 
79
    print "<way id='$prefix$id' timestamp='0001-01-01T00:00:00'>\n";
 
80
    while (@_){
 
81
        $s = shift(@_);
 
82
        print "<nd ref='$prefix$s' />\n";
 
83
    }
 
84
    print "<tag k='contour' v='elevation' />\n";
 
85
 
 
86
    if ($ARGV[2] && $ARGV[3]) {
 
87
        if ( $z % $ARGV[3] == 0 ) {
 
88
            print "<tag k='contour_ext' v='elevation_major'\n />";
 
89
        } else {
 
90
            if ( $z % $ARGV[2] == 0 ) {
 
91
                print "<tag k='contour_ext' v='elevation_medium'\n />";
 
92
            } else {
 
93
                print "<tag k='contour_ext' v='elevation_minor'\n />";
 
94
            }
 
95
        }
 
96
    }
 
97
 
 
98
    print "<tag k='ele' v='$z' />\n";
 
99
    print "<tag k='created_by' v='mkcntr' />\n";
 
100
    print "</way>\n";
 
101
    return $id;
 
102
    
 
103
}