I have a table called as events. events has a column of point datatype. (x,y) = (latitude,longitude) for the point. Now, I have an another set of points whose latitude and longitude are known. Now, I want to form a polygon of these points and then want to know how many event points are present in this polygon. I am not able to formulate the query.

I tried using

ST_AsText(ST_PointOnSurface('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'::geometry)); 

But couldn't find the answer.

  • You'll make it easier for us to help you if you add some sample data. FWIW I think your query will involve st_geomfromtext for your polygons and st_contains. Try something with those, and if you're still stuck post your attempt. – mlinth Nov 15 '16 at 12:55

You will need to incorporate ST_Point to create a geometry from your LatLong and ST_Intersects to determine which points intersect the polygon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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