tile38
tile38 copied to clipboard
Determine Direction
Is your feature request related to a problem? Please describe. Fleet points are updated every second and I would like to show nearest upcoming intersection point while traveling along a path but I do not want to show neighbors/intersections that have already been passed which will not work due there being no way to filter out.
Describe the solution you'd like I see that your geo library does provide a bearing function if two points are given. It would be nice to be able to specify only wanting the nearest neighbor if the bearing returned is within a given threshold for example if the bearing was between 80 - 100 you would know the truck is traveling eastbound. ex... nearby fleet LIMIT 2 where bearing between 80-100 point x,y or something similar. This way only the upcoming intersections will be returned if the bearing calculated between them and the fleet point is within the threshold
here is what I was referencing func() BearingTo on line 74. https://github.com/tidwall/tile38/blob/master/vendor/github.com/tidwall/geojson/geo/geo.go
Hi Gary,
Measuring and filtering on bearing would be very cool indeed. It seem a bit application specific, but I can imagine others might find it useful too. I added marked it as a potential future feature.
Something that might be quicker to realize is to create a "sector" from a lat/lon, a radius and a min-angle/max-angle. The resulting object can be used similar to how you do it with the geohash.
e.g.
// WITHIN collection SECTOR lat lon radius min-angle max-angle
WITHIN fleet SECTOR 33.462 -112.268 5000 180 240
On second thought, this is similar to my H3 request. The user could take care of that and pass the sector in an object search. 🤷
@iwpnd Does this represent what you are describing?
@tidwall I was just brainstorming on @gmonk 's request, but yes that's exactly what I meant. I had to solve something similar in PostGIS recently.
Would this require having to set up a geojson object for each direction of travel ? if so this is what I have done in the past but it gets tedious if you have several hundred intersections. I was just trying to devise a way to do this in a more dynamic way. To give some background this would be for a connected vehicle proof of concept where generally things are done using geofencing and distances. say a car is traveling eastbound and coming up to an intersection depending on distance and direction of travel the intersection could provide a count down of when the intersection would turn green but only if it met the direction/distance requirements. Currently I would have to do as before and setup sectors for each direction of travel and set distances but the issues is those distances could potentially change resulting in having to recreate/modify which is all a manual process not to mention a pain if you have several hundred vs being able to say what is the nearest vehicle near intersection x and is it traveling east bound at a distance of 100 meters if so then trigger an alert. Every scenario I tried using the current implementation of nearby would still trigger because bearing was not a factor and nearby still saw the intersection that was passed and not of interest anymore still the closest. Were as with bearing being calculated as soon as the vehicle passes the intersection the bearing calculated would obviously change and no longer within the param's thus not triggering. I know i would still have to setup nearby hooks/channels for each intersection but i would hope i could just to do somthing like NEARBY Fleet Limit 1 Point x.y where bearing +inf 80 and bearing -inf 100 and distance is between 50 to 100 meters or maybe use cardinal directions like bearing N,E,S,W
I know this may be too application specific so if you dont think this is something that could be beneficial to others dont worry about it.
@iwpnd This is cool is it possible to test this now ?
You can fetch the branch and try it out. I don't think the way it is now it will find its way into master though.
I merged the PR moments ago. On the surface the feature looks good and the PR included all the necessary tests.
It should be usable from the master branch, and edge docker tag.
I was actually expecting you would request to build it with your geometry and geodetic library in Tile38 directly. 😅
Unfortunately the new geometry and geodesic libraries that I've been working on aren't ready for primetime yet.
When I get those solid enough for Tile38 we can circle back.
I'm assuming you are referring to the new https://github.com/tidwall/geometry and https://github.com/tidwall/geodesic libraries.
Yes, I am referring to them. I was just thinking that it would be beneficial for you to if it would stay in your ecosystem. Let me know once you're confident they suffice and I will happily use them within Tile38 to achieve the same. :)
Sounds good. I’ll keep you posted.
This works great thanks for all your hard work @iwpnd & @tidwall