tombrennan06 / ozultimate-maps

MIT License
4 stars 1 forks source link

FEATURE REQUEST: Integrate feature search using API from national gazetter #1

Open gangerang opened 3 years ago

gangerang commented 3 years ago

Allow searching by place name to take user to the location of that place

Make use of the API which powers https://placenames.fsdf.org.au/

EG, searching for Kanangra Boyd NP location.

Input1 (search for 'kanangra')

https://api.placenames.fsdf.org.au/select?rows=50&fl=recordId,name,authorityId&q=kanangra&wt=json&fq=location:%5B-41.92417286830545,143.80527924278158%20TO%20-29.25407508748927,151.6746667233753%5D

Output1 (Identified as record NSW_25812) {"responseHeader":{"status":0,"QTime":0,"params":{"q":"kanangra","fl":"recordId,name,authorityId","fq":"location:[-41.92417286830545,143.80527924278158 TO -29.25407508748927,151.6746667233753]","rows":"50","wt":"json"}},"response":{"numFound":12,"start":0,"docs":[{"recordId":"NSW_25812","authorityId":"25812","name":"Kanangra-Boyd National Park"},{"recordId":"NSW_25813","authorityId":"25813","name":"Kanangra Brook"},{"recordId":"NSW_25815","authorityId":"25815","name":"Kanangra Creek"},{"recordId":"NSW_25816","authorityId":"25816","name":"Kanangra Falls"},{"recordId":"NSW_25817","authorityId":"25817","name":"Kanangra Gorge"},{"recordId":"NSW_25819","authorityId":"25819","name":"Kanangra Range"},{"recordId":"NSW_25820","authorityId":"25820","name":"Kanangra Reserve"},{"recordId":"NSW_25821","authorityId":"25821","name":"Kanangra Tops"},{"recordId":"NSW_25822","authorityId":"25822","name":"Kanangra Walls"},{"recordId":"NSW_25823","authorityId":"25823","name":"Kanangra Walls"},{"recordId":"NSW_75262","authorityId":"75262","name":"Kanangra"},{"recordId":"NSW_79877","authorityId":"79877","name":"Kanangra Pass"}]}}

Input2 (Search for record NSW_25812)

https://api.placenames.fsdf.org.au/select?q=recordId:NSW_25812&fq=location:%5B-37.54522085954277,146.75320600459875%20TO%20-32.98523486563149,154.5060598270132%5D&sort=geodist(ll,-35.26522786258713,150.62963291580598)%20asc&rows=1&wt=json

Output2 (returns lat lon) {"responseHeader":{"status":0,"QTime":0,"params":{"q":"recordId:NSW_25812","fq":"location:[-37.54522085954277,146.75320600459875 TO -32.98523486563149,154.5060598270132]","sort":"geodist(ll,-35.26522786258713,150.62963291580598) asc","rows":"1","wt":"json"}},"response":{"numFound":1,"start":0,"docs":[{"location":"150.0845093 -33.99843344","recordId":"NSW_25812","authorityId":"25812","name":"Kanangra-Boyd National Park","feature":"PARK","category":"COMMUNITY FACILITY","group":"CULTURE","authority":"NSW","supplyDate":"2021-07-13T02:06:29Z","ll":"150.0845093 -33.99843344","version":1714959124634009607}]}}

tombrennan06 commented 3 years ago

Tricky one.

  1. The API doesn't allow cross-origin requests, so any application needs to proxy the API locally. That can be done via a basic PHP proxy like https://github.com/softius/php-cross-domain-proxy/

  2. Ideally, both the names and location get returned in one query, rather than a two-stage query. A bit of guesswork, and that can be done via https://api.placenames.fsdf.org.au/select?rows=50&fl=recordId%2Cname%2CauthorityId%2Cfeature%2Clocation&q=kanangra+AND+%28authority%3A%22NSW%22%29&wt=json

  3. Last issue is that the API breaks down once you get past one word. This is an issue even in the Gazetteer. So anything using more common words (eg First Ascent Creek) is a problem. Actually, just found the key to this - double quotes around the query string (had already tried single quotes). https://api.placenames.fsdf.org.au/select?rows=50&fl=recordId%2Cname%2CauthorityId%2Cfeature&q=%22first%20asc%22+AND+%28authority%3A%22NSW%22%29&wt=json

So after all that, there's a placeholder version at https://maps.ozultimate.com/archive/test/ with the changes. Needs some tidying up but probably close to being production-isable.

gangerang commented 3 years ago

Wow, that seems to work pretty well, top stuff!

Only comment would be that it seems to be doing a search like this "[search string]%". I'd guess that "%[search string]%" might be more useful. Eg, when searching for 'Kanangra', you might want to find 'Mount Kanangra' and not just 'Kanangra Tops', 'Kanangra Walls' etc. But it seems like it could be a limitation of the API.

tombrennan06 commented 3 years ago

If you can work out how to get more out of the API, then I can probably integrate it.

According to the Help: "The search field can be used for matching features on partial or like name." But I can't see how to do "like" matching.

Beyond the help, there was some interesting stuff under https://link.fsdf.org.au/fsdf-theme/place-names including https://ecat.ga.gov.au/geonetwork/srv/eng/catalog.search#/metadata/76695