0

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 1

1

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)
  )
1
  • I'm trying to show the linestring in the resulting map, can you just add LineString to the SELECT portion to show that?
    – user28674
    Aug 11, 2014 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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