Created
January 3, 2018 17:57
-
-
Save xenos1984/83b6b2f1fd518faf1c3bd235009366ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header("Content-Type: text/plain"); | |
//$osm = json_decode(file_get_contents('http://overpass-api.de/api/interpreter?data=' . urlencode('[out:json][timeout:120];area["name"="Eesti"]->.area;(relation["type"="boundary"]["boundary"="administrative"](area.area););out tags;'))); | |
$osm = json_decode(file_get_contents("overpass.json"), true); | |
$csv = fopen("maakond.csv", "rt"); | |
$headerm = fgetcsv($csv, 1024, ',', '"', "\\"); | |
$ehakm = array(); | |
while(!feof($csv)) | |
{ | |
$data = array_combine($headerm, fgetcsv($csv, 1024, ',', '"', "\\")); | |
$ehakm[$data['MKOOD']] = $data; | |
} | |
fclose($csv); | |
$csv = fopen("omavalitsus.csv", "rt"); | |
$headero = fgetcsv($csv, 1024, ',', '"', "\\"); | |
$ehako = array(); | |
while(!feof($csv)) | |
{ | |
$data = array_combine($headero, fgetcsv($csv, 1024, ',', '"', "\\")); | |
$ehako[$data['OKOOD']] = $data; | |
} | |
fclose($csv); | |
$csv = fopen("asustusyksus.csv", "rt"); | |
$headera = fgetcsv($csv, 1024, ',', '"', "\\"); | |
$ehaka = array(); | |
while(!feof($csv)) | |
{ | |
$data = array_combine($headera, fgetcsv($csv, 1024, ',', '"', "\\")); | |
$ehaka[$data['AKOOD']] = $data; | |
} | |
fclose($csv); | |
foreach($osm['elements'] as $index => $entry) | |
{ | |
if(!array_key_exists('EHAK:code', $entry['tags'])) | |
{ | |
echo "Relation {$entry['id']} {$entry['tags']['name']} has no EHAK:code.\n"; | |
continue; | |
} | |
$code = $entry['tags']['EHAK:code']; | |
$idx = 0; | |
if(array_key_exists($code, $ehakm)) | |
{ | |
if(array_key_exists('OSM', $ehakm[$code])) | |
$idx = $ehakm[$code]['OSM']; | |
$ehakm[$code]['OSM'] = $index; | |
$level = 6; | |
$name = $ehakm[$code]['MNIMI']; | |
$codec = $codep = $namec = $namep = ""; | |
} | |
elseif(array_key_exists($code, $ehako)) | |
{ | |
if(array_key_exists('OSM', $ehako[$code])) | |
$idx = $ehako[$code]['OSM']; | |
$ehako[$code]['OSM'] = $index; | |
$level = 7; | |
$name = $ehako[$code]['ONIMI']; | |
$codec = $ehako[$code]['MKOOD']; | |
$namec = $ehako[$code]['MNIMI']; | |
$codep = $namep = ""; | |
} | |
elseif(array_key_exists($code, $ehaka)) | |
{ | |
if(array_key_exists('OSM', $ehaka[$code])) | |
$idx = $ehaka[$code]['OSM']; | |
$ehaka[$code]['OSM'] = $index; | |
if(abs($ehaka[$code]['TYYP'] - 4) == 2) | |
$level = 8; | |
else | |
$level = 9; | |
$name = $ehaka[$code]['ANIMI']; | |
$codec = $ehaka[$code]['MKOOD']; | |
$namec = $ehaka[$code]['MNIMI']; | |
$codep = $ehaka[$code]['OKOOD']; | |
$namep = $ehaka[$code]['ONIMI']; | |
} | |
else | |
{ | |
echo "Relation {$entry['id']} {$entry['tags']['name']} has invalid EHAK:code $code.\n"; | |
continue; | |
} | |
if($idx) | |
echo "Relation {$entry['id']} {$entry['tags']['name']} and {$osm['elements'][$idx]['id']} {$osm['elements'][$idx]['tags']['name']} have identical EHAK:code $code.\n"; | |
if(!array_key_exists('name', $entry['tags'])) | |
echo "Relation {$entry['id']} has no name.\n"; | |
elseif($entry['tags']['name'] != $name) | |
echo "Relation {$entry['id']} {$entry['tags']['name']} does not match EHAK name $name\n"; | |
if(!array_key_exists('admin_level', $entry['tags'])) | |
echo "Relation {$entry['id']} {$entry['tags']['name']} has no admin level.\n"; | |
elseif($entry['tags']['admin_level'] != $level) | |
echo "Relation {$entry['id']} {$entry['tags']['name']} admin level {$entry['tags']['admin_level']} does not match EHAK admin level $level\n"; | |
if($codep != "") | |
{ | |
if(!array_key_exists('EHAK:parishcode', $entry['tags'])) | |
echo "Relation {$entry['id']} {$entry['tags']['name']} has no EHAK:parishcode.\n"; | |
elseif($entry['tags']['EHAK:parishcode'] != $codep) | |
echo "Relation {$entry['id']} {$entry['tags']['name']} EHAK:parishcode {$entry['tags']['EHAK:parishcode']} does not match EHAK parish code $codep ($namep)\n"; | |
} | |
if($codec != "") | |
{ | |
if(!array_key_exists('EHAK:countycode', $entry['tags'])) | |
echo "Relation {$entry['id']} {$entry['tags']['name']} has no EHAK:countycode.\n"; | |
elseif($entry['tags']['EHAK:countycode'] != $codec) | |
echo "Relation {$entry['id']} {$entry['tags']['name']} EHAK:countycode {$entry['tags']['EHAK:countycode']} does not match EHAK county code $codec ($namec)\n"; | |
} | |
} | |
foreach($ehakm as $ehak) | |
{ | |
if(!array_key_exists('OSM', $ehak)) | |
echo "County {$ehak['MKOOD']} {$ehak['MNIMI']} has no OpenStreetMap relation.\n"; | |
} | |
foreach($ehako as $ehak) | |
{ | |
if(!array_key_exists('OSM', $ehak)) | |
echo "Parish {$ehak['OKOOD']} {$ehak['ONIMI']} in {$ehak['MKOOD']} {$ehak['MNIMI']} has no OpenStreetMap relation.\n"; | |
} | |
foreach($ehaka as $ehak) | |
{ | |
if(!array_key_exists('OSM', $ehak)) | |
echo "Place {$ehak['AKOOD']} {$ehak['ANIMI']} in {$ehak['OKOOD']} {$ehak['ONIMI']} in {$ehak['MKOOD']} {$ehak['MNIMI']} has no OpenStreetMap relation.\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment