/
map-generator.php
109 lines (85 loc) · 2.29 KB
/
map-generator.php
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
<?php
require_once ('../../varie.php');
init_geocache ();
global $geocache;
$output = new stdClass ();
$output->type = "FeatureCollection";
$output->features = array ();
foreach ($elenco_regioni as $region => $name) {
/*
I gruppi di carattere nazionale non possono essere messi sulla
cartina (a meno di piazzare un grosso marker di traverso su
tutta la nazione, ma non mi sembra il caso...), dunque li salto
*/
if ($name == "Italia")
continue;
$lugs = file ('https://raw.github.com/Gelma/LugMap/master/db/' . $region . '.txt', FILE_IGNORE_NEW_LINES);
$cities = file ('liste_comuni/' . $region . '.txt', FILE_IGNORE_NEW_LINES);
$found_cities = array ();
foreach ($lugs as $lug) {
$result = null;
$doshift = false;
$attr = explode ('|', $lug);
$mail = '';
$osmnode = '';
switch (count ($attr)) {
case 6:
$osmnode = $attr [5];
/*
Qui il break manca di proposito
*/
case 5:
$mail = $attr [4];
/*
Qui il break manca di proposito
*/
case 4:
default:
$site = $attr [3];
$zone = $attr [2];
$name = $attr [1];
$prov = $attr [0];
break;
}
if ($osmnode != '') {
$result = ask_openstreetmap ($osmnode);
}
if ($result == null) {
$doshift = true;
foreach ($cities as $city) {
if (stristr ($zone, $city) != false) {
$c = str_replace (' ', '%20', $city) . ',' . str_replace (' ', '%20', $prov);
$result = ask_coordinates ($c);
if ($result != null)
break;
$c = str_replace (' ', '%20', $city);
$result = ask_coordinates ($c);
if ($result != null)
break;
}
}
}
if ($result != null) {
list ($lat, $lon) = $result;
if ($doshift == true) {
$lon = shift_city ($city, $lon, $found_cities);
$found_cities [] = $city;
}
$point = new stdClass ();
$point->type = "Feature";
$point->properties = new stdClass ();
$point->properties->name = $name;
$point->properties->website = $site;
$point->geometry = new stdClass ();
$point->geometry->type = "Point";
$point->geometry->coordinates = array ($lon, $lat);
array_push ($output->features, $point);
}
else {
echo "Impossibile gestire la zona '$zone', si consiglia l'analisi manuale\n";
}
}
}
write_geo_file ('dati.txt', json_encode ($output));
save_geocache ();
?>