I have a number of pedestrian trajectories (green) that I would like to snap to the nearest road (brown). The roads are downloaded from OpenStreetMap and have been dissolved by name with
CREATE TABLE dissolved AS
SELECT osm_roads.name, ST_Union(osm_roads.geom) FROM osm_roads GROUP BY osm_roads.name;
Now I am left with two tables - dissolved
and trajectories
My goal is first, to snap each trajectory to the nearest road and then, find the "mileage" walked along each road by
ST_LENGTH(ST_Intersection(dissolved.geom, snapped.geom))
How would I perform the first part of the query - snapping each individual trajectory to the nearest road - with ST_Snap
- and then group ST_LENGTH(ST_Intersection())
by road name?
CREATE TABLE snapped AS SELECT ST_Snap(trajectories, dissolved, ST_Distance(trajectories, dissolved)*1.25) from (SELECT september.wkb_geometry as trajectories, dissolved.st_union as dissolved)
but this throws an errorST_Snap
, how can I ultimately calculate the distance of each trajectory along certain roads? Each trajectory can be broken down to segments which are closest to a particular road. Then the lengths of segments can be added up and grouped by road, but I have no idea where to start