简体   繁体   中英

Can ST_BUFFER and ST_WITHIN be used for linestrings within a linestring?

I am working with MariaDB and trying to get data based on the condition of linestrings that are within another linestring. To allow linestrings not having to be exactly within (due to GPX variability in coordinates), I want to include a buffer.

SELECT * FROM tableX WHERE ST_WITHIN(ST_BUFFER( linestring ,r), (SELECT linestring FROM tableY WHERE id=@id) )

I expect to retrieve at least one row, since this row is also retrieved with the same query without the buffer (so, I would expect this is equal to r=0). However, no matter how small or big r is, I get an empty table .

In the documentation it says that ST_BUFFER applies to all geometry objects, but I have only seen examples with points in either linestrings / polygons. It made me wonder if it is even possible to apply this function to linestrings within a linestring?

I have found the solution.

First, the ST_BUFFER creates a polygon geometry object so the ST_BUFFER function should be used only for the second argument of ST_WITHIN - since a polygon object can never be within a linestring object by definition.

Second, the radius should be way smaller than 1 (do not think in integers). While visualizing the results, one can see this corresponds to a huge circle range around the linestring. The radius I found for my solution was r=0.001.

Hope that it is of help to anyone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM