Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

Looking for all points in a square around a given point in PostGIS

$
0
0

For a given point (x,y), I would like to find all the points in the neighborhood (defined by myRadius, a number, in meters).

For now, I’m using a circle around each point, but some reason, I’d like to draw a square around each point instead of a circle (square in the orientation of x-y coordinates).

Command I use for the circle (distance):

SELECT * FROM table_of_points WHERE (ST_Transform(the_geom,21781) && ST_expand(ST_SetSRID(ST_GeomFromText('Point(x y)'), 21781), myRadius )

For the square, can I use:

SELECT * FROM table_of_points WHERE (ST_Transform(the_geom,21781) && ST_MakeEnvelope(x-myRadius, y-myRadius, x+myRadius, y+myRadius, 21781 ) )

It works, but I’m just wondering if it’s the fastest way of doing this.


Viewing all articles
Browse latest Browse all 1138

Trending Articles