-2

I'd like to write some JavaScript code which works out whether a given set of coordinates is contained within a particular UK local authority. I've been looking around, and this seems like the right approach.

I draw a polygon, and strike a line through my user's geolocation. If it crosses the lines of the polygon an even number of times, it's outside. If it does so an odd number of times, it's inside.

The problem is UK counties are usually formed of natural borders like hills and rivers. They aren't tidy polygons with straight sides. That means arbitrary rectangles which fit the counties inside them will end up including a lot of area which is outside the county I am trying to target.

So, where can I find/generate a description of the county borders in lat, long points?

  • 1
    Look for the boundary line dataset and a geographical library like turf.js to handle the point in polygon query. – Ian Turton Mar 8 at 17:59
  • 1
    Do you want counties, local authorities, unitary authorities, NUTS level 2 regions, ceremonial counties, postcode areas... UK geography is complex - do a bit of research with google and you can find boundary files for all these online. – Spacedman Mar 8 at 18:16
  • Boundary-Line™ ordnancesurvey.co.uk/business-and-government/products/…? Great Britain only (Not UK) – Mapperz Mar 9 at 3:26
0

ONS Geography provide a helpful visual summary of UK statistical geographies to help you decide which boundaries you need.

https://twitter.com/ONSgeography?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor

You can then use the ONS geography portal

http://geoportal.statistics.gov.uk/datasets?q=Administrative%20Boundaries&sort=name

or Ordnance Survey BoundaryLine data to get the polygons.

There are generalised boundaries which are less accurate, but which come in smaller files and are fine for display purposes or more accurate boundaries which give more accurate results for spatial queries (but have larger file sizes).

There is a bit of a learning curve if you're not used to the way UK admin areas are constructed and haven't used the datasets before, but you'll get there with trial and error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.