/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/extractdata.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
use Pod::Usage;
 
4
 
 
5
if ( @ARGV < 5){
 
6
    printf STDERR "Need Filename and 4 Corners to operate\n";
 
7
    pod2usage(1);
 
8
    exit 1;
 
9
}
 
10
 
 
11
open ASC, "$ARGV[0]";
 
12
#open OUT, ">$ARGV[0]";
 
13
 
 
14
for($i=0;$i<6;$i++){
 
15
    $head[$i]=<ASC>;
 
16
    chomp $head[$i];
 
17
    $head[$i]=~s/[a-zA-Z_]//g;
 
18
}
 
19
 
 
20
$ncols = $head[0];
 
21
$nrows = $head[1];
 
22
$xllcorner = $head[2];
 
23
$yllcorner = $head[3];
 
24
$cellsize = $head[4];
 
25
$NULL = $head[5];
 
26
 
 
27
#$newxllcorner = -2.4146;
 
28
#$newyllcorner = 51.3526;
 
29
#$newxtrcorner = -2.3171;
 
30
#$newytrcorner = 51.4089;
 
31
 
 
32
$newxllcorner = $ARGV[2];
 
33
$newyllcorner = $ARGV[1];
 
34
$newxtrcorner = $ARGV[4];
 
35
$newytrcorner = $ARGV[3];
 
36
 
 
37
$firstcol = int(($newxllcorner-$xllcorner)/$cellsize);
 
38
$lastcol = int(($newxtrcorner-$xllcorner)/$cellsize);
 
39
$firstrow = $nrows - int(($newytrcorner-$yllcorner)/$cellsize);
 
40
$lastrow = $nrows - int(($newyllcorner-$yllcorner)/$cellsize);
 
41
$newncols = $lastcol - $firstcol;
 
42
$newnrows = $lastrow - $firstrow;
 
43
$newxllcorner = $xllcorner + $firstcol * $cellsize;
 
44
$newyllcorner = $yllcorner + ($nrows-$lastrow) * $cellsize;
 
45
 
 
46
print STDERR "Extracting columns $firstcol-$lastcol from rows $firstrow-$lastrow\n";
 
47
 
 
48
print 
 
49
"ncols\t$newncols
 
50
nrows\t$newnrows
 
51
xllcorner\t$newxllcorner
 
52
yllcorner\t$newyllcorner
 
53
cellsise$cellsize
 
54
NODATA_value$NULL
 
55
";
 
56
 
 
57
for($i=0;$i<=$lastrow;$i++){
 
58
    $line=<ASC>;
 
59
    if($i>=$firstrow){
 
60
        chomp $line;
 
61
        @d = split(" ", $line);
 
62
        for($j=$firstcol;$j<$lastcol;$j++){
 
63
            print "$d[$j] ";
 
64
        }
 
65
        print "\n";
 
66
    }
 
67
}
 
68
 
 
69
sub coord {
 
70
    $lon = $xllcorner+$cellsize*$_[1];
 
71
    $lat = $yllcorner+$cellsize*($nrows-$_[0]);
 
72
    return "$lat, $lon\n";
 
73
}
 
74
 
 
75
##################################################################
 
76
# Usage/manual
 
77
 
 
78
__END__
 
79
 
 
80
=head1 NAME
 
81
 
 
82
B<extractdata> Version 0.05
 
83
 
 
84
=head1 DESCRIPTION
 
85
 
 
86
Extracting columns firstcol - lastcol from rows  firstrow - lastrow
 
87
for srtm2osm
 
88
 
 
89
=head1 SYNOPSIS
 
90
 
 
91
B<Common usages:>
 
92
 
 
93
extractdata <filename> <y-ll-corner> <x-ll-corner> <y-tr-corner> <x-tr-corner>
 
94
 
 
95
=head1 COPYRIGHT
 
96
 
 
97
... please fill in
 
98
 
 
99
=head1 AUTHOR
 
100
 
 
101
... please fill in
 
102
 
 
103
=head1 SEE ALSO
 
104
 
 
105
http://www.openstreetmap.org/
 
106
 
 
107
 
 
108
=cut