[postgis-users] Finding points of intersection of a linestring with another multiolygon and linestring

Trang Nguyen Trang.Nguyen at inrix.com
Wed Sep 30 22:27:41 PDT 2015

Hi forum,

I have a LINESTRING represent the waypoints of a trip through road segments (LINESTRING) and zones (MULTIPOLYGON).
For each segment and zone, I would like to find out the points in the waypoints  which intersected the targeted zone/segment geometries. First and last intersection point into and exiting the zone or segment  would the sufficient as well.
I can use st_intersection to find the intersection each of waypoints to segment and zone geometries, but this returns a geometry that doesn't necessarily contain the subset of intersecting points in the linestring. The query will be run on large datasets, so performance is an important consideration. GIST indexes exist on all the geometries joined (zone_geom, segment_geom and waypoints).

st_transform(st_intersection(segment_geom, waypoints),4326) seg_wp_intersection, -- need subset of points in waypoints that intersected with segment_geom
st_transform(st_intersection(zone_geom, waypoints),4326)  zone_wp_intersection,  -- need subset of  points in waypoints that intersected with zone_geom
trip_id, waypoints, zone_id, segment_id
from od1.v_trip_zone_segment
startts>=TIMESTAMP '2015-01-16T12:20:29.000Z' and startts<TIMESTAMP '2015-01-16T17:20:30.000Z' and endts<TIMESTAMP '2015-01-16T17:20:30.000Z' and zone_id in ('kansas_303','kansas_601','kansas_603','kansas_604','kansas_10','kansas_11','kansas_9','kansas_310','kansas_311','kansas_315','kansas_301','kansas_302','kansas_307','kansas_306','kansas_305','kansas_204','kansas_201','kansas_3','kansas_2','kansas_1') and segment_id in ('5062926','5062931','5062932','4062933','5055496','5063065','5062826','5062825','5062824','5062643','5062644','5062645','5062646','5055551','5062839','5062849','5062895','5063081') and segment_mapversion='1501'
and st_intersects(segment_geom, waypoints)
and st_intersects(szone_geom, waypoints)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20151001/5aeae351/attachment.html>

More information about the postgis-users mailing list