Tagged: 

Viewing 0 reply threads
  • Author
    Posts
    • #9026
      Michel Castaño
      Keymaster

      Geofences can be uploaded massively with cURL.

      1. Define a geofence with the following fields in JSON:

      {
        "geometry": {
          "type": "Circle",
          "radius": 105,
          "coordinates": [
            -82.28900,
            24.78238
          ]
        },
        "properties": {
          "name": "warehouse 234",
          "visibility": "groups",
          "groups": [
            500
          ],
          "custom": {
            "foo": "bar",
            "something": true
          },
          "types": [],
          "description": "this is a sample description"<
        }
      }
      

      The main fields here are:
      a. Geometry: specifies the Geometry type you want to create, the API supports:

      • Polygon of 3 or more coordinates (up to 800 coordinates),
      • Circle, or
      • LineString types.

      Polygon
      geometry.coordinates = [[[lon1,lat1] ,[lon2,lat2],[lon3,lat3], [lon1,lat1]]]
      Keep in mind that for Polygon types the last lon,lat pair has to be equal to the first, this tells the API that it’s closed at that point.

      Circle
      geometry.radius = radius in meters (minimum 50 meters)
      geometry.coordinates = [lon,lat]

      LineString
      geometry.radius = radius in meters
      geometry.coordinates = [[lon1,lat1],[lon2,lat2]]

      when creating geofences you can specify custom properties using the custom key in the properties. This accepts any JSON object value.

      The visibility of the geofences are as follow:

      visibility description
      all anyone with scope to see geofences has access to see them
      groups only people within the group you belong to have access to see the geofence
      private only your user has access to see the geofence

      If you set the visibility to “groups” you’ll have to specify in an array called: groups the group IDs you’d like this geofence to belong to.

      2. Create a post for each geofence to create:

      curl -X POST 
      --header 'Content-Type: application/json' --header "Authenticate: 597015be528ff39fed5c2fefe8ce1ea9b895df6ac71bee05d52a6d5e" 
      --data '{"geometry": {"type": "Circle","radius": 105,"coordinates": [-82.28900,24.78238]},"properties": {"name": "warehouse 234","visibility": "groups","groups": [500],"custom": {"foo": "bar","something": true},"types": [],"description": "this is a sample description"}}' 
      'https://pegasus1.pegasusgateway.com/api/geofences' 
      

      3. Create an script with the cURLs you have just generated:

      #!/bin/bash
      for i in $(seq 1 1);
      do
      
      curl -X POST 
      --header 'Content-Type: application/json' --header "Authenticate: 597015be528ff39fed5c2fefe8ce1ea9b895df6ac71bee05d52a6d5e" 
      --data '{"geometry": {"type": "Circle","radius": 105,"coordinates": [-81.28900,22.78238]},"properties": {"name": "warehouse 234","visibility": "groups","groups": [500],"custom": {"foo": "bar","something": true},"types": [],"description": "this is a sample description"}}' 
      'https://pegasus1.pegasusgateway.com/api/geofences' 
      
      curl -X POST 
      --header 'Content-Type: application/json' --header "Authenticate: 597015be528ff39fed5c2fefe8ce1ea9b895df6ac71bee05d52a6d5e" 
      --data '{"geometry": {"type": "Circle","radius": 105,"coordinates": [-8.5847,25.88954]},"properties": {"name": "test 567","visibility": "groups","groups": [500],"custom": {"foo": "bar","something": true},"types": [],"description": "this is a sample description"}}' 
      'https://pegasus1.pegasusgateway.com/api/geofences' 
      
      done
      

      4. Run the script for Bash (This is a Linux app, but there is a bash application in Windows store as well)

Viewing 0 reply threads
  • You must be logged in to reply to this topic.