3

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 this wonderful opensource map data. But as a newbie, 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 '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 5 '15 at 17:35
  • 2
    crosspost: stackoverflow.com/questions/32953708/… – scai Oct 5 '15 at 19:50
2

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'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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