-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathheight
executable file
·112 lines (92 loc) · 2.42 KB
/
height
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env perl
use Data::Dumper;
use FindBin;
use lib "$FindBin::Bin/lib";
use Geo::Coordinates::OSGB qw(ll_to_grid grid_to_ll);
use Geo::Coordinates::OSTN02;
use Elevation;
use Getopt::Long;
use Carp;
$SIG{__DIE__} = sub { Carp::confess @_ };
my $help;
my $elevation_plugin;
BEGIN {
sub load_config
{
my( $file ) = @_;
my $return;
unless ($return = do $file) {
warn "couldn't parse $file: $@" if $@;
warn "couldn't do $file: $!" unless defined $return;
warn "couldn't run $file" unless $return;
exit 1;
}
}
sub help
{
print "$0 <lat>,<long>\n";
print "Additional options: \n";
print " --elevation <plugin>\n";
}
if( !GetOptions (
"elevation=s" => \$elevation_plugin,
)) {
print STDERR ("Error in command line arguments\n");
help();
exit( 1 );
}
}
use strict;
use warnings;
if( $help )
{
help();
exit( 0 );
}
my $centre = $ARGV[0];
############################### ###############################
if( !-d "$FindBin::Bin/var" ) { mkdir( "$FindBin::Bin/var" ); }
if( !-d "$FindBin::Bin/var/tiles" ) { mkdir( "$FindBin::Bin/var/tiles" ); }
if( !-d "$FindBin::Bin/var/tmp" ) { mkdir( "$FindBin::Bin/var/tmp" ); }
if( !-d "$FindBin::Bin/var/lidar" ) { mkdir( "$FindBin::Bin/var/lidar" ); }
if( !-d "$FindBin::Bin/var/lidar/DSM" ) { mkdir( "$FindBin::Bin/var/lidar/DSM" ); }
if( !-d "$FindBin::Bin/var/lidar/DTM" ) { mkdir( "$FindBin::Bin/var/lidar/DTM" ); }
$elevation_plugin = "UKDEFRA" if( !defined $elevation_plugin );
my $rc = eval "use Elevation::$elevation_plugin; 1;";
if( !$rc ) {
die "Error in loading elevation; $@";
}
my $elevation = "Elevation::$elevation_plugin"->new(
"$FindBin::Bin/var/lidar",
"$FindBin::Bin/var/tmp",
);
my( $lat, $long ) = split( /,/,$centre);
no strict 'refs';
my $ll_to_en = "Elevation::".$elevation_plugin."::ll_to_en";
my( $e,$n ) = &$ll_to_en( $lat,$long );
use strict 'refs';
my $data = {};
my $SPREAD=2;
for( my $xo=-$SPREAD; $xo<=$SPREAD; ++$xo )
{
for( my $yo=-$SPREAD; $yo<=$SPREAD; ++$yo )
{
my $dsm = $elevation->en( "DSM", $e+$xo, $n+$yo );
my $dtm = $elevation->en( "DTM", $e+$xo, $n+$yo );
push @{$data->{DSM}}, $dsm;
push @{$data->{DTM}}, $dtm;
push @{$data->{DIFF}}, $dsm-$dtm;
}
}
print sprintf(
"DSM: % 3.2fm\nDTM: % 3.2fm\nHEIGHT: % 3.2fm\n",
median( $data->{DSM} ),
median( $data->{DTM} ),
median( $data->{DIFF} ) );
exit;
sub median
{
my( $list ) = @_;
my $i = int( ( scalar @$list ) / 2 );
return $list->[$i];
}