/i', $line, $matches))
{
$state = $stateInTr;
$poi = array();
$poi['status'] = colorToStatus($matches[1]);
}
}
else
{
if (preg_match('/| ([^<]+)<\/td>/i', $line, $matches))
{
$poi['name'] = $matches[1];
}
elseif ((false !== strpos($line, 'Google Maps')) && preg_match('/\&q=([^\&]+)\&/', $line, $matches))
{
$poi['q'] = $matches[1];
}
elseif (preg_match_all('/mlat=([0-9\.]+)\&mlon=([0-9\.]+)\&/', $line, $matches, PREG_SET_ORDER))
{
$poi['coords'] = array();
for ($i = 0; $i < count($matches); $i++)
{
$poi['coords'][] = array($matches[$i][1], $matches[$i][2]); // lat + lon
}
}
elseif (false !== strpos($line, ' |
'))
{
$countAll++;
// is poi already known? no? get it:
if (! isset($data['streets'][$poi['name']]))
{
$data['streets'][$poi['name']] = $poi;
$countNew++;
}
else // merge into existing data:
{
$countUpdated++;
$data['streets'][$poi['name']]['status'] = $poi['status']; // statuswechsel übernehmen
if (isset($poi['coords']))
{
$data['streets'][$poi['name']]['coords'] = $poi['coords'];
}
if (isset($poi['q']))
{
$data['streets'][$poi['name']]['q'] = $poi['q'];
}
}
$state = $stateOutTr;
}
}
}
fclose($fh);
echo 'Updated streetlist from url ' . $statusUrl . "\n";
$data['last_update_status'] = strftime('%F %T %s');
storeData($datafile, $data);
echo "Streets in url: $countAll, new: $countNew, updated: $countUpdated\n";
echo "Done.\n\n";
}
// Gecode incomplete streets
if (isset($opts['G']))
{
$countAll = 0;
$countHadCoords = 0;
$countUpdated = 0;
$countFailed = 0;
$countGeocoding = 0;
$countWhitelisted = 0;
$data = readData($datafile);
foreach ($data['streets'] as $streetname => $street)
{
$countAll++;
if (isset($street['coords']) && count($street['coords']))
{
$countHadCoords++;
}
else
{
$street['coords'] = array();
// try geocoder:
if (isset($street['q']))
{
$countGeocoding++;
$coords = getCoords($street['q'], 500000);
if ($coords !== null)
{
$countUpdated++;
$street['coords'][] = array($coords->lat, $coords->lon);
$data['streets'][ $streetname ] = $street; // update
echo $countGeocoding . ': Successful geocoded: ' . $streetname . ' ; searched for "' . $street['q'] . '".' . "\n";
}
else
{
echo $countGeocoding . ': Failed geocoding: ' . $streetname . ' ; searched for "' . $street['q'] . '".' . "\n";
$countFailed++;
}
}
}
}
$data['last_update_geocoder'] = strftime('%F %T %s');
storeData($datafile, $data);
echo "Updated: $countUpdated, failed: $countFailed.\n";
echo "Count all: $countAll, completeness: " . ((100*($countUpdated + $countHadCoords))/$countAll) . "%\n";
echo "Count whitelisted: $countWhitelisted\n";
echo "\n";
echo "Done.\n\n";
}
// Export layertext:
if (isset($opts['t']) && isset($opts['o']))
{
$offsetLat = 51; // lon
$offsetLon = 8; // lat
if (isset($opts['O']))
{
$tmp = explode(",", $opts['O']);
if (count($tmp) == 2)
{
$offsetLat = $tmp[0];
$offsetLon = $tmp[1];
}
}
$countOrphans = 0;
$countWhitelisted = 0;
$outfile = $opts['o'];
$data = readData($datafile);
$fh = fopen($outfile, 'w');
if ($fh === false)
{
throw new Exception('Could not create output file "' . $outfile . '".');
}
fwrite($fh, "lat\tlon\ttitle\tdescription\ticonSize\ticonOffset\ticon\n");
$dt = strftime("%d.%m.%Y %H:%M Uhr");
foreach ($data['streets'] as $streetname => $street)
{
// Idea: group without-coords around city
if (isset($street['coords']) && count($street['coords']))
{
if (in_array($street['name'], $osmWhitelist))
{
$countWhitelisted++;
continue;
}
$title = str_replace(array("\n", "\t", "\r"), '', $street['name']);
$description = $street['status'] . '