1

I have a bounding box given and want to know if this bounding box contains (or better intersects) any points or linestrings. So the query should return true if the first point/linestring was found and not test all of them.

The query I got so far is this:

SELECT NOT 
 (ST_Intersects(ST_Transform(ST_SetSRID(ST_MakeBox2D(ST_Point(13.3277368531, 52.4783729748), ST_Point(13.463715857, 52.5520736045)), 4326), 3857), geom_vertex_web_mercator) 
AND 
 ST_Intersects(ST_Transform(ST_SetSRID(ST_MakeBox2D(ST_Point(13.3277368531, 52.4783729748), ST_Point(13.463715857, 52.5520736045)), 4326), 3857), geom_way_web_mercator)) as isEmpty 
FROM vertex, edge 
LIMIT 1;

But this just takes the first point/linestring and returns the value for it. Can any one help.

EDIT This query seems to be very fast:

select exists (select true from network where ST_Intersects(ST_Transform(ST_SetSRID(ST_MakeBox2D(ST_Point(-140.0, 80.0), ST_Point(-135.0, 80.0)), 4326), 3857), geom_way_web_mercator)) as isEmpty;
1

How about SELECT EXISTS? According to the docs it should run until the first (if any) row is returned.

| improve this answer | |

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.