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
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.