This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Getting state names a route goes through

1

Hello,

I was hoping someone could please help.

I need to collect data for a project i have which looks at all the states a route goes through.

For example going from Jacksonville Florida to Lexington Kentucky the route would go through: Georgia Tennessee

I have over 100 routes and to look and write down each state a route goes through manually wouldn't be time effective so i wanted to see if there's a better way.

Is there a way i am able to get an output of this data from this site or another site base on the different origin and destination i have please?

I would be grateful for your help, suggestion and guidance.

Thank you.

asked 28 Jul '21, 04:51

Studnt123's gravatar image

Studnt123
26112
accept rate: 0%


One Answer:

4

If you are looking for web service that magically solves your problem - I'm afraid I don't know any.

What needs to be done is:

  • download the routes from a suitable routing engine, ideally in GeoJSON format (observe potential usage policies - but 100 routes, if queried with a little delay, shouldn't be an issue
  • prepare a data set with state boundaries - you can get them from OSM but it's probably easier to find a shape file on a random web site
  • have the computer detect which state polygons intersect with the route

One way to automate this is loading your routes and state boundaries into a PostGIS database. Then (let's assume you have loaded the routes with an ID into a "routes" table and the states with their names into a "states" table) the database can do the work for you with a simple query like

SELECT routes.id, states.name
FROM routes, states
WHERE ST_Intersects(routes.geom, states.geom)
ORDER BY routes.id;

answered 28 Jul '21, 11:31

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

Thank you very much for your suggestion and advice!

I appreciate it!

(29 Jul '21, 04:37) Studnt123

Source code available on GitHub .