0

How do I know if a point (or a coordinate lon-lat) is inside of a MULTIPOLYGON using PostGIS?

I tried with ST_Contains(), but being a MULTIPOLYGON always return False.

Also I tried with ST_Dump() for transform to a simple POLYGON but I didn't get that to work.

I used:

SELECT ST_GeomFromText(the_geom,900913)

and then:

SELECT ST_Contains("previous select result", ST_GeomFromText('POINT(lon lat)',4326))
  • Did you actually create a new table with single part polygons using ST_Dump? – Micha Aug 31 '16 at 10:37
  • Make sure your geometries are valid – Peter Horsbøll Møller Aug 31 '16 at 10:42
  • I use: SELECT ST_GeomFromText(the_geom,900913), and next: SELECT ST_Contains("previous select result", ST_GeomFromText(\'POINT(lon lat)\',4326)) – josemi Aug 31 '16 at 10:49
  • Please edit the question to include clarifications. It's not fair to those who would answer to need to mine the comments for critical information. – Vince Aug 31 '16 at 11:07
  • 1
    ST_Contains will always return false when the point and polygon do not share a coordinate system. You need to project (ST_Transform) one or the other (or both, thought that seems wasteful). – Vince Aug 31 '16 at 11:43
2

The problem is that the point and the shape are not projected to the same coordinate system; one or the other needs to be converted, using ST_Transform() like this:

SELECT ST_Contains('the_geom',ST_Transform(ST_GeomFromText('POINT(lon lat)',4326),900913))

Thanks to Vince for the hint.

|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.