source: subversion/applications/utils/import/srtm2osm/extractdata.pl @ 5763

Last change on this file since 5763 was 4582, checked in by joerg, 13 years ago

add small description to srtm2osm/extract

  • Property svn:executable set to *
File size: 2.0 KB
Line 
1#!/usr/bin/perl
2
3use Pod::Usage;
4
5if ( @ARGV < 5){
6    printf STDERR "Need Filename and 4 Corners to operate\n";
7    pod2usage(1);
8    exit 1;
9}
10
11open ASC, "$ARGV[0]";
12#open OUT, ">$ARGV[0]";
13
14for($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
46print STDERR "Extracting columns $firstcol-$lastcol from rows $firstrow-$lastrow\n";
47
48print 
49"ncols\t$newncols
50nrows\t$newnrows
51xllcorner\t$newxllcorner
52yllcorner\t$newyllcorner
53cellsise$cellsize
54NODATA_value$NULL
55";
56
57for($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
69sub 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
82B<extractdata> Version 0.05
83
84=head1 DESCRIPTION
85
86Extracting columns firstcol - lastcol from rows  firstrow - lastrow
87for srtm2osm
88
89=head1 SYNOPSIS
90
91B<Common usages:>
92
93extractdata <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
105http://www.openstreetmap.org/
106
107
108=cut
Note: See TracBrowser for help on using the repository browser.