Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I check whether a multipolygon contains point in PostGIS?

Tags:

postgis

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?

like image 816
krackmoe Avatar asked Dec 11 '12 15:12

krackmoe


People also ask

How do you check if a point is in a polygon SQL?

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

What is ST_ Contains?

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

What makes a polygon in valid?

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.

What is ST in PostGIS?

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.


2 Answers

it worked like this:

SELECT name, st_contains(latlon, ST_GeomFromText('POINT(16.391944 48.218056)', 4326))  FROM bezirks
like image 141
krackmoe Avatar answered Oct 18 '22 09:10

krackmoe


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.

like image 36
cavila Avatar answered Oct 18 '22 11:10

cavila