I have a polygon and I want to get all the points inside from a georeference table.

What is the SQL for that?

For example, obtain all the lat/long records that are inside the department ZZ polygon.

  • 4
    What have you tried so far? What are the table names, and what do the geometry values look like? Please edit the question to clarify. You'll also want the polygon to contain points, or have points contained by a polygon.
    – Vince
    Mar 3 '15 at 19:48
  • It would be easier to load the data into qgis and do a spatial query.
    – Mapperz
    Mar 3 '15 at 19:58

Much easier if you post your table structure and what you've tried so far, but here goes.

Assuming you have a table points with a column point of type geometry, and a table polygons with a column polygon of type geometry:

points p
polygons y
ON ST_CONTAINS(y.geometry, p.geometry)
WHERE y.department = 'ZZ'

If your points don't have geometry, but lon / lat columns, you can do ST_POINT(lon,lat) to convert them to geometry.

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