P
P
Pavel2020-02-25 11:05:51
PostgreSQL
Pavel, 2020-02-25 11:05:51

How to get points within a given area in PostGIS?

I have a table with places. The table has a column coordinates of type geography(POINT), coordinates from Google maps.
The task is to select places that are included in a certain area on the map (a section of Google maps visible on the front).

From the front, they send me the coordinates of the lower left and upper right corners, theoretically, you can try to get all four.

I can't figure out the postgis docs.. I looked at the ST_Contains and ST_CoveredBy functions, but somehow I didn't really understand.. the examples in the docs are not very clear. Or maybe he didn't look.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-02-25
@Palych_tw

From these coordinates of the corners, draw a line. Then look for the intersection of the enclosing rectangles for the given line and your points.

SELECT * FROM table WHERE geom && 'LINESTRING(0 0, 3 3)'::geometry

P.S. don't forget to specify the coordinate system correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question