-
Notifications
You must be signed in to change notification settings - Fork 0
/
proc_ghs-2.pl
executable file
·43 lines (37 loc) · 982 Bytes
/
proc_ghs-2.pl
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
#! /usr/bin/perl
###
#This iterates through the list of bboxes and geohashs
#truncates the geohashes to the required length
#$precision=3 gives a 156km by 156km extent. See wikipedia
#for further possible values.
#This then outputs to stdout a csv list of
#TruncatedGeohash,PolygonIndex:PolygonIndex etc \n
#
#SMDE 25/11/15
###
use File::Slurp;
use Modern::Perl;
use Data::Dumper;
my @lines=read_file('boxes-and-hashes.csv');
my %ghs;
my ($line, $index, $gh, $truncgh, $vals, $vals1);
my $precision=5; #can be changed for other extents, see wikipedia for table
foreach $line (@lines) {
#say $line;
($index,$gh)=split(/,/,$line);
$truncgh=substr($gh,0,$precision);
#say $truncgh;
if (exists($ghs{$truncgh})) {
#call value and add to it
$vals=$ghs{$truncgh};
#say $vals;
$vals1=$index.":".$vals;
#say $vals1;
$ghs{$truncgh}=$vals1;
} else {
#add value and key to hash
$ghs{$truncgh}=$index;
}
}
#write out hash
print map {"$_,$ghs{$_}\n"} keys %ghs;