I got one column (latlon
) which is a ST_MultiPolygon
.
The other geometry is a point which I just want to check if it is inside one of my MultiPolygons.
I tried:
SELECT ST_CONTAINS(latlon, ST_GeometryFromText('POINT(48.208417 16.372472)')
FROM districts
It always returns false; why can't I check if a point is within a multipolygon with ST_Contains
?
To test whether a point and a polygon have any intersection at all, use STIntersects(). To test whether a point is wholly contained inside a polygon, use STContains(), and to test whether it lies on the boundary use STBoundary().
The ST_Contains() function. The ST_Contains() function takes two geometry objects and returns t (TRUE) if the first object completely contains the second; otherwise, it returns f (FALSE).
A polygon or multipolygon is valid if all of the following are true: The polygon is closed; its start point is the same as its end point. Its boundary is a set of linestrings. The boundary does not touch or cross itself.
PostGIS has begun a transition from the existing naming convention to an SQL-MM-centric convention. As a result, most of the functions that you know and love have been renamed using the standard spatial type (ST) prefix.
it worked like this:
SELECT name, st_contains(latlon, ST_GeomFromText('POINT(16.391944 48.218056)', 4326)) FROM bezirks
The st_contains works with multi geometries. You must ensure that the point is on the same coordinate system of polygon geometry.
Also you must know that if the point falls into boundary of your multipolygon it will not be considered contained. In this case it will return false since no point inside of polygon geometry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With