Description
Reading former issues here, I understand how you derived at your current Admin Level system implemented. #392 #398
And it all makes sense to a degree. It is clear that every country has different Admin Levels.
My issue takes place with locations within a certain country and their own Admin Level hierarchy and how to handle differences and inconsistencies. Let's take Germany for example since there has been a similar open discussion #483 . Here you can have cities with state, region and county but not necessarily. One city can have a region while the next one doesn't.
GeoNames therefore delivers empty admin_level_2 (Region) for those cities.
Look at "adminName2": ""
{"geonames": [{
"adminCode3": "03458",
"adminCode2": "00",
"countryName": "Germany",
"adminCode1": "06",
"lng": "8.55947",
"adminCode4": "03458005",
"adminName2": "",
"fcodeName": "populated place",
"adminName3": "Landkreis Oldenburg",
"distance": "0.82744",
"timezone": {
"dstOffset": 2,
"gmtOffset": 1,
"timeZoneId": "Europe/Berlin"
},
"adminName4": "Ganderkesee",
"adminName5": "",
"name": "Almsloh",
"fcode": "PPL",
"geonameId": 2958212,
"asciiName": "Almsloh",
"lat": "53.05641",
"population": 0,
"adminName1": "Lower Saxony",
"adminId1": "2862926",
"countryId": "2921044",
"fclName": "city, village,...",
"elevation": 0,
"countryCode": "DE",
"adminId4": "6552965",
"adminId3": "2857455",
"toponymName": "Almsloh",
"fcl": "P",
"continentCode": "EU"
}]}
This goes against previous comment @giosh94mhz #428
[...] In theory (and in all my tests), all providers properly fill Admin Level starting with one, and there are not holes (e.g. level 1 and 3 present, without level 2). [...]
Based on the above comment GeoNames implementation drops empty Admin Levels:
/src/Geocoder/Provider/Geonames.php#140
for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; ++ $level) {
$adminNameProp = 'adminName' . $level;
$adminCodeProp = 'adminCode' . $level;
if (! empty($item->$adminNameProp) || ! empty($item->$adminCodeProp)) {
$adminLevels[] = [
'name' => empty($item->$adminNameProp) ? null : $item->$adminNameProp ,
'code' => empty($item->$adminCodeProp) ? null : $item->$adminCodeProp,
'level' => $level,
];
}
}
Which results in different Admin Level sets within the same country. Admin Level 2 may contain a region or maybe a county.
Another issue would take place when using OpenStreetMap as a provider. Here the Admin Level has been taken ad absurdum since for all countries only state and county are being imported.
/src/Geocoder/Provider/Nominatim.php#111
$adminLevels = [];
foreach (['state', 'county'] as $i => $tagName) {
if (null !== ($adminLevel = $this->getNodeValue($addressNode->getElementsByTagName($tagName)))) {
$adminLevels[] = ['name' => $adminLevel, 'level' => $i + 1];
}
}
This way a lot of information is lost/unusable in most countries as you can see in the listing #392 .
How would I safely extract the county using GeoNames for Germany cities for example? Even though every city in German will have a county it will not always be at the same Admin Level.