Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dividing a region into geofences #164

Closed
salfifarooq opened this issue Apr 3, 2017 · 6 comments
Closed

Dividing a region into geofences #164

salfifarooq opened this issue Apr 3, 2017 · 6 comments

Comments

@salfifarooq
Copy link

Hey this is some tremendous software system for geospatial stuff.

I have a use-case wherein I need to divide a given geographical area, which can range from small region of few kilometers to a country, into geofences (static + roaming). How do you think I should proceed with this using tile38?

@amorskoy
Copy link

amorskoy commented Apr 3, 2017

In fact I did probably the same. It was not perfect from the beginning, but finally we succeed with @tidwall
See:
#94
#95
#99
#107
#132
#133

Finally, I was able to make good POC.

@tidwall
Copy link
Owner

tidwall commented Apr 6, 2017

Hi Salfi,

It shouldn't matter the size of the fence, just the complexity and the number of operations that it has to perform. A geofence is similar to a SET followed by a NEARBY, INTERSECTS, or WITHIN query on the defined fence area. For a complex geofence such as a country, it's ideal to use a GeoJSON object with a defined "bbox":

For example:

image

Is better than:

image

This is because the "bbox" won't need to be recalculated after each SET command.

If what you are interested crossing between geofences such as:

image

Then it could be worthwhile to reduce the fences down to a minimal threshold:

image

put a boxes around those too:

image

and use the DETECT enter option when defining both fences.


Here's some examples based on the images above:

SETHOOK enter-boliva http://127.0.0.1/fence INTERSECTS fleet FENCE DETECT enter OBJECT '{"type":"Polygon","bbox":[-63.325195,-21.983801,-57.612304,-18.458768],"coordinates":[[[-63.325195,-21.983801],[-62.819824,-21.983801],[-62.644042,-22.309425],[-62.292480,-21.063997],[-62.314453,-20.529933],[-61.918945,-20.076570],[-61.765136,-19.642587],[-60.380859,-19.373340],[-59.985351,-19.290405],[-59.084472,-19.269665],[-58.117675,-19.849393],[-58.117675,-20.220965],[-57.810058,-19.993998],[-58.029785,-19.663280],[-57.612304,-18.458768],[-63.325195,-18.458768],[-63.325195,-21.983801]]]}'
SETHOOK enter-paraguay http://127.0.0.1/fence INTERSECTS fleet FENCE DETECT enter OBJECT '{"type":"Polygon","bbox":[-62.644042,-22.309425,-57.857675,-19.269665],"coordinates":[[[-57.957675,-22.109425],[-62.644042,-22.309425],[-62.292480,-21.063997],[-62.314453,-20.529933],[-61.918945,-20.076570],[-61.765136,-19.642587],[-60.380859,-19.373340],[-59.985351,-19.290405],[-59.084472,-19.269665],[-58.117675,-19.849393],[-58.117675,-19.849393],[-58.117675,-20.220965],[-57.857675,-21.049393],[-57.957675,-22.109425]]]}'

These are just some ideas based on assumptions. I'm sure you application will differ quite a bit. Also roaming fences will increase the number of operations and notifications quite a bit. So you may want to do some basic testing on your side to see what throughput you get.


The original geojson which I created at http://geojson.io

Bolivia

{
  "type": "Polygon",
  "bbox": [-63.325195,-21.983801,-57.612304,-18.458768],
  "coordinates": [[
    [-63.325195,-21.983801],
    [-62.819824,-21.983801],
    [-62.644042,-22.309425],
    [-62.292480,-21.063997],
    [-62.314453,-20.529933],
    [-61.918945,-20.076570],
    [-61.765136,-19.642587],
    [-60.380859,-19.373340],
    [-59.985351,-19.290405],
    [-59.084472,-19.269665],
    [-58.117675,-19.849393],
    [-58.117675,-20.220965],
    [-57.810058,-19.993998],
    [-58.029785,-19.663280],
    [-57.612304,-18.458768],
    [-63.325195,-18.458768],
    [-63.325195,-21.983801]
  ]]
}

Paraguay

{
  "type": "Polygon",
  "bbox": [-62.644042,-22.309425,-57.857675,-19.269665],
  "coordinates": [[
    [-57.957675,-22.109425],
    [-62.644042,-22.309425],
    [-62.292480,-21.063997],
    [-62.314453,-20.529933],
    [-61.918945,-20.076570],
    [-61.765136,-19.642587],
    [-60.380859,-19.373340],
    [-59.985351,-19.290405],
    [-59.084472,-19.269665],
    [-58.117675,-19.849393],
    [-58.117675,-19.849393],
    [-58.117675,-20.220965],
    [-57.857675,-21.049393],
    [-57.957675,-22.109425]
  ]]
}

---

@tidwall
Copy link
Owner

tidwall commented Apr 6, 2017

@amorskoy I would love to hear more details about your POC and the application. If you have some time in the future. :)

@tidwall
Copy link
Owner

tidwall commented Apr 20, 2017

@Salafi-Farooq I'm closing this issue for now. Please feel free to reopen if you have further questions. Thanks!

@tidwall tidwall closed this as completed Apr 20, 2017
@younisshah
Copy link

younisshah commented Apr 30, 2017

@tidwall How does one go about geofencing a city?

@younisshah
Copy link

@tidwall Given a location specified as a lat/lon pair, how do I find which of many tens of thousands of geofences this location falls into using tile38?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants