tidwall / tile38

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

Feature/set circle support #745

Closed undeadcat closed 6 days ago

undeadcat commented 2 weeks ago

Please do not open a pull request without first filing an issue and/or discussing the feature directly with the project maintainer.

Please ensure you adhere to every item in this list

Describe your changes

Adds support for SET ... CIRCLE.

127.0.0.1:9851> SET cities sf POINT 37.769092 -122.451505
OK
127.0.0.1:9851> SET cities 10_km_from_sf CIRCLE 37.769092 -122.451505 10000
OK
127.0.0.1:9851> SET cities 100_km_from_sf CIRCLE 37.769092 -122.451505 100000
OK
127.0.0.1:9851> GET cities 10_km_from_sf
"{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-122.451505,37.769092]},\"properties\":{\"type\":\"Circle\",\"radius\":10000,\"radius_units\":\"m\"}}"
127.0.0.1:9851> INTERSECTS cities POINT 37.769092 -122.451505
1) (integer) 0
2) 1) 1) "100_km_from_sf"
      2) "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-122.451505,37.769092]},\"properties\":{\"type\":\"Circle\",\"radius\":100000,\"radius_units\":\"m\"}}"
   2) 1) "10_km_from_sf"
      2) "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-122.451505,37.769092]},\"properties\":{\"type\":\"Circle\",\"radius\":10000,\"radius_units\":\"m\"}}"
   3) 1) "sf"
      2) "{\"type\":\"Point\",\"coordinates\":[-122.451505,37.769092]}"

127.0.0.1:9851> INTERSECTS cities IDS POINT 37.769092 -122.451505
1) (integer) 0
2) 1) "100_km_from_sf"
   2) "10_km_from_sf"
   3) "sf"

127.0.0.1:9851> INTERSECTS cities IDS POINT 37.554478 -122.020158
1) (integer) 0
2) 1) "100_km_from_sf"

This is based on PR https://github.com/tidwall/tile38/pull/649, but with some differences:

Issue number and link

Pull request require a prior issue with discussion. Include the issue number of link here.

iwpnd commented 2 weeks ago

Duplicate of #649

tidwall commented 1 week ago

The problem with a circle type as a geometry stored in a collection is that there is no GeoJSON compatible way to represent it without losing precision on output. I'm not opposed with the idea of a SET ... CIRCLE ... command but I would like to somehow solve the compatibility issue.