source: subversion/utils/srtm2osm/extractdata.pl @ 2191

Last change on this file since 2191 was 2125, checked in by enxrah, 13 years ago

srtm2osm a little utility to create contour lines in OSM format

  • Property svn:executable set to *
File size: 1.4 KB
RevLine 
[2125]1#!/usr/bin/perl
2
3open ASC, "$ARGV[0]";
4#open OUT, ">$ARGV[0]";
5
6for($i=0;$i<6;$i++){
7    $head[$i]=<ASC>;
8    chomp $head[$i];
9    $head[$i]=~s/[a-zA-Z_]//g;
10}
11
12$ncols = $head[0];
13$nrows = $head[1];
14$xllcorner = $head[2];
15$yllcorner = $head[3];
16$cellsize = $head[4];
17$NULL = $head[5];
18
19#$newxllcorner = -2.4146;
20#$newyllcorner = 51.3526;
21#$newxtrcorner = -2.3171;
22#$newytrcorner = 51.4089;
23
24$newxllcorner = $ARGV[2];
25$newyllcorner = $ARGV[1];
26$newxtrcorner = $ARGV[4];
27$newytrcorner = $ARGV[3];
28
29$firstcol = int(($newxllcorner-$xllcorner)/$cellsize);
30$lastcol = int(($newxtrcorner-$xllcorner)/$cellsize);
31$firstrow = $nrows - int(($newytrcorner-$yllcorner)/$cellsize);
32$lastrow = $nrows - int(($newyllcorner-$yllcorner)/$cellsize);
33$newncols = $lastcol - $firstcol;
34$newnrows = $lastrow - $firstrow;
35$newxllcorner = $xllcorner + $firstcol * $cellsize;
36$newyllcorner = $yllcorner + ($nrows-$lastrow) * $cellsize;
37
38print STDERR "Extracting columns $firstcol-$lastcol from rows $firstrow-$lastrow\n";
39
40print 
41"ncols\t$newncols
42nrows\t$newnrows
43xllcorner\t$newxllcorner
44yllcorner\t$newyllcorner
45cellsise$cellsize
46NODATA_value$NULL
47";
48
49for($i=0;$i<=$lastrow;$i++){
50    $line=<ASC>;
51    if($i>=$firstrow){
52        chomp $line;
53        @d = split(" ", $line);
54        for($j=$firstcol;$j<$lastcol;$j++){
55            print "$d[$j] ";
56        }
57        print "\n";
58    }
59}
60
61sub coord {
62    $lon = $xllcorner+$cellsize*$_[1];
63    $lat = $yllcorner+$cellsize*($nrows-$_[0]);
64    return "$lat, $lon\n";
65}
Note: See TracBrowser for help on using the repository browser.