K
K
Kirill Ivanov2017-06-05 23:09:40
PostgreSQL
Kirill Ivanov, 2017-06-05 23:09:40

How to determine whether a point belongs to a polygon in postgresql?

Good afternoon. A difficulty arose. Help decide. I have a table (point) in which the coordinates of points (geometry) are stored. There is also a second table (borough) that stores the coordinates of the polygons (geom). The next question is: Calculate for each polygon, the number of points lying in it. I know to use one of the following ST_Within or ST_Contains functions. But unfortunately I can not figure it out ((
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Damir Makhmutov, 2017-06-05
@doodoo

Probably something like this: sqlfiddle.com/#!15/415f5/9

F
freeExec, 2017-06-06
@freeExec

SELECT id, 
       (SELECT COUNT(*) FROM point AS b WHERE ST_Within(points.geometry, borough.geometry)) AS count,
       name
  FROM borough

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question