1

I have two points which represents lower left and upper right point of BBOX. I have one point which SHOULD be somewhere inside and I want to test it.

I have all of them as 'geometry(POINT, 4326)' data type.

When I try functions:

ST_MakeBox2D( geom4326ur, geom4326ll )
ST_Envelope ( ST_MakeBox2D( geom4326ur, geom4326ll ) 
Box2D

I get only linestring geometry connecting these two points. I don't get 4 points of box which I need to transform them to polygon and then check with ST_Intersect if all points are inside their bounding boxes.

Can you help me solve this? I would like to have most effective solution - I am running this on millions of points.

3

ST_MakeBox2D already returns a geometry that is a polygon for PostGIS. The right syntax has points in lower left-upper right order but function does not seem to be strict with that.

SELECT
ST_MakeBox2D(
ST_GeomFromText('POINT (0 0)'),
ST_GeomFromText('POINT (1 1)'));

"BOX(0 0,1 1)"

SELECT
ST_MakeBox2D(
ST_GeomFromText('POINT (1 1)'),
ST_GeomFromText('POINT (0 0)'));

"BOX(0 0,1 1)"

SELECT ST_AsText(
ST_MakeBox2D(
ST_GeomFromText('POINT (0 0)'),
ST_GeomFromText('POINT (1 1)')));

"POLYGON((0 0,0 1,1 1,1 0,0 0))"

Your ST_MakeBox2D should work both alone and inside ST_Envelope. Could it be that your coordinates do not make a box but either X- or Y-coordinates are the same like in this example?

SELECT ST_AsText(ST_Envelope(
ST_MakeBox2D(
ST_GeomFromText('POINT (0 0)'),
ST_GeomFromText('POINT (0 1)'))));

"LINESTRING(0 0,0 1)"
  • This is correct. There were problems in my geometries - some of the X or Y were same which resulted in linestrings. – dkocich Apr 11 '16 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.