I have a multipolygon of geography type (multi_bounds) and a point. I'm trying to figure out the fastest way to query whether the multipolygon contains the point. In this case if the point is part of the boundary it should still return true.

I've tried CoveredBy: WHERE ST_CoveredBy(ST_SetSRID(ST_MakePoint(:long, :lat), 4326), multi_bounds::geometry)

Where :long and :lat are arguments provided by yesql.

And I've tried contains: WHERE ST_Contains(multi_bounds::geometry, ST_SetSRID(ST_MakePoint(:long, :lat), 4326))

I don't see a noticeable difference and I'm wondering what the best practice is here.

I did try ST_CoveredBy without casting multi_bounds to geometry but I couldn't get past an error: org.postgresql.util.PSQLException: ERROR: BOOM! Could not generate outside point!

  • 1
    Does St_Intersect not work? – Nate Wessel Sep 8 '15 at 17:38
  • How about casting the point to geography? – Jakub Kania Sep 8 '15 at 18:23
  • @JakubKania Yeah I tried casting the point to geography and leaving multi_bounds as is (geography) and got the error above. – Cody Canning Sep 8 '15 at 18:26
  • 1
    @NateWessel That's a great idea I had been overthinking the problem a little bit. Issue now is I'm getting ERROR: BOOM! Could not generate outside point! with ST_Intersect too for some of my multipolygons. – Cody Canning Sep 8 '15 at 19:05
  • @CodyCanning: Is it possible that's a problem with your input? I can't see why PostGIS would need to create a point to check whether a point intersects with a polygon. Creating the point is not part of the interection checking process. Perhaps your input is outside of the range of latitude and longitude values. – Nate Wessel Sep 8 '15 at 22:09

credit to Nate Wessel for the suggestion.

Adding a column multi_bounds_geom of geometry type and using ST_Intersect is faster than anything else I tried.

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.