Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Limit results by radius around lat/lon #77

Open
RamRaider opened this issue Feb 19, 2017 · 2 comments
Open

Limit results by radius around lat/lon #77

RamRaider opened this issue Feb 19, 2017 · 2 comments
Assignees

Comments

@RamRaider
Copy link

It appears that ALL results are returned from queries such as

//data.gov.uk/data/api/service/health/hospitals/nearest?lat=52.64105830207872&lon=1.032092571258545

which seems pointless as the returned data is much larger than it needs to be. Is there or can there be a distance limiting parameter - ie

//data.gov.uk/data/api/service/health/hospitals/nearest?lat=52.64105830207872&lon=1.032092571258545&radius=20

etc??

In the API documentation it states there is the ability to query the database directly by crafting the sql and appending to the endpoint url - but it is unclear how one would use this approach to achieve the desired distance limit mentioned.

@rossjones
Copy link
Contributor

rossjones commented Feb 21, 2017

Yes, limiting and radius and paging are all things that need doing. There's no support for radius at present, although theoretically it's just a case of using ST_Distance_Sphere in this case it's a little more complicated.

In the meantime, so you can keep your resultsets small you could go to https://data.gov.uk/data/api/health#sql and try the following query

select * from hospitals 
order by ST_Distance(LatLong, ST_SetSRID(ST_MakePoint(52.64105830207872, 1.032092571258545), 4326))
limit 10;

If you then click download as json you should have the URL to use.
Obviously it isn't as useful as radius, but it might help you progress in the meantime.

@RamRaider
Copy link
Author

:) Brilliant - thanks for the useful response and code! I shall give the example sql a try and see how I get on with that approach

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants