/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs

« back to all changes in this revision

Viewing changes to Methods/Mapping/scripts/osm2mp/osmget.pl

  • Committer: Suren A. Chilingaryan
  • Date: 2009-04-09 03:21:08 UTC
  • Revision ID: csa@dside.dyndns.org-20090409032108-w4edamdh4adrgdu3
import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
# use strict;
 
3
require LWP::UserAgent;
 
4
 
 
5
 
 
6
 
 
7
my $bbox = $ARGV[0];
 
8
 
 
9
my $api  = "http://api.openstreetmap.org/api/0.5/map?bbox=";
 
10
my $step = 0.5;
 
11
 
 
12
 
 
13
my @tiles;
 
14
my ($minlon, $minlat, $maxlon, $maxlat) = split ",", $bbox;
 
15
 
 
16
for (my $lon=$minlon; $lon<$maxlon; $lon+=$step) {
 
17
    for (my $lat=$minlat; $lat<$maxlat; $lat+=$step) {
 
18
        push @tiles, join (",", ($lon, $lat, (sort($maxlon,$lon+$step))[0], (sort($maxlat,$lat+$step))[0]));
 
19
    }
 
20
}
 
21
 
 
22
while (scalar @tiles) {
 
23
 
 
24
    my $tile = shift @tiles;
 
25
    print STDERR "Getting bbox=$tile...   ";
 
26
 
 
27
    my $ua = LWP::UserAgent->new;
 
28
    my $req = HTTP::Request->new(GET => "$api$tile");
 
29
    my $res = $ua->request($req);
 
30
 
 
31
    if ($res->is_success) {
 
32
        print STDERR "Ok\n";
 
33
        print $res->content;
 
34
    } else {
 
35
#        print STDERR $res->status_line . "  --| ";
 
36
        print STDERR $res->code . "  --| ";
 
37
        if ($res->code==400 || $res->code==500) {
 
38
            print STDERR "tile will be splitted\n";
 
39
            my ($lon0, $lat0, $lon1, $lat1) = split ",", $tile;
 
40
            push @tiles, join (",", ($lon0, $lat0, ($lon0+$lon1)/2, ($lat0+$lat1)/2));
 
41
            push @tiles, join (",", ($lon0, ($lat0+$lat1)/2, ($lon0+$lon1)/2, $lat1));
 
42
            push @tiles, join (",", (($lon0+$lon1)/2, $lat0, $lon1, ($lat0+$lat1)/2));
 
43
            push @tiles, join (",", (($lon0+$lon1)/2, ($lat0+$lat1)/2, $lon1, $lat1));
 
44
        } else {
 
45
            print STDERR "shall try again\n";
 
46
            push @tiles, $tile;
 
47
        }
 
48
    }
 
49
 
 
50
}
 
51