olga-in-space
olga-in-space

Reputation: 11

How to get points in bounding box by degrees for map

I have some concerns about working of BOX3D PostGIS function. I tried to find places in square -158.721365889063 66.09275164148659, 154.608712235937 52.56807548751039(degrees ). But this where statement

    some_place.point && SetSRID('BOX3D(-158.721365889063 66.09275164148659,
    154.608712235937 52.56807548751039)'::box3d,4326)

returns places in the biggest of two possible squares.

When I change order of angles or use 'xmin ymin,xmax ymax' order, I got the same result.

Also I used

     ST_Contains( SetSRID( ST_MakeBox2D( 
      ST_Point(143.930001298437,66.82980906973742), 
      ST_Point(-145.757498701563,51.37699768868392) ), 4326 ), some_place.point)

with the same result.

How can I do it for some specific order of angle's points?

Upvotes: 1

Views: 965

Answers (1)

Thomas
Thomas

Reputation: 1066

Postgis want the coordiants as followed:

ST_MakeBox2D(<LL>, <UR>)

LL means lower left, UR upper right:

So for you this means:

some_place.point && SetSRID('BOX3D(154.608712235937  52.56807548751039,
-158.721365889063 66.09275164148659)'::box3d,4326)

and

ST_Contains( SetSRID( ST_MakeBox2D( 
  ST_Point(143.930001298437,51.37699768868392), 
  ST_Point(-145.757498701563,66.82980906973742) ), 4326 ), some_place.point)

If you still get wrong results, try to split the query at 180 / -179.9999999 degrees

Upvotes: 1

Related Questions