tidwall / tile38

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

Polygon WebSocket Geofence formatting? #332

Open EdwardDeaver opened 6 years ago

EdwardDeaver commented 6 years ago

Hello,

I'm trying to set up a polygon geofence using a websocket connection in NodeJS. I have a BOUNDS square working but I can't see how to implement a polygon because of the curly braces and internal quotes.

Here is my example code:

var 1 = new WebSocket('ws://SERVERIP:9851/WITHIN+fleet+FENCE+BOUNDS+10+-112.268+20+-112.245);

A few Issues have examples of polygons: https://github.com/tidwall/tile38/issues/292 https://github.com/tidwall/tile38/issues/311

I don't see how to implement these in a WebSocket call to tile38 to create a Polygon GeoFence?


Also I've been testing Tile38 out so far and it can easily handle 5000 websocket connections at once. It's amazing.

tidwall commented 6 years ago

Hi Edward,

A Websocket URL need to be encoded, the '+' character represents spaces, but more complex object need percent encoding.

For example, the standard command:

WITHIN fleet FENCE {"type":"Polygon","coordinates":[[[-111.91789,33.4801],[-111.92304,33.4799],[-111.92098,33.4689],[-111.91085,33.4715],[-111.90879,33.4764],[-111.91326,33.4805],[-111.91789,33.4801]]]}

Can be percent encoded like:

ws://SERVERIP:9851/WITHIN+fleet+FENCE+OBJECT+%7B%22type%22%3A%22Polygon%22%2C%22coordinates%22%3A%5B%5B%5B-111.91789%2C33.4801%5D%2C%5B-111.92304%2C33.4799%5D%2C%5B-111.92098%2C33.4689%5D%2C%5B-111.91085%2C33.4715%5D%2C%5B-111.90879%2C33.4764%5D%2C%5B-111.91326%2C33.4805%5D%2C%5B-111.91789%2C33.4801%5D%5D%5D%7D
EdwardDeaver commented 6 years ago

Thank you so much!

tidwall commented 6 years ago

You're welcome :)

EdwardDeaver commented 6 years ago

Tidwall,

is it possible to put a "buffer zone" around a polygon? For instance if I have a polygon that has a buffer of 100 meters around it, an object that enters that 100 meter buffer will trigger the 'inside' message?

tidwall commented 6 years ago

Buffering is something that is commonly requested and a feature that I would like to add to Tile38 in the future. But currently it's not possible to dynamically add a buffer around a polygon.

As a workaround you can add the buffer prior to adding the polygon to Tile38. I think Turf.js can do this, and there are some python tools too.

https://www.google.com/search?q=geojson%20buffer

79 #95 #182

EdwardDeaver commented 6 years ago

Thank you.

I'll explore the options.

I have a final(probably not final, but I'll make new issues) question. In the way I'm going about creating web socket connections to tile38 is it possible to name my Geofences so my response has a "Fence ID"?

I know using the web hook way you can get a hook name in the fence response but I'm unsure of how to set a unique ID not using a web hook.

tidwall commented 6 years ago

Each webhook can contain additional meta data, the name of the field is META.

For example:

SETHOOK warehouse http://10.0.20.78 META mykey myval NEARBY fleet FENCE POINT 33 -112 500

Sending a SET fleet hello POINT 33 -112 command will fire the event

{"command":"set","group":"5b436e8cd5eefd4e00b5236d","detect":"enter","hook":"warehouse","meta":{"mykey":"myval"},"key":"fleet","time":"2018-07-09T07:17:48.30434069-07:00","id":"hello","object":{"type":"Point","coordinates":[-112,33]}}

Where you can see the meta.mykey field.

tidwall commented 6 years ago

Whoops. I just noticed you said not using a web hook.

Sorry but there's no way to define additional properties to a non-webhook geofence at this time.