tidwall / tile38

Real-time Geospatial and Geofencing
https://tile38.com
MIT License
9.15k stars 570 forks source link

Tile38 Nearby Does not produce results as expected #710

Open chamikabm opened 1 year ago

chamikabm commented 1 year ago

Describe the bug I've following Geometry objects in Tile38

# OSM WAY 1

SET LRS_TEST OSM&&WAY10592122 FIELD meta '{"feature":"WAY","layer_id":"WAY","feature_id":"OSM&&WAY10592122","vicmap_road_names":["GARDINERS CREEK TRAIL","CITYLINK","UNNAMED"]}' OBJECT '{"type":"Feature","geometry":{"type":"LineString","coordinates":[[145.0352298,-37.8374751],[145.0349665,-37.8374204],[145.0347479,-37.8373876],[145.0344542,-37.8373537],[145.0342236,-37.8373346],[145.034013,-37.837324],[145.0338078,-37.8373198],[145.0335839,-37.8373219],[145.0333626,-37.8373304],[145.0331507,-37.8373431],[145.0329643,-37.8373621],[145.032747,-37.8373886],[145.0325713,-37.837414],[145.0323943,-37.8374469],[145.0321448,-37.8374988],[145.0318029,-37.837575],[145.0315467,-37.8376343],[145.0312879,-37.8376894],[145.0310827,-37.8377339],[145.0308949,-37.8377678],[145.0306723,-37.8378038],[145.0304939,-37.837826],[145.0303169,-37.8378451],[145.030128,-37.8378619],[145.0299588,-37.8378674],[145.029759,-37.8378684],[145.0295414,-37.8378635],[145.0293322,-37.8378507],[145.0291689,-37.8378332],[145.0289908,-37.8378107],[145.0287668,-37.8377738],[145.0284598,-37.837689],[145.0281995,-37.8376017],[145.0280017,-37.8375254],[145.0277925,-37.8374397],[145.0276122,-37.8373553],[145.0274176,-37.8372527],[145.0272614,-37.8371596],[145.0271053,-37.8370584],[145.0269363,-37.8369281],[145.026669,-37.8367093],[145.0265103,-37.8365467],[145.0263191,-37.8363432],[145.0259387,-37.8359123],[145.0254405,-37.8353373],[145.0248245,-37.8346331],[145.024076,-37.8337694]]},"feature_id":"OSM&&WAY10592122","layer_id":"OSM","feature_type":"LINE","properties":{"Hex Index":[604314936591515647]}}'

# OSM WAY 2

SET LRS_TEST OSM&&WAY10592129 FIELD meta '{"feature":"WAY","layer_id":"WAY","feature_id":"OSM&&WAY10592122","vicmap_road_names":["GARDINERS CREEK TRAIL","CITYLINK","UNNAMED"]}' OBJECT '{"type":"Feature","geometry":{"type":"LineString","coordinates":[[145.0242202,-37.833699],[145.0249771,-37.8345629],[145.0255818,-37.8352643],[145.0261807,-37.8359464],[145.0263563,-37.8361408],[145.0266897,-37.8364842],[145.0269932,-37.8367649],[145.0271473,-37.8368942],[145.0274437,-37.8370893],[145.0276962,-37.8372252],[145.0279431,-37.8373415],[145.0282033,-37.8374456],[145.0284439,-37.8375247],[145.0286924,-37.837598],[145.0289724,-37.8376538],[145.0292708,-37.8377009],[145.0295253,-37.8377236],[145.0297765,-37.8377265],[145.0300567,-37.8377233],[145.0303277,-37.8377053],[145.0305851,-37.8376725],[145.0308601,-37.837629],[145.031135,-37.8375761],[145.0315011,-37.8374903],[145.031764,-37.8374268],[145.0321489,-37.837341],[145.0324144,-37.8372869],[145.032684,-37.8372425],[145.0329562,-37.8372064],[145.0332164,-37.8371842],[145.033499,-37.8371691],[145.0337609,-37.8371651],[145.0340264,-37.8371715],[145.0342987,-37.8371863],[145.0345682,-37.8372086],[145.0348405,-37.8372467],[145.0350497,-37.8372816],[145.0352732,-37.8373251]]},"feature_id":"OSM&&WAY10592129","layer_id":"OSM","feature_type":"LINE","properties":{"Hex Index":[604314936591515647]}}'

# OSM WAY 3

SET LRS_TEST OSM&&WAY756852509 FIELD meta '{"feature":"WAY","layer_id":"WAY","feature_id":"OSM&&WAY756852509","vicmap_road_names":[]}}' OBJECT '{"type":"Feature","geometry":{"type":"LineString","coordinates":[[145.0290871,-37.834018],[145.0289588,-37.8340363],[145.028506,-37.8339769],[145.0283699,-37.8339298]]},"feature_id":"OSM&&WAY756852509","layer_id":"OSM","feature_type":"LINE","properties":{"Hex Index":[604314936591515647]}}'

# OSM WAY 4

SET LRS_TEST OSM&&WAY756852510 FIELD meta '{"feature":"WAY","layer_id":"WAY","feature_id":"OSM&&WAY756852510","vicmap_road_names":["MORRISON STREET"]}' OBJECT '{"type":"Feature","geometry":{"type":"LineString","coordinates":[[145.0283699,-37.8339298],[145.0285162,-37.8339201],[145.0289616,-37.8339774],[145.0290871,-37.834018]]},"feature_id":"OSM&&WAY756852510","layer_id":"OSM","feature_type":"LINE","properties":{"Hex Index":[604314936591515647]}}'

NEARBY LRS_TEST LIMIT 1 WHEREIN meta.layer_id 1 WAY IDS POINT -37.834040127081664 145.02898743753536 5.0

To Reproduce Use the above commands to get the output

Expected behavior Expected behaviour is to provide me the closest road to the point provided in the NEARBY, and it should produce this output ["OSM&&WAY756852509"], but currently it gives ["OSM&&WAY10592122"] for ids instead of.

Screenshot 2023-11-07 at 1 11 18 pm

Additional context Tile38 Docker compose:

  tile38:
    image: tile38/tile38:latest
    container_name: tile38
    volumes:
      - tile38-data:/data
    ports:
      - 9851:9851
    network_mode: bridge
chamikabm commented 1 year ago

Even the following command produce the wrong result, it given OSM&&WAY756852510 as ids

INTERSECTS LRS_TEST BUFFER 10.0 WHEREIN meta.layer_id 1 WAY IDS OBJECT "{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"coordinates\":[145.02898743753536,-37.834040127081664],\"type\":\"Point\"}}"

iwpnd commented 1 year ago

NEARBY will only ever consider the center point of linestrings and polygons, hence the result you see.

chamikabm commented 1 year ago

@iwpnd , Interesting, It seems like that information is missing from the documentation. What would be the better approach for achieving the same ?

My idea is to find all the nearby linestrings to a given point within a specified radius and retrieve them in of ascending distance from the given point.

INTERSECTS LRS_TEST BUFFER 100.0 MATCH OSM&&WAY* IDS OBJECT "{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"coordinates\":[145.02898743753536,-37.834040127081664],\"type\":\"Point\"}}"

I tried the above it seems to be working, but the issue is results are not in the order of ascending distance from the given point

iwpnd commented 1 year ago

You can use a tool that provides you with the required capabilities such as PostGIS or you can calculate distances in your application and order instead of relying on Tile38 here.

chamikabm commented 1 year ago

Sure thank you.