tile38 icon indicating copy to clipboard operation
tile38 copied to clipboard

Add ability to search object nearby other objects. (linestring buffering)

Open tidwall opened this issue 8 years ago • 7 comments

Currently the NEARBY command only supports a radius search around single a point, such as:

NEARBY poi POINT 41.2801 -7.7214 100

But it would be great to add the ability to search nearby other objects such as:

NEARBY poi OBJECT {"type":"LineString","coordinates":[[-7.71175,41.28433],[-7.71708,41.28233],[-7.72145,41.28012],[-7.72579,41.27761],[-7.72791,41.27710],[-7.73216,41.27718],[-7.74237,41.27782]]} 100

Under the hood the NEARBY command would need to generate a new polygon from the linestring by "buffering" the linestring using an algorithm like the Minkowski Sum, PostGIS ST_MinkowskiSum.

Original LineString:

LineString

Buffered LineString:

LineString-Buffer

And then the NEARBY command would hand the control to the INTERSECTS command.

tidwall avatar Nov 09 '16 16:11 tidwall

If someone wants to implement this, there is a good example in JavaScript, here: https://github.com/Turfjs/turf/blob/master/packages/turf-buffer/index.js

I might implement this in Go eventually, though not any time soon. I am leaving this here for anyone else who may be interested in porting it.

umpc avatar Dec 08 '17 02:12 umpc

Almost similar in geoLib https://github.com/manuelbieh/geolib/blob/master/src/isPointNearLine.ts Detects if a point is within a certain distance from the line

ronalddas avatar Dec 07 '20 18:12 ronalddas

Has there been some development on this issue?

higoramp avatar Dec 07 '21 14:12 higoramp

Actually, I do have something in a dev branch somewhere. I'll dig around and see what state the code is in.

tidwall avatar Dec 08 '21 00:12 tidwall

I just committed the ability to buffer objects in 241117c.

It's a little different that what I suggested back in 2016, but it should provide the same underlying functionality.

Here's an example:

INTERSECTS poi BUFFER 100 OBJECT {"type":"LineString","coordinates":[[-7.71175,41.28433],[-7.71708,41.28233],[-7.72145,41.28012],[-7.72579,41.27761],[-7.72791,41.27710],[-7.73216,41.27718],[-7.74237,41.27782]]}

It uses a new BUFFER option that takes one param (meters). This will buffer any object, like Point, LineString, Polygon, etc.

tidwall avatar Dec 10 '21 01:12 tidwall