I'm trying to extract GPS points on roads in a region. For each road, I need a GPS point on that road every 10 meters.

I'm aware that Google Map API offer such way points, but due to the latency-sensitive nature of this application and amount of data needed, I cannot afford to do network communications to Google server.

I came across OSM but as someone new, it's very unclear how I can extract GPS points on roads from OSM. I know roads are stored as "line string" with keyword "highway".

Some GeoJSON file includes start and end gps locations for each road but how do I extract all GPS points (Lat,Lng) along the road?

  • There is an API overpass-turbo.eu/s/bPX click run and then export to geojson, if your using postgis you might need to do a SELECT roads and ST_AsGeoJSON to get the geometry in a useful format postgis.net/docs/ST_AsGeoJSON.html
    – Mapperz
    Oct 5, 2015 at 17:24
  • Thank you so much Mapperz. That's a wonderful API. But it seems that it only outputs a few points along the road. Any suggestions on how I can calculate other points, especially for roads that are not straight?
    – James
    Oct 5, 2015 at 17:35
  • 2
    crosspost: stackoverflow.com/questions/32953708/…
    – scai
    Oct 5, 2015 at 19:50
  • Can you please post me a link to the mentioned Google Map API service? I cannot find it. Thx Oct 31, 2021 at 18:40
  • @scai The question in your link has been deleted by the wonderful SO moderators. Any update available? Oct 31, 2021 at 18:43

1 Answer 1


In my answer here I use a query to create points along lines with a distinct distance

WITH line AS 
        (ST_Dump(geom)).geom AS geom
    FROM your_polylinestring_table),
linemeasure AS
        ST_AddMeasure(line.geom, 0, ST_Length(line.geom)) AS linem,
        generate_series(0, ST_Length(line.geom)::int, 10) AS i
    FROM line),
geometries AS (
        (ST_Dump(ST_GeometryN(ST_LocateAlong(linem, i), 1))).geom AS geom 
    FROM linemeasure)

        ST_SetSRID(ST_MakePoint(ST_X(geom), ST_Y(geom)), 31468) AS geom
    FROM geometries

So, obviously you are using a PostGIS/PostgreSQL database, You can import OSM data (with osm2pgsql, osmosis, etc.).

Important is an unique ID. You can use the osm_id coming along when you import the OSM data.

When you have data in geojson format you can use the postgis function ST_GeomFromGeoJSON. Another way: Here is a howTo to convert geojson data to a shapefile. The shapefile you can easily import to postgres/postgis with gdal/ogr, pgadmin or QGIS.

After that you can export your point data as GPX with ogr2ogr. The comments for this GIS SE answer have some useful Information.

ogr2ogr -f GPX points.gpx PG:'host=server user=username dbname=database'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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