St_Contains dosen't work for linestring


#1

Hi,
I have a query for finding lineStrings in a specific polygon. But my query didn’t return any linestrings and errors. I have checked my linestring is in this polygon. Is it a bug in mapd? You can see my query below.
Thanks

select * from hat Where ST_Contains(ST_GeomFromText( ‘POLYGON((30.790879 38.828834,30.793320 38.828834,30.793320 38.831726,30.790879 38.8317264, 30.790879 38.828834))’, 4326),mapd_geo)


#2

Hi @Kayhan,

The ST_Contains () will work with points within polygon, linestring is not currently supported. You can use the LINESTRING accessor functions ST_PointN(), ST_StartPoint(), ST_EndPoint(), ST_XMin(), ST_YMin(), ST_XMax() and ST_YMax() to extract the points within the linestring and test with ST_Contains().

Regards,
Veda


#3

Hi @Kayhan,

I just verified that in MapD Ver 4.1.0, ST_Contains works with POLYGON and LINESTRING. It is still unsupported with MULTIPOLYGON though.
If you see linestrings as not contained where you would expect them to be, then please share a few examples, and we will check it out.

Regards,
Veda


#4

I’m using 4.1 docker cpu mapd version. When I tried ST_Contains it’s did’t work. No returns any data and errors. So I tried to ST_Distance and I could see LINESTRINGs and POLYGONs. You can see my queries below.

1- With ST_Contains no return any data and error:

select * from hat Where ST_Contains(ST_GeomFromText( ‘POLYGON((30.790879726409912 38.82883467963268,30.793320536613464 38.8288346796326,30.793320536613464 38.8317264905966,30.790879726409912 38.83172649059667, 30.790879726409912 38.82883467963268))’, 4326),mapd_geo)

2- With ST_Distance return data

select * from hat Where ST_DISTANCE(ST_GeomFromText( ‘POLYGON((30.790879726409912 38.82883467963268,30.793320536613464 38.8288346796326,30.793320536613464 38.8317264905966,30.790879726409912 38.83172649059667, 30.790879726409912 38.82883467963268))’, 4326),mapd_geo )=0

Query result is :

… … …LINESTRING (30.7906535131813 38.8292682165416,30.7916071223056 38.8288252748683)

Kind regards,
Kayhan


#5

Mapd should support the ST_Contains between polygons and linestrings because I can see an extension function on the mapd-core source called ST_Contains_Polygon_LineString in ExtensionFunctionsGeo.hpp (the only apparent limitation is the number of rings on polygon) but in my 4.1 is not working (Am I doing something wrong?)

I tried with very simple geometries.

mapdql> create table test_linestring(ls_field geometry(linestring));
mapdql> insert into test_linestring values(‘linestring(0 0, 0 1)’);

mapdql> select st_contains(ST_GeomFromText(‘POLYGON((-3 -3,-3 3,3 3,3 -3,-3 -3))’),ls_field) from test_linestring;
false
1 rows returned.

mapdql> select st_contains(ST_GeomFromText(‘POLYGON((-3 -3,-3 3,3 3,3 -3,-3 -3))’),ST_GeomFromText(‘linestring(0 0, 0 1)’)) from test_linestring;
false
1 rows returned.


#6

Hi @Kayhan,

I upgraded mapd to 4.1.1, and I can confirm st_contains is working now


#7

Thanks for your informations.


#8

Hi aznable,
I have installed last mapd cpu docker version. But St_Contains function still doesn’t return any data.(When I click the helper menu on mapd the version still looks 4.1.0. May it’s forgotten for update.)

select * from hat Where ST_DISTANCE(ST_GeomFromText( ‘POLYGON((30.790 38.828,30.795 38.828,30.795 38.834,30.790 38.834, 30.790 38.828))’, 4326),mapd_geo )=0
//returns 11 rows

select * from hat Where ST_Contains(ST_GeomFromText( ‘POLYGON((30.790 38.828,30.795 38.828,30.795 38.834,30.790 38.834, 30.790 38.828))’, 4326),mapd_geo )
//return 0 rows

So I’m using St_Distance function as a St_Contains. It’s my simple solution.

Thanks
Kayhan