I have a GeoJSON polygon, and a table with lots of points. I want to SELECT
all points that are within an arbitrary GeoJSON polygon.
How can I do that with PostGIS SQL?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI have a GeoJSON polygon, and a table with lots of points. I want to SELECT
all points that are within an arbitrary GeoJSON polygon.
How can I do that with PostGIS SQL?
You need a ST_GeomFromGeoJSON
select *
from points p
where ST_Within(
p.geom,
ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[...]}')
)
Edit: ST_Intersects
works also (need to set SRID
on GeoJSON, and transform):
select row_to_json(t)
from (select * from table
where st_intersects(
st_transform(
st_setsrid(
ST_geomfromgeojson('{"type":"Polygon","coordinates":[...]}'),
4326),
3857),
table.geom)) as t;
FROM select * from table
, I want to do FROM (select * from table where height>1500) as sub
- but this doesn't work. Why?