From: Artem Ziablytskyi Date: Mon, 17 Jan 2022 16:20:06 +0000 (+0100) Subject: add `:ISO3166-2` field to response address details X-Git-Tag: v4.1.0~63^2~6 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/82dbcbb12a1285e7b345e232196b02b9cae35f9a add `:ISO3166-2` field to response address details --- diff --git a/VAGRANT.md b/VAGRANT.md index b10a5ac7..d26b8dbd 100644 --- a/VAGRANT.md +++ b/VAGRANT.md @@ -44,7 +44,7 @@ is. # inside the virtual machine: cd build wget --no-verbose --output-document=/tmp/monaco.osm.pbf http://download.geofabrik.de/europe/monaco-latest.osm.pbf - ./utils/setup.php --osm-file /tmp/monaco.osm.pbf --osm2pgsql-cache 1000 --all 2>&1 | tee monaco.$$.log + nominatim import --osm-file /tmp/monaco.osm.pbf ``` To repeat an import you'd need to delete the database first diff --git a/docs/api/Output.md b/docs/api/Output.md index 3c541d33..d3ecf8d7 100644 --- a/docs/api/Output.md +++ b/docs/api/Output.md @@ -28,7 +28,7 @@ a single place (for reverse) of the following format: "city": "London", "state_district": "Greater London", "state": "England", - "state_code": "ENG", + "ISO3166-2": "GB-ENG", "postcode": "SW1A 2DU", "country": "United Kingdom", "country_code": "gb" diff --git a/lib-php/AddressDetails.php b/lib-php/AddressDetails.php index a1a2a636..657dc3e2 100644 --- a/lib-php/AddressDetails.php +++ b/lib-php/AddressDetails.php @@ -93,8 +93,8 @@ class AddressDetails ) { $aAddress[$sTypeLabel] = $sName; - if ('state' === $sTypeLabel && !empty($aLine['name'])) { - $this->addStateCode($aAddress, $aLine['name']); + if (!empty($aLine['name'])) { + $this->addStateCode($aAddress, $sTypeLabel, $aLine['name']); } } } @@ -182,14 +182,13 @@ class AddressDetails /** * Add `state_code` field to address details to represent second part of ISO 3166-2 country subdivision code */ - private function addStateCode(&$aAddress, $nameDetails) + private function addStateCode(&$aAddress, $sTypeLabel, $nameDetails) { if (is_string($nameDetails)) { $nameDetails = json_decode('{' . str_replace('"=>"', '":"', $nameDetails) . '}', true); } - - if (!empty($nameDetails['ref'])) { - $aAddress['state_code'] = $nameDetails['ref']; + if (!empty($nameDetails['ISO3166-2'])) { + $aAddress["$sTypeLabel:ISO3166-2"] = $nameDetails['ISO3166-2']; } } } diff --git a/test/php/Nominatim/AddressDetailsTest.php b/test/php/Nominatim/AddressDetailsTest.php index 4cf36344..02813286 100644 --- a/test/php/Nominatim/AddressDetailsTest.php +++ b/test/php/Nominatim/AddressDetailsTest.php @@ -86,7 +86,7 @@ class AddressDetailsTest extends \PHPUnit\Framework\TestCase 'city' => 'London', 'state_district' => 'Greater London', 'state' => 'England', - 'state_code' => 'ENG', + 'state:ISO3166-2' => 'GB-ENG', 'postcode' => 'SW1A 2AA', 'country' => 'United Kingdom', 'country_code' => 'gb' diff --git a/test/php/fixtures/address_details_10_downing_street.json b/test/php/fixtures/address_details_10_downing_street.json index f56cfd9a..0a56beec 100644 --- a/test/php/fixtures/address_details_10_downing_street.json +++ b/test/php/fixtures/address_details_10_downing_street.json @@ -157,7 +157,7 @@ {"place_id":194325361, "osm_type":"R", "osm_id":58447, - "name":{"ref": "ENG", "name": "England", "name:be": "Англія", "name:br": "Bro-Saoz", "name:ca": "Anglaterra", "name:cs": "Anglie", "name:cy": "Lloegr", "name:de": "England", "name:el": "Αγγλία", "name:en": "England", "name:eo": "Anglujo", "name:es": "Inglaterra", "name:fi": "Englanti", "name:fr": "Angleterre", "name:fy": "Ingelân", "name:ga": "Sasana", "name:gd": "Sasainn", "name:gv": "Sostyn", "name:he": "אנגליה", "name:hu": "Anglia", "name:ia": "Anglaterra", "name:io": "Anglia", "name:it": "Inghilterra", "name:la": "Anglia", "name:lt": "Anglija", "name:nl": "Engeland", "name:pl": "Anglia", "name:pt": "Inglaterra", "name:ru": "Англия", "name:sk": "Anglicko", "name:sv": "England", "name:tr": "İngiltere", "name:uk": "Англія", "name:vi": "Anh", "name:vo": "Linglän", "name:zh": "英格蘭", "name:hsb": "Jendźelska", "name:nds": "England", "name:tok": "ma Inli", "name:tzl": "Anglatzara", "alt_name:eo": "Anglio", "alt_name:ia": "Anglia", "old_name:vi": "Anh Quốc", "alt_name:nds": "Ingland", "name:be-tarask": "Ангельшчына", "name:zh-classical": "英格蘭", "name:zh-simplified": "英格兰", "name:zh-traditional": "英格蘭"}, + "name":{"ref": "ENG", "ISO3166-2": "GB-ENG", "name": "England", "name:be": "Англія", "name:br": "Bro-Saoz", "name:ca": "Anglaterra", "name:cs": "Anglie", "name:cy": "Lloegr", "name:de": "England", "name:el": "Αγγλία", "name:en": "England", "name:eo": "Anglujo", "name:es": "Inglaterra", "name:fi": "Englanti", "name:fr": "Angleterre", "name:fy": "Ingelân", "name:ga": "Sasana", "name:gd": "Sasainn", "name:gv": "Sostyn", "name:he": "אנגליה", "name:hu": "Anglia", "name:ia": "Anglaterra", "name:io": "Anglia", "name:it": "Inghilterra", "name:la": "Anglia", "name:lt": "Anglija", "name:nl": "Engeland", "name:pl": "Anglia", "name:pt": "Inglaterra", "name:ru": "Англия", "name:sk": "Anglicko", "name:sv": "England", "name:tr": "İngiltere", "name:uk": "Англія", "name:vi": "Anh", "name:vo": "Linglän", "name:zh": "英格蘭", "name:hsb": "Jendźelska", "name:nds": "England", "name:tok": "ma Inli", "name:tzl": "Anglatzara", "alt_name:eo": "Anglio", "alt_name:ia": "Anglia", "old_name:vi": "Anh Quốc", "alt_name:nds": "Ingland", "name:be-tarask": "Ангельшчына", "name:zh-classical": "英格蘭", "name:zh-simplified": "英格兰", "name:zh-traditional": "英格蘭"}, "class":"boundary", "type":"administrative", "admin_level":4, diff --git a/vagrant/Install-on-Ubuntu-20.sh b/vagrant/Install-on-Ubuntu-20.sh index 68bd6b04..06b8b5b8 100755 --- a/vagrant/Install-on-Ubuntu-20.sh +++ b/vagrant/Install-on-Ubuntu-20.sh @@ -222,7 +222,7 @@ server { listen 80 default_server; listen [::]:80 default_server; - root $USERHOME/nominatim-project/website; + root $USERHOME/nominatim/website; index search.php index.html; location / { try_files \$uri \$uri/ @php;