I'm attempting to create a simple process with CartoDB, I have a layer with number of polygons, I want to to run a SQL with a multipoint line to report which polygons were intersected.
1 Answer
It is a simple SQL statement,
SELECT * FROM table_name WHERE ST_Intersects(the_geom, your_line_string)
Replace your_line_string with whatever way you want to supply the geometry. Two nice ways are either as WKT or as a GeoJSON text string.
First WKT
SELECT * FROM table_name
WHERE
ST_Intersects(
the_geom,
ST_GeomFromText('LINESTRING(-160 -23.5, 160 -23.5)',4326)
)
Second GeoJSON
SELECT * FROM table_name
WHERE
ST_Intersects(
the_geom,
ST_SetSRID(
ST_GeomFromGeoJSON('{ "type": "LineString","coordinates": [ [-160, -23.5], [160, -23.5] ] }'),4326)
)
-
I'm trying to show the linestring in the resulting map, can you just add LineString to the SELECT portion to show that? Aug 11, 2014 at 18:12