2

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, see note), 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?

note: eventually I want to see if a GPX (blue) covered a specific path (purple). Due to GPX variability, the path is not acknowledged by ST_WITHIN to be within the GPX track: enter image description here

Hence, the buffer function would be very useful here.

2 Answers 2

0

The doc says

ST_WITHIN(g1,g2)

Returns 1 or 0 to indicate whether geometry g1 is spatially within geometry g2.

so the line geometry should be the 1st one, and the buffer should be the 2nd one

1
  • I thought I had tried both ways. Now, with the query with the buffer in the second part, it does not finish. It gets stuck in "loading.." . The same applies if I use the ST_CONTAINS command (and use the buffer for the first argument). Can you show me it should be working?
    – Hyp
    Jul 2, 2020 at 10:27
0

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.

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.