class Orion::Geo

Public Class Methods

new() click to toggle source
# File lib/orion/geo/geo.rb, line 7
def initialize
  config = Orion::Config::load_config('http://192.168.99.100:32769')
  @url = config[:orion_url]
end

Public Instance Methods

delete(type, id) click to toggle source

type = type of data E.g: ‘City’ id = id of the object

# File lib/orion/geo/geo.rb, line 83
def delete(type, id)
  action = '/ngsi10/updateContext'

  options = {
    body: {
      contextElements: [
        {
          type: type,
          isPattern: "false",
          id: id
        }
      ]
    }.to_json,
    headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
  }

  HTTParty.post(@url + action, options)
end
pull(type, type_area, array_point) click to toggle source

type = type of data E.g: ‘City’ type_area = ‘circle’ || ‘polygon’

- polygon: array_point = ['lat, long','lat, long','lat, long'] ----- infinite number of points
- circle: array_point = ['lat, long, radius'] ----- radius in meters
# File lib/orion/geo/geo.rb, line 54
def pull(type, type_area, array_point)
  action = '/ngsi10/queryContext'

  options = {
      body: {
      entities: [
        {
          type: type,
          isPattern: "true",
          id: ".*"
        }
      ],
      restriction: {
        scopes: [
          {
            type: "FIWARE::Location",
            value: get_area(type_area, array_point)
          }
        ]
      }
    }.to_json,
    headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
  }

  HTTParty.post(@url + action, options)
end
push(type,id,long,lat) click to toggle source

type = type of data E.g: ‘City’ id = id of the element long = Longitude lat = latitude

# File lib/orion/geo/geo.rb, line 16
def push(type,id,long,lat)
  action = '/ngsi10/updateContext'

  options = {
      body: {
          contextElements: [
            {
              type: type,
              isPattern: "false",
              id: id,
              attributes: [
              {
                name: "position",
                type: "coords",
                value: "#{lat}, #{long}",
                metadatas: [
                  {
                    name: "location",
                    type: "string",
                    value: "WSG84"
                  }
                ]
              }
            ]
          }
          ],
          updateAction: "APPEND"
        }.to_json,
      headers: { 'Content-Type' => 'application/json' }
      }

  HTTParty.post(@url + action, options)
end

Private Instance Methods

get_area(type_area, array_point) click to toggle source

type_area = ‘circle’ || ‘polygon’

- polygon: array_point = ['lat, long','lat, long','lat, long'] ----- infinite number of points
- polygon: array_point = [lat, long, radius] ----- radius in meters
# File lib/orion/geo/geo.rb, line 106
def get_area(type_area, array_point)
  if type_area == 'circle'
    area = {
        circle: {
            centerLatitude: array_point[0],
            centerLongitude: array_point[1],
            radius: array_point[2]
        }
    }
  else
    area = {
        polygon: {
            vertices:
            array_point.map{ |c|
              c = c.split(',')
              {
                  latitude: c[0],
                  longitude: c[1]
              }
            }
        }
    }
  end
  area
end