4

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?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
James
  • 143
  • 1
  • 3
  • There is an API http://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 http://postgis.net/docs/ST_AsGeoJSON.html – Mapperz Oct 05 '15 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 05 '15 at 17:35
  • 2
    crosspost: https://stackoverflow.com/questions/32953708/how-to-get-gps-points-on-a-road-from-osm-data – scai Oct 05 '15 at 19:50
  • Can you please post me a link to the mentioned Google Map API service? I cannot find it. Thx – Peter VARGA Oct 31 '21 at 18:40
  • @scai The question in your link has been deleted by the wonderful SO moderators. Any update available? – Peter VARGA Oct 31 '21 at 18:43

1 Answers1

4

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

WITH line AS 
    (SELECT
        your_polylinestring_id,
        (ST_Dump(geom)).geom AS geom
    FROM your_polylinestring_table),
linemeasure AS
    (SELECT
        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 (
    SELECT
        i,
        (ST_Dump(ST_GeometryN(ST_LocateAlong(linem, i), 1))).geom AS geom 
    FROM linemeasure)

    SELECT
        i,
        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'
Stefan
  • 4,414
  • 1
  • 33
  • 66