Is it possible to return the posted speed and number of lanes of a highway segment using Google Maps API, OSM data, or any other stream (paid for or free)?
-
Specifically for OSM, are you looking for a way using an OSM API or downloaded OSM data ?– WillCommented Apr 5, 2013 at 18:54
-
@Will. I'm open to both, preferably be able to use the API; however, I have no issues whatsoever if I can download the data to myserver and use that– dassoukiCommented Apr 5, 2013 at 21:27
-
from the OSM website (openstreetmap.org) you can always export the area of interest in XML and take out the info on the type of road and speed limit. but i am not sure this is how you want to do this.– Gago-SilvaCommented Apr 6, 2013 at 18:35
1 Answer
I will give you a method using downloaded OSM data, as the API is designed for editing and not for read-only. You will find more details on this on the API usage policy page of the OSM wiki. If you really want to use an API, you can look at the read-only APIs like the Overpass API. Several other methods could also work, depending on how you will use this data and which tools you like most.
- Download OSM data for you area of interest. Use Geofabrik if the area is big, or the OSM website export tab if your area is small (a city or less).
- Put all this data in PostGIS :
- Install osm2pgsql and find the default.style file (on Ubuntu : /usr/share/osm2pgsql/default.style)
- Copy this default.style, save it as yourdefault.style and edit it to add the following lines so you can retrieve the lanes and maxspeed from OSM:
way lanes text linear way maxspeed text linear
- Run the following (this is for Ubuntu but should be very similar on Windows):
sudo su postgres createdb gis psql -d gis -c "CREATE EXTENSION postgis;" psql gis -c "ALTER TABLE geometry_columns OWNER TO postgres" psql gis -c "ALTER TABLE spatial_ref_sys OWNER TO postgres" osm2pgsql -s --style /path/yourdefault.style -W -U postgres -d gis /file/path/toosm/fileorpbf/name.osm
- You can now run any query you want on the gis database to get the maxspped and number of lanes of a road segment
Important note: this is a technical method, but there is no guarantee that the speed and number of lanes are present in OSM for the highways you are interested in.