Get points inside bounding box

I am trying to select places from my postgis db that are within a specific bounding box. I am trying to accomplish this with this query:

//latlong - latitude, longitude of a place

SELECT * FROM places WHERE St_Contains(St_GeomFromText('Polygon((:top_left_long :top_left_lat, :bottom_right_long :bottom_right_lat))'), latlong);

First of all, I get the following error:

 Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: :top_left_lat 

What does it mean? And the second problem - am I feeding these parameters correctly? I mean first longitude, then latitude?

+3
source share
3 answers

Here is the query I used in the old project:

SELECT param1, param2, ... 
FROM messages 
WHERE ST_Contains( 
    ST_SetSRID(
        ST_MakeBox2D(
            ST_Point(0, 50), ST_Point(50,0)
        ), 
        4326
    ), 
    the_geom
)

the_geom was my geometry column Note. MakeBox2D occupies the top left and bottom right

+6
source

With these arguments, you cannot build a polygon.

A - , 1 0 . . - 3- .

LinearRing "" , , . LinearRings "".

(, ):

a) :

b) , ;

c) , ,

( OpenGIS - - 1: )

ou box2d, , .

:

  • , St_GeomFromText
  • ST_SetSRID, , .
+1

I think, because :top_left_longother parameters are not replaced by your values.

Can you print the SQL query before executing?

0
source

All Articles