tile38 icon indicating copy to clipboard operation
tile38 copied to clipboard

nearby to return distance to objects

Open auselen opened this issue 9 years ago • 8 comments

Would it be possible for nearby queries to return distance inside objects as well?

so instead of {"type":"Point","coordinates":[1,2]} may be we can get something like {"type":"Point","coordinates":[1,2], "distance": 3000}

that will make ordering of results easier.

My real issue is to get the nearest object, but then for a relative big search area I get many result, and I think they are not ordered by distance.

auselen avatar Jan 04 '17 21:01 auselen

Hi @auselen,

Would this be for the NEARBY command specifically? I think that returning the distance of each object along with the results should be trivial for points.

Perhaps adding a DISTANCES keyword, such as:

NEARBY fleet DISTANCES POINT 33 -115

For complex objects this will be a bit more challenging because of object edge detection and such. #95 touches on this problem a bit (a feature that I would like work on in the near future). Though it'd possible to return the center of the object's bounding box as point to use for the distance calculation.

Right now Tile38 tries to follow the GeoJSON spec as much as possible. I wondering if it's best to have the distance member as a separate value outside the geojson block, similar to the way the object id is seperate. So it would be id,object,distance for each item that is returned.

As for ordering from closest to farthest, I've been working on a new r-tree implementation that should support k nearest neighbors and make this possible. I don't have an eta, but I'll keep you posted when it's ready.

tidwall avatar Jan 04 '17 22:01 tidwall

DISTANCES keyword and [id, object, distance] would work just fine as well. Should I expect this to be released soon?

I don't think about complex objects about now just because I understand that's hard business.

What I'm doing is to find nearest city given a point, I get locations from geonames, and I'm just thinking of working around picking the right one by weighting distance, population, etc. just some approximation instead of doing bounding boxes etc.

auselen avatar Jan 04 '17 22:01 auselen

I'll add the DISTANCES keyword to roadmap. I'm a bit backlogged right now, but hopefully I can get to it soon.

tidwall avatar Jan 04 '17 23:01 tidwall

Sharing a one liner to fill tile38 with geonames data. I realized keys can't have spaces (not possible to surround them with quotes, so can't use city name as key) also not possible to set some string info for the point (like city name in this case). Other than those, it's great!

curl -s http://download.geonames.org/export/dump/cities1000.zip | zcat | awk -F $'\t' '{print "set city",$1,"POINT",$5,$6} END {print "quit"}' | ./tile38-cli
127.0.0.1:9851> SERVER
{"ok":true,"stats":{"aof_size":29887319,"avg_item_size":332,"heap_released":0,"heap_size":48752640,"id":"e4ddbd6ac9841d874e4511b1519b5303","in_memory_size":3357186,"max_heap_size":0,"mem_alloc":48752640,"num_collections":1,"num_hooks":0,"num_objects":146831,"num_points":146831,"num_strings":0,"pid":25680,"pointer_size":8,"read_only":false},"elapsed":"353.304µs"}

Feel free to add them to wiki if you think it is good enough.

auselen avatar Jan 05 '17 14:01 auselen

@auselen using city as a key name is kinda bad idea. In Russia in e.g. there is a lot of cities with a non-unique names. You will just mess all data. Also in US, they have a cities with similar names.

m1ome avatar Jan 08 '17 09:01 m1ome

No question there but it's more of a one line demo thing. Also imagine concatenating all the administrative names to city name to get it more distinctive. I don't know if it's a redis thing to not to have spaces in keys.

auselen avatar Jan 08 '17 10:01 auselen

@auselen Redis does support spaces in keys, and Tile38 does too. I think you may have found a limitation of the tile38-cli command.

When I use the redis-cli and use the following command it seems to work.

curl -s http://download.geonames.org/export/dump/cities1000.zip | \
    zcat | \
    awk -F $'\t' '{print "set city \""$2"\" POINT",$5,$6} END {print "quit"}' | \
    redis-cli -p 9851

tidwall avatar Jan 08 '17 11:01 tidwall

@tidwall this feature already in doc's maybe you can close this issue?

m1ome avatar Jan 15 '17 10:01 m1ome