forked from liosha/osm2mp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmp-housesearch.pl
executable file
·109 lines (78 loc) · 2.69 KB
/
mp-housesearch.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
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
#!/usr/bin/perl
########
# $Id$
# $Rev$
# $Author$
# $Date$
use 5.010;
use strict;
use warnings;
use autodie;
our $VERSION = 0.02;
use Readonly;
use Encode;
use Geo::Parse::PolishFormat;
use List::Util qw{ min max };
use List::MoreUtils qw{ all any };
use match::simple;
use Math::Polygon::Tree 0.06 qw{ polygon_centroid };
use Data::Dump 'dd';
Readonly my $MP_CODEPAGE => 'cp1251';
Readonly my $FAKE_ROAD_LENGTH => 0.00002;
Readonly my $MAX_HOUSE_NUMBER => 9999;
my $roadid = 1;
my $nodeid = 1;
my $callback = sub {
my $obj = shift;
if ( $obj->{name} eq 'IMG ID' ) {
say '[IMG ID]';
for my $line ( @{ $obj->{lines} } ) {
next if index( $line, 'Routing=' ) == 0;
$line =~ s/^ID=(\d)/'ID='.($1+1)/xmse;
$line =~ s/^Name=/Name=S: /xms;
say $line;
}
say 'Numbering=Y';
say 'DrawPriority=20';
say "[END-IMG ID]\n\n";
return;
};
if ( $obj->{name} eq 'POLYGON' && $obj->{attributes}->{Type} eq '0x4B' ) {
say '[POLYGON]';
for my $line ( @{ $obj->{lines} } ) {
print "$line\n";
}
say "[END]\n\n";
return;
};
return
unless $obj->{name} eq 'POLYGON' && $obj->{attributes}->{Type} eq '0x13'
|| $obj->{name} eq 'POI' && $obj->{attributes}->{Type} |M| [ '0x2800', '0x6100' ];
return
unless all { exists $obj->{attributes}->{$_} } qw{ HouseNumber StreetDesc CityName };
my $number = encode $MP_CODEPAGE, uc( decode $MP_CODEPAGE, $obj->{attributes}->{HouseNumber} );
$number =~ tr/ \t\r\n//;
my $digits = min( 0+$number, $MAX_HOUSE_NUMBER );
return unless $digits;
say '[POLYLINE]';
say 'Type=0x0D';
say "Label=$number $obj->{attributes}->{StreetDesc}";
my ($lat, $lon) = @{ polygon_centroid($obj->{attributes}->{Data0}) };
printf "Data0=(%f,%f),(%f,%f)\n", $lat-$FAKE_ROAD_LENGTH, $lon, $lat+$FAKE_ROAD_LENGTH, $lon;
say 'RoadID=' . $roadid++;
$obj->{attributes}->{CityName} =~ tr/,/ /;
$obj->{attributes}->{RegionName} =~ tr/,/ /;
$obj->{attributes}->{CountryName} =~ tr/,/ /;
say "Numbers1=0,B,$digits,$digits,N,-1,-1,-1,-1,$obj->{attributes}->{CityName},$obj->{attributes}->{RegionName},$obj->{attributes}->{CountryName},-1";
printf "Nod1=0,%d,0\n", $nodeid++;
printf "Nod2=1,%d,0\n", $nodeid++;
while ( my ( $k, $v ) = each %{ $obj->{attributes} } ) {
next if any { $k eq $_ } qw{ Type Label HouseNumber StreetDesc };
next if $k =~ /^Data\d+/xms;
print "$k=$v\n";
}
say "[END]\n";
};
local $SIG{__WARN__} = sub { shift };
my $parser = Geo::Parse::PolishFormat->new();
$parser->parse( $ARGV[0], $callback );