From f498f02ba501f75a703dbef9c2e780d16f1695dc Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Thu, 20 Jul 2023 18:15:03 +0200 Subject: [PATCH 01/12] Add ability to filter reverse query on osm data --- src/Provider/Photon/Photon.php | 1 + ...moot.io_e701db024e1614b6d2a4f4c71bffec8ddd1c83ce | 1 + src/Provider/Photon/Tests/PhotonTest.php | 13 +++++++++++++ 3 files changed, 15 insertions(+) create mode 100644 src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_e701db024e1614b6d2a4f4c71bffec8ddd1c83ce diff --git a/src/Provider/Photon/Photon.php b/src/Provider/Photon/Photon.php index cdeea8978..f73187122 100644 --- a/src/Provider/Photon/Photon.php +++ b/src/Provider/Photon/Photon.php @@ -98,6 +98,7 @@ public function reverseQuery(ReverseQuery $query): Collection .http_build_query([ 'lat' => $latitude, 'lon' => $longitude, + 'query_string_filter' => $query->getData('query_string_filter'), 'lang' => $query->getLocale(), ]); diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_e701db024e1614b6d2a4f4c71bffec8ddd1c83ce b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_e701db024e1614b6d2a4f4c71bffec8ddd1c83ce new file mode 100644 index 000000000..f01e889ef --- /dev/null +++ b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_e701db024e1614b6d2a4f4c71bffec8ddd1c83ce @@ -0,0 +1 @@ +s:416:"{"features":[{"geometry":{"coordinates":[6.038995,45.7362133],"type":"Point"},"type":"Feature","properties":{"osm_id":9992954218,"country":"France","city":"Saint-Offenge","countrycode":"FR","postcode":"73100","county":"Savoie","type":"locality","osm_type":"N","osm_key":"place","district":"Saint-Offenge-Dessous","osm_value":"locality","name":"Le Loret","state":"Auvergne-Rhône-Alpes"}}],"type":"FeatureCollection"}"; \ No newline at end of file diff --git a/src/Provider/Photon/Tests/PhotonTest.php b/src/Provider/Photon/Tests/PhotonTest.php index c82bfbf32..fe2edced0 100644 --- a/src/Provider/Photon/Tests/PhotonTest.php +++ b/src/Provider/Photon/Tests/PhotonTest.php @@ -120,4 +120,17 @@ public function testReverseQuery() $this->assertEquals('Landkreis Hildesheim', $result->getCounty()); $this->assertEquals('Sehlem', $result->getDistrict()); } + + public function testReverseQueryWithOsmDataFilter() + { + $provider = Photon::withKomootServer($this->getHttpClient()); + $reverseQuery = ReverseQuery::fromCoordinates(45.73179, 6.03248) + ->withData('query_string_filter', 'osm_key:place') + ->withLimit(1); + /** @var \Geocoder\Provider\Photon\Model\PhotonAddress $result */ + $result = $provider->reverseQuery($reverseQuery)->first(); + + $this->assertEquals('place', $result->getOSMTag()->key); + $this->assertEquals('locality', $result->getOSMTag()->value); + } } From abac0bac6001c3cab797e9ecbf66d95c24e9b129 Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Mon, 31 Jul 2023 11:07:47 +0200 Subject: [PATCH 02/12] Add osm tag filter feature & limit filter --- src/Provider/Photon/Photon.php | 3 ++- src/Provider/Photon/Tests/PhotonTest.php | 25 ++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Provider/Photon/Photon.php b/src/Provider/Photon/Photon.php index f73187122..8e2d05981 100644 --- a/src/Provider/Photon/Photon.php +++ b/src/Provider/Photon/Photon.php @@ -98,7 +98,8 @@ public function reverseQuery(ReverseQuery $query): Collection .http_build_query([ 'lat' => $latitude, 'lon' => $longitude, - 'query_string_filter' => $query->getData('query_string_filter'), + 'osm_tag' => $query->getData('osm_tag'), + 'limit' => $query->getLimit(), 'lang' => $query->getLocale(), ]); diff --git a/src/Provider/Photon/Tests/PhotonTest.php b/src/Provider/Photon/Tests/PhotonTest.php index fe2edced0..68ac1d4f2 100644 --- a/src/Provider/Photon/Tests/PhotonTest.php +++ b/src/Provider/Photon/Tests/PhotonTest.php @@ -14,6 +14,7 @@ use Geocoder\IntegrationTest\BaseTestCase; use Geocoder\Provider\Photon\Photon; +use Geocoder\Provider\Photon\Model\PhotonAddress; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; @@ -97,7 +98,8 @@ public function testGeocodeQueryWithNamedResult() public function testReverseQuery() { $provider = Photon::withKomootServer($this->getHttpClient()); - $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(52, 10)); + $reverseQuery = ReverseQuery::fromCoordinates(52, 10)->withLimit(1); + $results = $provider->reverseQuery($reverseQuery); $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); @@ -121,16 +123,19 @@ public function testReverseQuery() $this->assertEquals('Sehlem', $result->getDistrict()); } - public function testReverseQueryWithOsmDataFilter() + public function testReverseQueryWithOsmTagFilter() { $provider = Photon::withKomootServer($this->getHttpClient()); - $reverseQuery = ReverseQuery::fromCoordinates(45.73179, 6.03248) - ->withData('query_string_filter', 'osm_key:place') - ->withLimit(1); - /** @var \Geocoder\Provider\Photon\Model\PhotonAddress $result */ - $result = $provider->reverseQuery($reverseQuery)->first(); - - $this->assertEquals('place', $result->getOSMTag()->key); - $this->assertEquals('locality', $result->getOSMTag()->value); + $reverseQuery = ReverseQuery::fromCoordinates(52.51644, 13.38890) + ->withData('osm_tag', 'amenity:pharmacy') + ->withLimit(3); + $results = $provider->reverseQuery($reverseQuery); + + $this->assertCount(3, $results); + foreach ($results as $result) { + $this->assertInstanceOf(PhotonAddress::class, $result); + $this->assertEquals('amenity', $result->getOSMTag()->key); + $this->assertEquals('pharmacy', $result->getOSMTag()->value); + } } } From 9089dae97cb33a40c8a77985fc344c561b10b3b6 Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Mon, 31 Jul 2023 11:08:19 +0200 Subject: [PATCH 03/12] Clean cached results from Photon API --- .../photon.komoot.io_36b7f4cab09652077420062dc53bc340e8b2b22d | 1 - .../photon.komoot.io_61baba2ee6bc4ba2e6688559d40d4e58e1ddd7c1 | 1 - ...=> photon.komoot.io_723a82c29164f0fc32d4c774f86c4569afdd804b} | 0 .../photon.komoot.io_77590bd663047da83d48c67d9101f04a82e48976 | 1 + .../photon.komoot.io_900b8b48594b267db76d84cfe7fd8b0ba4b927d6 | 1 + .../photon.komoot.io_e701db024e1614b6d2a4f4c71bffec8ddd1c83ce | 1 - .../photon.komoot.io_fb4e33e538bd52319d02f18862965a0c30d78dfd | 1 - 7 files changed, 2 insertions(+), 4 deletions(-) delete mode 100644 src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_36b7f4cab09652077420062dc53bc340e8b2b22d delete mode 100644 src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_61baba2ee6bc4ba2e6688559d40d4e58e1ddd7c1 rename src/Provider/Photon/Tests/.cached_responses/{photon.komoot.io_98f80bc58862d177a1c6507d33f5c83a88ab1ffd => photon.komoot.io_723a82c29164f0fc32d4c774f86c4569afdd804b} (100%) create mode 100644 src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_77590bd663047da83d48c67d9101f04a82e48976 create mode 100644 src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_900b8b48594b267db76d84cfe7fd8b0ba4b927d6 delete mode 100644 src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_e701db024e1614b6d2a4f4c71bffec8ddd1c83ce delete mode 100644 src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_fb4e33e538bd52319d02f18862965a0c30d78dfd diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_36b7f4cab09652077420062dc53bc340e8b2b22d b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_36b7f4cab09652077420062dc53bc340e8b2b22d deleted file mode 100644 index 45e7c2303..000000000 --- a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_36b7f4cab09652077420062dc53bc340e8b2b22d +++ /dev/null @@ -1 +0,0 @@ -s:455:"{"features":[{"geometry":{"coordinates":[-77.036931,38.900368],"type":"Point"},"type":"Feature","properties":{"osm_id":5076279021,"country":"United States of America","city":"Washington","countrycode":"US","postcode":"20012","locality":"Golden Triangle","type":"house","osm_type":"N","osm_key":"man_made","housenumber":"800","street":"Black Lives Matter Plaza Northwest","osm_value":"surveillance","state":"Washington, D.C."}}],"type":"FeatureCollection"}"; \ No newline at end of file diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_61baba2ee6bc4ba2e6688559d40d4e58e1ddd7c1 b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_61baba2ee6bc4ba2e6688559d40d4e58e1ddd7c1 deleted file mode 100644 index 916081189..000000000 --- a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_61baba2ee6bc4ba2e6688559d40d4e58e1ddd7c1 +++ /dev/null @@ -1 +0,0 @@ -s:2279:"{"features":[{"geometry":{"coordinates":[-0.1285993,51.5010484],"type":"Point"},"type":"Feature","properties":{"osm_id":2806295309,"country":"United Kingdom","city":"London","countrycode":"GB","postcode":"SW1P 3AE","locality":"Westminster","county":"Greater London","type":"house","osm_type":"N","osm_key":"office","housenumber":"8\u201310","street":"Great George Street","district":"Millbank","osm_value":"warmonger","name":"Finmeccanica UK Ltd","state":"England"}},{"geometry":{"coordinates":[-0.12770820958562096,51.50344025],"type":"Point"},"type":"Feature","properties":{"osm_id":1879842,"extent":[-0.1278356,51.5036483,-0.1273038,51.5032573],"country":"United Kingdom","countrycode":"GB","postcode":"SW1A 2AA","locality":"Westminster","county":"Greater London","type":"house","osm_type":"R","osm_key":"tourism","housenumber":"10","street":"Downing Street","district":"Covent Garden","osm_value":"attraction","name":"Prime Minister\u2019s Office","state":"England"}},{"geometry":{"coordinates":[-0.2765595,51.6136283],"type":"Point"},"type":"Feature","properties":{"osm_id":7179640410,"country":"United Kingdom","city":"Edgware, London","countrycode":"GB","postcode":"HA8 7JJ","county":"Greater London","type":"house","osm_type":"N","osm_key":"amenity","housenumber":"103","street":"Station Road","district":"Mill Hill","osm_value":"bank","name":"HSBC UK","state":"England"}},{"geometry":{"coordinates":[-0.1050314,51.5149368],"type":"Point"},"type":"Feature","properties":{"osm_id":6878399378,"country":"United Kingdom","city":"City of London","countrycode":"GB","postcode":"EC4A 4AD","locality":"Blackfriars","county":"Greater London","type":"house","osm_type":"N","osm_key":"office","housenumber":"10","street":"Saint Bride Street","osm_value":"company","name":"techUK","state":"England"}},{"geometry":{"coordinates":[-0.0469504,51.6429794],"type":"Point"},"type":"Feature","properties":{"osm_id":2444967088,"country":"United Kingdom","city":"London Borough of Enfield","countrycode":"GB","postcode":"EN3 4ES","locality":"Enfield Highway","county":"Greater London","type":"house","osm_type":"N","osm_key":"shop","housenumber":"106","street":"High Street","district":"Ponders End","osm_value":"car_parts","name":"UK Garage","state":"England"}}],"type":"FeatureCollection"}"; \ No newline at end of file diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_98f80bc58862d177a1c6507d33f5c83a88ab1ffd b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_723a82c29164f0fc32d4c774f86c4569afdd804b similarity index 100% rename from src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_98f80bc58862d177a1c6507d33f5c83a88ab1ffd rename to src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_723a82c29164f0fc32d4c774f86c4569afdd804b diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_77590bd663047da83d48c67d9101f04a82e48976 b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_77590bd663047da83d48c67d9101f04a82e48976 new file mode 100644 index 000000000..b9e1d963f --- /dev/null +++ b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_77590bd663047da83d48c67d9101f04a82e48976 @@ -0,0 +1 @@ +s:2127:"{"features":[{"geometry":{"coordinates":[-77.0372192,38.9002248],"type":"Point"},"type":"Feature","properties":{"osm_type":"W","osm_id":1049842804,"extent":[-77.0372192,38.9002248,-77.0370581,38.9002243],"country":"United States","osm_key":"highway","city":"Washington","countrycode":"US","osm_value":"secondary","postcode":"20006","name":"H Street Northwest","state":"District of Columbia","type":"street"}},{"geometry":{"coordinates":[-77.0366811,38.9002231],"type":"Point"},"type":"Feature","properties":{"osm_type":"W","osm_id":589539534,"extent":[-77.0370581,38.9002243,-77.0365521,38.9002187],"country":"United States","osm_key":"highway","city":"Washington","countrycode":"US","osm_value":"secondary","postcode":"20006","name":"H Street Northwest","state":"District of Columbia","type":"street"}},{"geometry":{"coordinates":[-77.03689992471391,38.90050395],"type":"Point"},"type":"Feature","properties":{"osm_id":55326891,"extent":[-77.0371738,38.9006934,-77.0367231,38.9003173],"country":"United States","city":"Washington","countrycode":"US","postcode":"20006","locality":"Golden Triangle","type":"house","osm_type":"W","osm_key":"tourism","housenumber":"800","street":"Black Lives Matter Plaza Northwest","osm_value":"hotel","name":"Hay-Adams Hotel","state":"District of Columbia"}},{"geometry":{"coordinates":[-77.0374769,38.9003895],"type":"Point"},"type":"Feature","properties":{"osm_type":"N","osm_id":367142942,"country":"United States","osm_key":"building","city":"Washington","street":"H Street Northwest","countrycode":"US","osm_value":"public","postcode":"20006","name":"United States Chamber of Commerce Building","state":"District of Columbia","type":"house"}},{"geometry":{"coordinates":[-77.0364753,38.9003613],"type":"Point"},"type":"Feature","properties":{"osm_id":4957653991,"country":"United States","city":"Washington","countrycode":"US","postcode":"20062","locality":"Golden Triangle","type":"house","osm_type":"N","osm_key":"tourism","street":"Black Lives Matter Plaza Northwest","osm_value":"information","name":"16th Street Meridian","state":"District of Columbia"}}],"type":"FeatureCollection"}"; \ No newline at end of file diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_900b8b48594b267db76d84cfe7fd8b0ba4b927d6 b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_900b8b48594b267db76d84cfe7fd8b0ba4b927d6 new file mode 100644 index 000000000..4bf2c6c13 --- /dev/null +++ b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_900b8b48594b267db76d84cfe7fd8b0ba4b927d6 @@ -0,0 +1 @@ +s:1219:"{"features":[{"geometry":{"coordinates":[13.3879579,52.5185603],"type":"Point"},"type":"Feature","properties":{"osm_id":380498298,"country":"Deutschland","city":"Berlin","countrycode":"DE","postcode":"10117","locality":"Dorotheenstadt","type":"house","osm_type":"N","osm_key":"amenity","housenumber":"151","street":"Friedrichstraße","district":"Mitte","osm_value":"pharmacy","name":"Dorotheenstadt Apotheke"}},{"geometry":{"coordinates":[13.3874475,52.5196854],"type":"Point"},"type":"Feature","properties":{"osm_id":3331787468,"country":"Deutschland","city":"Berlin","countrycode":"DE","postcode":"10117","locality":"Dorotheenstadt","type":"house","osm_type":"N","osm_key":"amenity","housenumber":"25","street":"Georgenstraße","district":"Mitte","osm_value":"pharmacy","name":"Aschenbachs Apotheke"}},{"geometry":{"coordinates":[13.3903812,52.5122639],"type":"Point"},"type":"Feature","properties":{"osm_id":956306643,"country":"Deutschland","city":"Berlin","countrycode":"DE","postcode":"10117","locality":"Dorotheenstadt","type":"house","osm_type":"N","osm_key":"amenity","housenumber":"68","street":"Friedrichstraße","district":"Mitte","osm_value":"pharmacy","name":"Apotheke Q205"}}],"type":"FeatureCollection"}"; \ No newline at end of file diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_e701db024e1614b6d2a4f4c71bffec8ddd1c83ce b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_e701db024e1614b6d2a4f4c71bffec8ddd1c83ce deleted file mode 100644 index f01e889ef..000000000 --- a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_e701db024e1614b6d2a4f4c71bffec8ddd1c83ce +++ /dev/null @@ -1 +0,0 @@ -s:416:"{"features":[{"geometry":{"coordinates":[6.038995,45.7362133],"type":"Point"},"type":"Feature","properties":{"osm_id":9992954218,"country":"France","city":"Saint-Offenge","countrycode":"FR","postcode":"73100","county":"Savoie","type":"locality","osm_type":"N","osm_key":"place","district":"Saint-Offenge-Dessous","osm_value":"locality","name":"Le Loret","state":"Auvergne-Rhône-Alpes"}}],"type":"FeatureCollection"}"; \ No newline at end of file diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_fb4e33e538bd52319d02f18862965a0c30d78dfd b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_fb4e33e538bd52319d02f18862965a0c30d78dfd deleted file mode 100644 index c3b709ce4..000000000 --- a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_fb4e33e538bd52319d02f18862965a0c30d78dfd +++ /dev/null @@ -1 +0,0 @@ -s:246:"{"features":[{"geometry":{"coordinates":[0,0],"type":"Point"},"type":"Feature","properties":{"osm_id":3815077900,"osm_type":"N","osm_key":"man_made","osm_value":"monitoring_station","name":"Soul Buoy","type":"house"}}],"type":"FeatureCollection"}"; \ No newline at end of file From 9715af77751ba24a897e2a2d8cd38b3e3e238f1f Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Mon, 31 Jul 2023 12:19:46 +0200 Subject: [PATCH 04/12] Some documentation about Photon Geocoder --- src/Provider/Photon/Readme.md | 41 +++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Provider/Photon/Readme.md b/src/Provider/Photon/Readme.md index bfd981ad5..42e1cf36e 100644 --- a/src/Provider/Photon/Readme.md +++ b/src/Provider/Photon/Readme.md @@ -10,13 +10,46 @@ This is the photon provider from the PHP Geocoder. This is a **READ ONLY** repository. See the [main repo](https://github.com/geocoder-php/Geocoder) for information and documentation. -### Install - +## Install ```bash composer require geocoder-php/photon-provider ``` -### Contribute +## API Documentation +https://photon.komoot.io +https://github.com/komoot/photon + +## Usage + +### Basic usage +You can use your own photon instance : +```php +// New instance of the provider : +$provider = new Geocoder\Provider\Photon\Photon($httpClient, 'https://your-photon-root-url'); +// Run geocode or reverse query +$query = $provider->geocodeQuery(new \Geocoder\Query\GeocodeQuery('Paris')); +$reverseQuery = $provider->reverseQuery(\Geocoder\Query\ReverseQuery::fromCoordinates(48.86036 ,2.33852)); +``` + +### OSM Tag Feature +You can search for location data based on osm tag filters. + +For example, you can filter a geocode query to only include results of type 'place'. You can even restrict it to only have places of type 'city'. + +In the reverse geocoding context you can search for the 3 pharmacies closest to a location. + +To see what you can do with this feature, check [the official photon documentation](https://github.com/komoot/photon#filter-results-by-tags-and-values) + +Below is an example to query the 3 pharmacies closest to a location : +```php +$provider = new Geocoder\Provider\Photon\Photon($httpClient, 'https://your-photon-root-url'); +$reverseQuery = ReverseQuery::fromCoordinates(52.51644, 13.38890) + ->withData('osm_tag', 'amenity:pharmacy') + ->withLimit(3); + +$results = $provider->reverseQuery($reverseQuery); +``` -Contributions are very welcome! Send a pull request to the [main repository](https://github.com/geocoder-php/Geocoder) or +## Contribute +Contributions are very welcome! Send a pull request to the [main repository](https://github.com/geocoder-php/Geocoder) or report any issues you find on the [issue tracker](https://github.com/geocoder-php/Geocoder/issues). From 71a1a8ec64c451b3aa31f8c00645441f80c907c8 Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Mon, 31 Jul 2023 12:45:31 +0200 Subject: [PATCH 05/12] Add support of osm tag filter for geocode query --- src/Provider/Photon/Photon.php | 1 + src/Provider/Photon/Readme.md | 2 +- ...t.io_f3b7c730ba71e84b11ac92049cd31806186e0ef1 | 1 + src/Provider/Photon/Tests/PhotonTest.php | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f3b7c730ba71e84b11ac92049cd31806186e0ef1 diff --git a/src/Provider/Photon/Photon.php b/src/Provider/Photon/Photon.php index 8e2d05981..53bfc095b 100644 --- a/src/Provider/Photon/Photon.php +++ b/src/Provider/Photon/Photon.php @@ -68,6 +68,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection .'/api?' .http_build_query([ 'q' => $address, + 'osm_tag' => $query->getData('osm_tag'), 'limit' => $query->getLimit(), 'lang' => $query->getLocale(), ]); diff --git a/src/Provider/Photon/Readme.md b/src/Provider/Photon/Readme.md index 42e1cf36e..75f350f66 100644 --- a/src/Provider/Photon/Readme.md +++ b/src/Provider/Photon/Readme.md @@ -27,7 +27,7 @@ You can use your own photon instance : // New instance of the provider : $provider = new Geocoder\Provider\Photon\Photon($httpClient, 'https://your-photon-root-url'); // Run geocode or reverse query -$query = $provider->geocodeQuery(new \Geocoder\Query\GeocodeQuery('Paris')); +$query = $provider->geocodeQuery(\Geocoder\Query\GeocodeQuery::create('Paris')); $reverseQuery = $provider->reverseQuery(\Geocoder\Query\ReverseQuery::fromCoordinates(48.86036 ,2.33852)); ``` diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f3b7c730ba71e84b11ac92049cd31806186e0ef1 b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f3b7c730ba71e84b11ac92049cd31806186e0ef1 new file mode 100644 index 000000000..6e057cd72 --- /dev/null +++ b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f3b7c730ba71e84b11ac92049cd31806186e0ef1 @@ -0,0 +1 @@ +s:2187:"{"features":[{"geometry":{"coordinates":[2.2978602225671843,48.8643133],"type":"Point"},"type":"Feature","properties":{"osm_id":79219308,"extent":[2.2971088,48.8647083,2.2984772,48.8639024],"country":"France","city":"Paris","countrycode":"FR","postcode":"75116","locality":"Quartier de Chaillot","type":"house","osm_type":"W","osm_key":"tourism","street":"Rue Gaston de Saint-Paul","district":"Paris","osm_value":"museum","name":"Musée d'Art Moderne de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3518758,48.850724],"type":"Point"},"type":"Feature","properties":{"osm_id":237003117,"country":"France","city":"Paris","countrycode":"FR","postcode":"75005","locality":"Quartier Saint-Victor","type":"house","osm_type":"N","osm_key":"tourism","street":"Quai de la Tournelle","district":"Paris","osm_value":"museum","name":"Musée de l'Assistance Publique Hôpitaux de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3450724,48.8640506],"type":"Point"},"type":"Feature","properties":{"osm_id":3087374948,"country":"France","city":"Paris","countrycode":"FR","postcode":"75001","locality":"Les Halles","type":"house","osm_type":"N","osm_key":"tourism","street":"Rue du Jour","district":"Paris","osm_value":"museum","name":"Musée du Barreau de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3153496472839956,48.866042],"type":"Point"},"type":"Feature","properties":{"osm_id":2778854,"extent":[2.3143339,48.866628,2.3156049,48.8654594],"country":"France","city":"Paris","countrycode":"FR","postcode":"75008","locality":"Quartier des Champs-Élysées","type":"house","osm_type":"R","osm_key":"tourism","street":"Avenue Winston Churchill","district":"Paris","osm_value":"museum","name":"Petit Palais","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3453019,48.8625016],"type":"Point"},"type":"Feature","properties":{"osm_id":1028569468,"country":"France","city":"Paris","countrycode":"FR","postcode":"75001","locality":"Les Halles","type":"house","osm_type":"N","osm_key":"tourism","street":"Rue du Cinéma","district":"Paris","osm_value":"museum","name":"Salle des collections","state":"Île-de-France"}}],"type":"FeatureCollection"}"; \ No newline at end of file diff --git a/src/Provider/Photon/Tests/PhotonTest.php b/src/Provider/Photon/Tests/PhotonTest.php index 68ac1d4f2..d4a46b4a0 100644 --- a/src/Provider/Photon/Tests/PhotonTest.php +++ b/src/Provider/Photon/Tests/PhotonTest.php @@ -95,6 +95,22 @@ public function testGeocodeQueryWithNamedResult() $this->assertEquals('The Sherlock Holmes Museum and shop', $result->getName()); } + public function testGeocodeQueryWithOsmTagFilter() + { + $provider = Photon::withKomootServer($this->getHttpClient()); + $query = GeocodeQuery::create('Paris') + ->withData('osm_tag', 'tourism:museum') + ->withLimit(5); + $results = $provider->geocodeQuery($query); + + $this->assertCount(5, $results); + foreach ($results as $result) { + $this->assertInstanceOf(PhotonAddress::class, $result); + $this->assertEquals('tourism', $result->getOSMTag()->key); + $this->assertEquals('museum', $result->getOSMTag()->value); + } + } + public function testReverseQuery() { $provider = Photon::withKomootServer($this->getHttpClient()); From 5db5e2d3ed93b07366ae3216278f9a50a2af4b1c Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Mon, 31 Jul 2023 14:46:01 +0200 Subject: [PATCH 06/12] CS fix --- src/Provider/Photon/Tests/PhotonTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Provider/Photon/Tests/PhotonTest.php b/src/Provider/Photon/Tests/PhotonTest.php index d4a46b4a0..85182948b 100644 --- a/src/Provider/Photon/Tests/PhotonTest.php +++ b/src/Provider/Photon/Tests/PhotonTest.php @@ -13,8 +13,8 @@ namespace Geocoder\Provider\Photon\Tests; use Geocoder\IntegrationTest\BaseTestCase; -use Geocoder\Provider\Photon\Photon; use Geocoder\Provider\Photon\Model\PhotonAddress; +use Geocoder\Provider\Photon\Photon; use Geocoder\Query\GeocodeQuery; use Geocoder\Query\ReverseQuery; From 4b1759286d2be887983a92224c4efa3930bbe9c5 Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Mon, 31 Jul 2023 16:01:38 +0200 Subject: [PATCH 07/12] Add compatibility for multiple osm tag filters --- src/Provider/Photon/Photon.php | 29 +++++++++++++++++-- ..._3c362ba852ee2323f9f25ca02c28cc5238959dbc} | 0 ..._8cd3447834c3ae8316dda602714b4ca4959eae65} | 0 ...o_f28b8c40cd259040dfbde8c3a179463de6a2ecc8 | 1 + src/Provider/Photon/Tests/PhotonTest.php | 16 ++++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) rename src/Provider/Photon/Tests/.cached_responses/{photon.komoot.io_900b8b48594b267db76d84cfe7fd8b0ba4b927d6 => photon.komoot.io_3c362ba852ee2323f9f25ca02c28cc5238959dbc} (100%) rename src/Provider/Photon/Tests/.cached_responses/{photon.komoot.io_f3b7c730ba71e84b11ac92049cd31806186e0ef1 => photon.komoot.io_8cd3447834c3ae8316dda602714b4ca4959eae65} (100%) create mode 100644 src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f28b8c40cd259040dfbde8c3a179463de6a2ecc8 diff --git a/src/Provider/Photon/Photon.php b/src/Provider/Photon/Photon.php index 53bfc095b..f45cdfe76 100644 --- a/src/Provider/Photon/Photon.php +++ b/src/Provider/Photon/Photon.php @@ -68,10 +68,13 @@ public function geocodeQuery(GeocodeQuery $query): Collection .'/api?' .http_build_query([ 'q' => $address, - 'osm_tag' => $query->getData('osm_tag'), 'limit' => $query->getLimit(), 'lang' => $query->getLocale(), ]); + $osmTagFilters = $this->buildOsmTagFilterQuery($query->getData('osm_tag')); + if (!empty($osmTagFilters)) { + $url .= $osmTagFilters; + } $json = $this->executeQuery($url); @@ -99,10 +102,13 @@ public function reverseQuery(ReverseQuery $query): Collection .http_build_query([ 'lat' => $latitude, 'lon' => $longitude, - 'osm_tag' => $query->getData('osm_tag'), 'limit' => $query->getLimit(), 'lang' => $query->getLocale(), ]); + $osmTagFilters = $this->buildOsmTagFilterQuery($query->getData('osm_tag')); + if (!empty($osmTagFilters)) { + $url .= $osmTagFilters; + } $json = $this->executeQuery($url); @@ -161,6 +167,25 @@ public function getName(): string return 'photon'; } + /** + * @param string|array|null $filters + */ + private function buildOsmTagFilterQuery($filters): string + { + $query = ''; + if (null === $filters) { + return $query; + } + if (is_string($filters)) { + return '&osm_tag='.urlencode($filters); + } + foreach ($filters as $filter) { + $query .= '&osm_tag='.urlencode($filter); + } + + return $query; + } + private function executeQuery(string $url): \stdClass { $content = $this->getUrlContents($url); diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_900b8b48594b267db76d84cfe7fd8b0ba4b927d6 b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_3c362ba852ee2323f9f25ca02c28cc5238959dbc similarity index 100% rename from src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_900b8b48594b267db76d84cfe7fd8b0ba4b927d6 rename to src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_3c362ba852ee2323f9f25ca02c28cc5238959dbc diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f3b7c730ba71e84b11ac92049cd31806186e0ef1 b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_8cd3447834c3ae8316dda602714b4ca4959eae65 similarity index 100% rename from src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f3b7c730ba71e84b11ac92049cd31806186e0ef1 rename to src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_8cd3447834c3ae8316dda602714b4ca4959eae65 diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f28b8c40cd259040dfbde8c3a179463de6a2ecc8 b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f28b8c40cd259040dfbde8c3a179463de6a2ecc8 new file mode 100644 index 000000000..166755be3 --- /dev/null +++ b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f28b8c40cd259040dfbde8c3a179463de6a2ecc8 @@ -0,0 +1 @@ +s:2263:"{"features":[{"geometry":{"coordinates":[2.3328439,48.8587571],"type":"Point"},"type":"Feature","properties":{"osm_id":4839163372,"country":"France","city":"Paris","countrycode":"FR","postcode":"75006","locality":"Saint-Germain-des-Prés","type":"house","osm_type":"N","osm_key":"tourism","street":"Promenade Marceline Loridan-Ivens","district":"Paris","osm_value":"artwork","name":"La Ville de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.418394477960865,48.8318844],"type":"Point"},"type":"Feature","properties":{"osm_id":26008116,"extent":[2.4141177,48.834668,2.4204695,48.8289812],"country":"France","city":"Paris","countrycode":"FR","postcode":"75012","locality":"Quartier du Bel-Air","type":"house","osm_type":"W","osm_key":"tourism","street":"Promenade Maurice-Boitel","district":"Paris","osm_value":"zoo","name":"Parc zoologique de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.345051233260165,48.85565735],"type":"Point"},"type":"Feature","properties":{"osm_id":536982,"extent":[2.3429677,48.856811,2.3462472,48.8544964],"country":"France","city":"Paris","countrycode":"FR","postcode":"75001","locality":"Quartier Saint-Germain-l'Auxerrois","type":"house","osm_type":"R","osm_key":"tourism","street":"Cour du Premier Président","district":"Paris","osm_value":"attraction","name":"Palais de Justice de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.2933072,48.870745],"type":"Point"},"type":"Feature","properties":{"osm_id":2990418382,"country":"France","city":"Paris","countrycode":"FR","postcode":"75116","locality":"Quartier de Chaillot","type":"house","osm_type":"N","osm_key":"tourism","street":"Avenue Kléber","district":"Paris","osm_value":"hotel","name":"The Peninsula Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.288981354650506,48.82872115000001],"type":"Point"},"type":"Feature","properties":{"osm_id":129135460,"extent":[2.2847236,48.8321689,2.2921187,48.8253682],"country":"France","city":"Paris","countrycode":"FR","postcode":"75015","locality":"Paris Expo Porte de Versailles","type":"house","osm_type":"W","osm_key":"tourism","district":"Paris","osm_value":"attraction","name":"Parc des Expositions de Paris","state":"Île-de-France"}}],"type":"FeatureCollection"}"; \ No newline at end of file diff --git a/src/Provider/Photon/Tests/PhotonTest.php b/src/Provider/Photon/Tests/PhotonTest.php index 85182948b..67b8962d1 100644 --- a/src/Provider/Photon/Tests/PhotonTest.php +++ b/src/Provider/Photon/Tests/PhotonTest.php @@ -111,6 +111,22 @@ public function testGeocodeQueryWithOsmTagFilter() } } + public function testGeocodeQueryWithMultipleOsmTagFilter() + { + $provider = Photon::withKomootServer($this->getHttpClient()); + $query = GeocodeQuery::create('Paris') + ->withData('osm_tag', ['tourism', ':!museum']) + ->withLimit(5); + $results = $provider->geocodeQuery($query); + + $this->assertCount(5, $results); + foreach ($results as $result) { + $this->assertInstanceOf(PhotonAddress::class, $result); + $this->assertEquals('tourism', $result->getOSMTag()->key); + $this->assertNotEquals('museum', $result->getOSMTag()->value); + } + } + public function testReverseQuery() { $provider = Photon::withKomootServer($this->getHttpClient()); From 0c4180a75a9c17a158d0cd78a707da5b96419ada Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Mon, 31 Jul 2023 16:13:35 +0200 Subject: [PATCH 08/12] More documentation about multiple osm tag filters --- src/Provider/Photon/Readme.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Provider/Photon/Readme.md b/src/Provider/Photon/Readme.md index 75f350f66..c3e5c637e 100644 --- a/src/Provider/Photon/Readme.md +++ b/src/Provider/Photon/Readme.md @@ -35,7 +35,6 @@ $reverseQuery = $provider->reverseQuery(\Geocoder\Query\ReverseQuery::fromCoordi You can search for location data based on osm tag filters. For example, you can filter a geocode query to only include results of type 'place'. You can even restrict it to only have places of type 'city'. - In the reverse geocoding context you can search for the 3 pharmacies closest to a location. To see what you can do with this feature, check [the official photon documentation](https://github.com/komoot/photon#filter-results-by-tags-and-values) @@ -43,13 +42,24 @@ To see what you can do with this feature, check [the official photon documentati Below is an example to query the 3 pharmacies closest to a location : ```php $provider = new Geocoder\Provider\Photon\Photon($httpClient, 'https://your-photon-root-url'); -$reverseQuery = ReverseQuery::fromCoordinates(52.51644, 13.38890) +$reverseQuery = \Geocoder\Query\ReverseQuery::fromCoordinates(52.51644, 13.38890) ->withData('osm_tag', 'amenity:pharmacy') ->withLimit(3); $results = $provider->reverseQuery($reverseQuery); ``` +You can combine multiple osm tag filters : +```php +$provider = new Geocoder\Provider\Photon\Photon($httpClient, 'https://your-photon-root-url'); +$reverseQuery = \Geocoder\Query\GeocodeQuery::create('Paris') + ->withData('osm_tag', ['tourism', ':!museum']) + ->withLimit(5); +// Here we get 5 tourism results in Paris which are not museums +$results = $provider->reverseQuery($reverseQuery); +``` + + ## Contribute Contributions are very welcome! Send a pull request to the [main repository](https://github.com/geocoder-php/Geocoder) or report any issues you find on the [issue tracker](https://github.com/geocoder-php/Geocoder/issues). From 724c11dec9eed0567c0b064b83956c7cefa88a4b Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Wed, 2 Aug 2023 09:44:48 +0200 Subject: [PATCH 09/12] Fix array type for phpstan analyse --- src/Provider/Photon/Photon.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Provider/Photon/Photon.php b/src/Provider/Photon/Photon.php index f45cdfe76..564b8a36f 100644 --- a/src/Provider/Photon/Photon.php +++ b/src/Provider/Photon/Photon.php @@ -168,7 +168,7 @@ public function getName(): string } /** - * @param string|array|null $filters + * @param string|array|null $filters */ private function buildOsmTagFilterQuery($filters): string { From 687fd763a3f4bb00815ee4b893c889eafa76fb4d Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Thu, 19 Dec 2024 10:43:36 +0100 Subject: [PATCH 10/12] Fix CS --- src/Provider/Photon/Tests/PhotonTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Provider/Photon/Tests/PhotonTest.php b/src/Provider/Photon/Tests/PhotonTest.php index c9cfcb631..9388398e4 100644 --- a/src/Provider/Photon/Tests/PhotonTest.php +++ b/src/Provider/Photon/Tests/PhotonTest.php @@ -60,7 +60,7 @@ public function testGeocodeQuery(): void $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Provider\Photon\Model\PhotonAddress $result */ + /** @var PhotonAddress $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEqualsWithDelta(48.8631927, $result->getCoordinates()->getLatitude(), 0.00001); @@ -89,7 +89,7 @@ public function testGeocodeQueryWithNamedResult(): void $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Provider\Photon\Model\PhotonAddress $result */ + /** @var PhotonAddress $result */ $result = $results->first(); $this->assertEquals('The Sherlock Holmes Museum and shop', $result->getName()); @@ -136,7 +136,7 @@ public function testReverseQuery(): void $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); $this->assertCount(1, $results); - /** @var \Geocoder\Provider\Photon\Model\PhotonAddress $result */ + /** @var PhotonAddress $result */ $result = $results->first(); $this->assertInstanceOf('\Geocoder\Model\Address', $result); $this->assertEqualsWithDelta(51.9982968, $result->getCoordinates()->getLatitude(), 0.00001); From b21dfe438e19c60fb9411e88147b76e64e3146db Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Thu, 2 Jan 2025 16:30:35 +0100 Subject: [PATCH 11/12] Update tests for multiple osm tags --- ...t.io_f02c930445a15eb88482c0cc3c22a782c9ee6005 | 1 + ...t.io_f28b8c40cd259040dfbde8c3a179463de6a2ecc8 | 1 - src/Provider/Photon/Tests/PhotonTest.php | 16 ++++++++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f02c930445a15eb88482c0cc3c22a782c9ee6005 delete mode 100644 src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f28b8c40cd259040dfbde8c3a179463de6a2ecc8 diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f02c930445a15eb88482c0cc3c22a782c9ee6005 b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f02c930445a15eb88482c0cc3c22a782c9ee6005 new file mode 100644 index 000000000..d23d4a4ec --- /dev/null +++ b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f02c930445a15eb88482c0cc3c22a782c9ee6005 @@ -0,0 +1 @@ +s:4208:"{"features":[{"geometry":{"coordinates":[2.2978602225671843,48.8643133],"type":"Point"},"type":"Feature","properties":{"osm_id":79219308,"extent":[2.2971088,48.8647083,2.2984772,48.8639024],"country":"France","city":"Paris","countrycode":"FR","postcode":"75116","locality":"Chaillot","type":"house","osm_type":"W","osm_key":"tourism","street":"Rue Gaston de Saint-Paul","district":"Paris","osm_value":"museum","name":"Musée d'Art Moderne de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3153496472839956,48.866042],"type":"Point"},"type":"Feature","properties":{"osm_id":2778854,"extent":[2.3143339,48.866628,2.3156049,48.8654594],"country":"France","city":"Paris","countrycode":"FR","postcode":"75008","locality":"Quartier des Champs-Élysées","type":"house","osm_type":"R","osm_key":"tourism","street":"Avenue Winston Churchill","district":"Paris","osm_value":"museum","name":"Musée des beaux-arts de la Ville de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3518758,48.850724],"type":"Point"},"type":"Feature","properties":{"osm_id":237003117,"country":"France","city":"Paris","countrycode":"FR","postcode":"75005","locality":"Quartier Saint-Victor","type":"house","osm_type":"N","osm_key":"tourism","street":"Quai de la Tournelle","district":"Paris","osm_value":"museum","name":"Musée de l'Assistance Publique Hôpitaux de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3450724,48.8640506],"type":"Point"},"type":"Feature","properties":{"osm_id":3087374948,"country":"France","city":"Paris","countrycode":"FR","postcode":"75001","locality":"Les Halles","type":"house","osm_type":"N","osm_key":"tourism","street":"Rue du Jour","district":"Paris","osm_value":"museum","name":"Musée du Barreau de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3453019,48.8625016],"type":"Point"},"type":"Feature","properties":{"osm_id":1028569468,"country":"France","city":"Paris 1er Arrondissement","countrycode":"FR","postcode":"75001","locality":"Les Halles","type":"house","osm_type":"N","osm_key":"tourism","street":"Rue du cinéma","district":"Paris","osm_value":"museum","name":"Salle des collections","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3587471,48.865943],"type":"Point"},"type":"Feature","properties":{"osm_id":5275610309,"country":"France","city":"Paris","countrycode":"FR","postcode":"75003","locality":"Quartier des Arts-et-Métiers","type":"house","osm_type":"N","osm_key":"tourism","street":"Rue de Turbigo","district":"Paris","osm_value":"gallery","name":"Paris-B","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3314642,48.881227],"type":"Point"},"type":"Feature","properties":{"osm_id":10677716841,"country":"France","city":"Paris","countrycode":"FR","postcode":"75009","locality":"Quartier Saint-Georges","type":"house","osm_type":"N","osm_key":"tourism","street":"Rue Blanche","district":"Paris","osm_value":"gallery","name":"Mu Gallery Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3736064,48.8623128],"type":"Point"},"type":"Feature","properties":{"osm_id":10130759032,"country":"France","city":"Paris","countrycode":"FR","postcode":"75011","locality":"Quartier Saint-Ambroise","type":"house","osm_type":"N","osm_key":"tourism","street":"Rue Saint-Sébastien","district":"Paris","osm_value":"gallery","name":"Paris-New York","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3644211,48.8602831],"type":"Point"},"type":"Feature","properties":{"osm_id":3210924575,"country":"France","city":"Paris","countrycode":"FR","postcode":"75003","locality":"Quartier des Archives","type":"house","osm_type":"N","osm_key":"tourism","street":"Rue Debelleyme","district":"Le Marais","osm_value":"gallery","name":"lecœur-paris.com","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3525427,48.86361],"type":"Point"},"type":"Feature","properties":{"osm_id":10744217145,"country":"France","city":"Paris","countrycode":"FR","postcode":"75003","locality":"Quartier Sainte-Avoye","type":"house","osm_type":"N","osm_key":"tourism","street":"Rue Saint-Martin","district":"Paris","osm_value":"gallery","name":"Galerie Paris Horizon","state":"Île-de-France"}}],"type":"FeatureCollection"}"; \ No newline at end of file diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f28b8c40cd259040dfbde8c3a179463de6a2ecc8 b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f28b8c40cd259040dfbde8c3a179463de6a2ecc8 deleted file mode 100644 index 166755be3..000000000 --- a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_f28b8c40cd259040dfbde8c3a179463de6a2ecc8 +++ /dev/null @@ -1 +0,0 @@ -s:2263:"{"features":[{"geometry":{"coordinates":[2.3328439,48.8587571],"type":"Point"},"type":"Feature","properties":{"osm_id":4839163372,"country":"France","city":"Paris","countrycode":"FR","postcode":"75006","locality":"Saint-Germain-des-Prés","type":"house","osm_type":"N","osm_key":"tourism","street":"Promenade Marceline Loridan-Ivens","district":"Paris","osm_value":"artwork","name":"La Ville de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.418394477960865,48.8318844],"type":"Point"},"type":"Feature","properties":{"osm_id":26008116,"extent":[2.4141177,48.834668,2.4204695,48.8289812],"country":"France","city":"Paris","countrycode":"FR","postcode":"75012","locality":"Quartier du Bel-Air","type":"house","osm_type":"W","osm_key":"tourism","street":"Promenade Maurice-Boitel","district":"Paris","osm_value":"zoo","name":"Parc zoologique de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.345051233260165,48.85565735],"type":"Point"},"type":"Feature","properties":{"osm_id":536982,"extent":[2.3429677,48.856811,2.3462472,48.8544964],"country":"France","city":"Paris","countrycode":"FR","postcode":"75001","locality":"Quartier Saint-Germain-l'Auxerrois","type":"house","osm_type":"R","osm_key":"tourism","street":"Cour du Premier Président","district":"Paris","osm_value":"attraction","name":"Palais de Justice de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.2933072,48.870745],"type":"Point"},"type":"Feature","properties":{"osm_id":2990418382,"country":"France","city":"Paris","countrycode":"FR","postcode":"75116","locality":"Quartier de Chaillot","type":"house","osm_type":"N","osm_key":"tourism","street":"Avenue Kléber","district":"Paris","osm_value":"hotel","name":"The Peninsula Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.288981354650506,48.82872115000001],"type":"Point"},"type":"Feature","properties":{"osm_id":129135460,"extent":[2.2847236,48.8321689,2.2921187,48.8253682],"country":"France","city":"Paris","countrycode":"FR","postcode":"75015","locality":"Paris Expo Porte de Versailles","type":"house","osm_type":"W","osm_key":"tourism","district":"Paris","osm_value":"attraction","name":"Parc des Expositions de Paris","state":"Île-de-France"}}],"type":"FeatureCollection"}"; \ No newline at end of file diff --git a/src/Provider/Photon/Tests/PhotonTest.php b/src/Provider/Photon/Tests/PhotonTest.php index 9388398e4..1148341d7 100644 --- a/src/Provider/Photon/Tests/PhotonTest.php +++ b/src/Provider/Photon/Tests/PhotonTest.php @@ -115,16 +115,24 @@ public function testGeocodeQueryWithMultipleOsmTagFilter(): void { $provider = Photon::withKomootServer($this->getHttpClient()); $query = GeocodeQuery::create('Paris') - ->withData('osm_tag', ['tourism', ':!museum']) - ->withLimit(5); + ->withData('osm_tag', ['tourism:museum', 'tourism:gallery']) + ->withLimit(10); $results = $provider->geocodeQuery($query); - $this->assertCount(5, $results); + $this->assertCount(10, $results); + $countMuseums = $countGalleries = 0; foreach ($results as $result) { $this->assertInstanceOf(PhotonAddress::class, $result); $this->assertEquals('tourism', $result->getOSMTag()->key); - $this->assertNotEquals('museum', $result->getOSMTag()->value); + $this->assertContains($result->getOSMTag()->value, ['museum', 'gallery']); + if ('museum' === $result->getOSMTag()->value) { + ++$countMuseums; + } elseif ('gallery' === $result->getOSMTag()->value) { + ++$countGalleries; + } } + $this->assertGreaterThan(0, $countMuseums); + $this->assertGreaterThan(0, $countGalleries); } public function testReverseQuery(): void From 256464e51dcd4615fd350dae11f69a4b2055e1cd Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Thu, 2 Jan 2025 16:45:23 +0100 Subject: [PATCH 12/12] Documentation for multiple osm tags --- src/Provider/Photon/Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Provider/Photon/Readme.md b/src/Provider/Photon/Readme.md index c3e5c637e..c684245f7 100644 --- a/src/Provider/Photon/Readme.md +++ b/src/Provider/Photon/Readme.md @@ -53,9 +53,9 @@ You can combine multiple osm tag filters : ```php $provider = new Geocoder\Provider\Photon\Photon($httpClient, 'https://your-photon-root-url'); $reverseQuery = \Geocoder\Query\GeocodeQuery::create('Paris') - ->withData('osm_tag', ['tourism', ':!museum']) + ->withData('osm_tag', ['tourism:museum', 'tourism:gallery']) ->withLimit(5); -// Here we get 5 tourism results in Paris which are not museums +// Here we get 5 tourism results in Paris which are either museum or art gallery $results = $provider->reverseQuery($reverseQuery); ```