source: subversion/applications/utils/osm-extract/polygons/fast_complete_poly_filter.pl

Last change on this file was 19328, checked in by frederik, 9 years ago

fix

File size: 1.5 KB
Line 
1#!/usr/bin/perl
2
3# script that achieves the same as
4#
5# osmosis --rx infile.osm
6#  --bp file=file.poly completeWays=yes completeRelations=yes
7#  --wx outfile.osm
8#
9# just faster, by adding a "--bb" step just before the --bp that
10# cuts out the area of the polygon plus a safety buffer. this provides
11# a big speedup if the polygon cuts out a relatively small area of the
12# input file, because it saves osmosis a lot of temporary storage.
13#
14# requires osmosis to be in the $PATH.
15
16if (scalar(@ARGV) != 3)
17{
18    print "usage: $0 infile.osm polyfile.poly outfile.osm\n";
19    exit;
20}
21
22my ($infile, $polyfile, $outfile) = @ARGV;
23
24if (!-r $infile)
25{
26    print "cannot open $infile for reading\n";
27    exit;
28}
29
30if (-s $infile > 20000000000)
31{
32    $idt = "idTrackerType=BitSet";
33}
34
35if (!-r $polyfile)
36{
37    print "cannot open $polyfile for reading\n";
38    exit;
39}
40
41if (!open(X, ">$outfile"))
42{
43    print "cannot open $outfile for writing\n";
44    exit;
45}
46close(X);
47
48open (POLY, $polyfile);
49
50my $bottom = 90;
51my $top = -90;
52my $left = 180;
53my $right = -180;
54
55while($line = <POLY>)
56{
57    my ($dummy, $x, $y) = split(/\s+/, $line);
58    if ($x =~ /^[0-9-+.eE]+$/ && $y =~ /^[0-9-+.eE]+$/)
59    {
60        if ($x<$left) { $left=$x } elsif ($x>$right) { $right=$x; }
61        if ($y<$bottom) { $bottom=$y } elsif ($y>$top) { $top=$y; }
62    }
63}
64close(POLY);
65
66$left--; $right++;
67$bottom--; $top++;
68
69$command =  "osmosis --rx $infile --bb left=$left right=$right bottom=$bottom top=$top $idt --bp file=$polyfile completeWays=true completeRelations=true --wx $outfile";
70print "$command\n";
71exec $command;
Note: See TracBrowser for help on using the repository browser.