說明

歡迎使用 SensorThings API 文檔!本文檔講解了 Open Geospatial Consortium (OGC) SensorThings 國際標準的的相關內容。OGC SensorThings API 為物聯網(Internet of Things,IoT)中的所有設備提供了開放且統一的連接方式,也給這些設備的觀測(Observations)提供了可供運用與分析的接口。SensorThings API 標準第壹部分:傳感於 2016 年發布,該部分允許管理和接收由物聯網傳感器獲得的觀察數據或測量數據。發布於 2019 年的第二部分:任務處理核心則提出了壹種操控傳感器或者執行器的機制。

SensorThings API 的基礎是對系統中的實體(entities)在現實世界中的相互關系進行模型化。這些實體之間的自然關系使得任何垂直產業中的物聯網傳感器設備都可被模型化。比如,一個物聯網設備(device)或者一個物聯網系統(system)可模型化為一個物體(Thing),一個物體(Thing)既含有位置(Location),也含有一個或多個數據流(Datastreams)。每個數據流(Datastream)都是通過一個傳感器(Sensor)觀測一個觀測屬性(ObservedProperty)而獲得的,且這個傳感器(Sensor)可能存在多個觀測(Observations)。傳感器(Sensor)觀測(Observation)的是一個特定的被觀測物(FeatureOfInterest)。綜合以上,這些相互關系就可靈活且標準化地描述和模擬各種傳感系統,SensorThings 借助這些相互關系從而實現了為任何組織的異構設備提供了單數據交換的功能。

這份文檔可指導開發人員如何增刪改查(Create-Read-Update-Delete ,CRUD),以及如何通過復雜查詢從系統中取回數據。文檔中一部分示例提供了向 SensorThings 服務器發送請求的模版。

OGC SensorThings API 第壹部分: 傳感 OGC SensorThings API 第二部分: 任務處理

OGC SensorThings API 第二部分 - 任務處理核心討論文件

SensorThings API - Sensing

下圖為OGC SensorThings API的UML數據模型,其中定義了不同的實體以及他們的屬性,同時展示了不同實體之間的關系。

Sensor ObservedProperty Datastream Observation Thing Location HistoricalLocation FeatureOfInterest

SensorThings資源基路徑

想取得資源首先需要獲得資源基路徑。

返回所有可用的SensorThings資源的JSON數組。

[formpanel type=GET] [formtitle] /v1.0/ [/formtitle] [formbody]

[/formbody] [/formpanel]

Things

Thing可能是一個實體世界的物件(實體的物體),也可能是信息世界(虛擬的物體),可被識別和整合進入通訊網路[ITU-T Y.2060]。

Thing是創建SensorThings模型結構的起點,一個Thing有Location(位置)和一個或多個Datastreams(數據流)來Observation(觀測)。一個最精簡的Thing可在不指定Location和Datastreams的情況下創建。同時,Thing也可以通過嵌套Location和Datastreams來創建。

POST

Property Required Type
name mandatory String
description mandatory String
properties optional JSON Object

創建一個Thing時所需的實體:

Entity Required
Locations optional
HistoricalLocations optional
Datastreams optional

示例 1: POST

創建一個Thing。 [tabpanel] [tabpage header=HTTP id=thingspost-example1-1]

{
  "name": "Temperature Monitoring System",
  "description": "Sensor system monitoring area temperature",
  "properties": {
    "Deployment Condition": "Deployed in a third floor balcony",
    "Case Used": "Radiation shield"
  }
}

[/tabpage] [tabpage header=JavaScript/jQuery id=thingspost-example1-2]

var json = JSON.stringify({
  "name": "Temperature Monitoring System",
  "description": "Sensor system monitoring area temperature",
  "properties": {
    "Deployment Condition": "Deployed in a third floor balcony",
    "Case Used": "Radiation shield"
  }
}
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things",
    type: "POST",
    data: json,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);  
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=thingspost-example1-3]

curl -XPOST -H "Content-type: application/json" -d '{
  "name": "Temperature Monitoring System",
  "description": "Sensor system monitoring area temperature",
  "properties": {
    "Deployment Condition": "Deployed in a third floor balcony",
    "Case Used": "Radiation shield"
  }
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things"

[/tabpage] [/tabpanel]

[formpanel type=POST] [formtitle] /v1.0/Things [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 使用新的Location來POST

在創建Thing時,可同時創建跟他相關的Location(位置),這個Location在系統中將以一個新的Location進行存儲。

[tabpanel] [tabpage header=HTTP id=thingspost-example2-1]

{
  "name": "Temperature Monitoring System",
  "description": "Sensor system monitoring area temperature",
  "properties": {
    "Deployment Condition": "Deployed in a third floor balcony",
    "Case Used": "Radiation shield"
  },
  "Locations": [{
    "name": "UofC CCIT",
    "description": "University of Calgary, CCIT building",
    "encodingType": "application/vnd.geo+json",
    "location": {
      "type": "Point",
      "coordinates": [-114.133, 51.08]
    }
  }]
}

[/tabpage] [tabpage header=JavaScript/jQuery id=thingspost-example2-2]

var json = JSON.stringify({
  "name": "Temperature Monitoring System",
  "description": "Sensor system monitoring area temperature",
  "properties": {
    "Deployment Condition": "Deployed in a third floor balcony",
    "Case Used": "Radiation shield"
  },
  "Locations": [{
    "name": "UofC CCIT",
    "description": "University of Calgary, CCIT building",
    "encodingType": "application/vnd.geo+json",
    "location": {
      "type": "Point",
      "coordinates": [-114.133, 51.08]
    }
  }]
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things",
    type: "POST",
    data: json,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=thingspost-example2-3]

curl -X POST -H "Content-Type: application/json" -d '{
  "name": "Temperature Monitoring System",
  "description": "Sensor system monitoring area temperature",
  "properties": {
    "Deployment Condition": "Deployed in a third floor balcony",
    "Case Used": "Radiation shield"
  },
  "Locations": [{
    "name": "UofC CCIT",
    "description": "University of Calgary, CCIT building",
    "encodingType": "application/vnd.geo+json",
    "location": {
      "type": "Point",
      "coordinates": [-114.133, 51.08]
    }
  }]
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things"

[/tabpage] [/tabpanel]

[formpanel type=POST] [formtitle] /v1.0/Things [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 3: 鏈接已存在的Location來POST

創建一個Thing,並將其綁定一個已存在的Location id。

[tabpanel] [tabpage header=HTTP id=thingspost-example3-1]

{
  "name": "Temperature Monitoring System",
  "description": "Sensor system monitoring area temperature",
  "properties": {
    "Deployment Condition": "Deployed in a third floor balcony",
    "Case Used": "Radiation shield"
  },
  "Locations": [
    {"@iot.id":1}
  ]
}

[/tabpage] [tabpage header=JavaScript/jQuery id=thingspost-example3-2]

var json = JSON.stringify({
  "name": "Temperature Monitoring System",
  "description": "Sensor system monitoring area temperature",
  "properties": {
    "Deployment Condition": "Deployed in a third floor balcony",
    "Case Used": "Radiation shield"
  },
  "Locations": [
    {"@iot.id":1}
  ]
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things",
    type: "POST",
    data: json,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=thingspost-example3-3]

curl -XPOST -H "Content-type: application/json" -d '{
  "name": "Temperature Monitoring System",
  "description": "Sensor system monitoring area temperature",
  "properties": {
    "Deployment Condition": "Deployed in a third floor balcony",
    "Case Used": "Radiation shield"
  },
  "Locations": [
    {"@iot.id":1}
  ]
}' 'https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things'

[/tabpage] [/tabpanel]

[formpanel type=POST] [formtitle] /v1.0/Things [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 4: 嵌入Location和Datastream來POST

創建一個Thing,並嵌入Location和Datastream。在請求正文中嵌入完整的JSON實體的對象表示,便可與相關實體進行連接。

[tabpanel] [tabpage header=HTTP id=thingspost-example4-1]

{
  "name": "Temperature Monitoring System",
  "description": "Sensor system monitoring area temperature",
  "properties": {
    "Deployment Condition": "Deployed in a third floor balcony",
    "Case Used": "Radiation shield"
  },
  "Locations": [{
    "name": "UofC CCIT",
    "description": "University of Calgary, CCIT building",
    "encodingType": "application/vnd.geo+json",
    "location": {
      "type": "Point",
      "coordinates": [-114.133, 51.08]
    }
  }],
  "Datastreams": [{
    "name": "Air Temperature DS",
    "description": "Datastream for recording temperature",
    "observationType": "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement",
    "unitOfMeasurement": {
      "name": "Degree Celsius",
      "symbol": "degC",
      "definition": "http://www.qudt.org/qudt/owl/1.0.0/unit/Instances.html#DegreeCelsius"
    },
    "ObservedProperty": {
      "name": "Area Temperature",
      "description": "The degree or intensity of heat present in the area",
      "definition": "http://www.qudt.org/qudt/owl/1.0.0/quantity/Instances.html#AreaTemperature"
    },
    "Sensor": {
      "name": "DHT22",
      "description": "DHT22 temperature sensor",
      "encodingType": "application/pdf",
      "metadata": "https://cdn-shop.adafruit.com/datasheets/DHT22.pdf"
    }
  }]
}

[/tabpage] [tabpage header=JavaScript/jQuery id=thingspost-example4-2]

var json = JSON.stringify({
  "name": "Temperature Monitoring System",
  "description": "Sensor system monitoring area temperature",
  "properties": {
    "Deployment Condition": "Deployed in a third floor balcony",
    "Case Used": "Radiation shield"
  },
  "Locations": [{
    "name": "UofC CCIT",
    "description": "University of Calgary, CCIT building",
    "encodingType": "application/vnd.geo+json",
    "location": {
      "type": "Point",
      "coordinates": [-114.133, 51.08]
    }
  }],
  "Datastreams": [{
    "name": "Air Temperature DS",
    "description": "Datastream for recording temperature",
    "observationType": "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement",
    "unitOfMeasurement": {
      "name": "Degree Celsius",
      "symbol": "degC",
      "definition": "http://www.qudt.org/qudt/owl/1.0.0/unit/Instances.html#DegreeCelsius"
    },
    "ObservedProperty": {
      "name": "Area Temperature",
      "description": "The degree or intensity of heat present in the area",
      "definition": "http://www.qudt.org/qudt/owl/1.0.0/quantity/Instances.html#AreaTemperature"
    },
    "Sensor": {
      "name": "DHT22",
      "description": "DHT22 temperature sensor",
      "encodingType": "application/pdf",
      "metadata": "https://cdn-shop.adafruit.com/datasheets/DHT22.pdf"
    }
  }]
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things",
    type: "POST",
    data: json,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=thingspost-example4-3]

curl -XPOST -H "Content-type: application/json" -d '{
  "name": "Temperature Monitoring System",
  "description": "Sensor system monitoring area temperature",
  "properties": {
    "Deployment Condition": "Deployed in a third floor balcony",
    "Case Used": "Radiation shield"
  },
  "Locations": [{
    "name": "UofC CCIT",
    "description": "University of Calgary, CCIT building",
    "encodingType": "application/vnd.geo+json",
    "location": {
      "type": "Point",
      "coordinates": [-114.133, 51.08]
    }
  }],
  "Datastreams": [{
    "name": "Air Temperature DS",
    "description": "Datastream for recording temperature",
    "observationType": "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement",
    "unitOfMeasurement": {
      "name": "Degree Celsius",
      "symbol": "degC",
      "definition": "http://www.qudt.org/qudt/owl/1.0.0/unit/Instances.html#DegreeCelsius"
    },
    "ObservedProperty": {
      "name": "Area Temperature",
      "description": "The degree or intensity of heat present in the area",
      "definition": "http://www.qudt.org/qudt/owl/1.0.0/quantity/Instances.html#AreaTemperature"
    },
    "Sensor": {
      "name": "DHT22",
      "description": "DHT22 temperature sensor",
      "encodingType": "application/pdf",
      "metadata": "https://cdn-shop.adafruit.com/datasheets/DHT22.pdf"
    }
  }]
}' 'https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things'

[/tabpage] [/tabpanel]

[formpanel type=POST] [formtitle] /v1.0/Things [/formtitle] [formbody]

[/formbody] [/formpanel]

GET

示例 1: GET

取回所有的Thing。

[tabpanel] [tabpage header=HTTP id=Things-get-1]

https://toronto-bike-snapshot.sensorup.com/v1.0/Things

[/tabpage] [tabpage header=JavaScript/jQuery id=Things-get-2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/Things",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=Things-get-3]

curl -X GET -H "Content-Type: application/json" "https://toronto-bike-snapshot.sensorup.com/v1.0/Things"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/Things [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 使用id來GET

取回一個指定的Thing。

[formpanel type=GET] [formtitle] /v1.0/Things(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 3: 使用expand來GET

使用$expand查詢選項,取回一個Thing和其所包含的實體,可取回多實體集合或單一實體。

$expand相關實體 描述
Locations 展示Thing實體內Location詳細內容
Datastreams 展示Thing實體內Datastreams詳細內容
HistoricalLocations 展示Thing實體內HistoricalLocation詳細內容

[formpanel type=GET] [formtitle] /v1.0/Things(id)?$expand=Datastreams [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 4: 使用select來GET

取回一個指定的Thing的特定屬性。

$select查詢屬性 Description
name Thing的實體名稱
description Thing的實體描述
properties Thing的物體屬性
Locations 從Thing到Location的鏈接
Datastreams 從Thing到Datastream的鏈接
HistoricalLocations 從Thing到HistoricalLocations的鏈接

[formpanel type=GET] [formtitle] /v1.0/Things(id)?$select=description [/formtitle] [formbody]

[/formbody] [/formpanel]

PATCH

更新一個指定Thing的屬性。

[tabpanel] [tabpage header=HTTP id=things-patch-1]

{
  "description": "WiFi Water Temperature System",
  "properties": {
    "detail": "3 ft water sealed, external temperature probe.",
    "WiFi-range": "Up to 250 ft.* (Typical to standard WiFi devices)"
  },
  "Locations": [
    {"@iot.id":1}
  ]
}

[/tabpage] [tabpage header=JavaScript/jQuery id=things-patch-2]

var patchJson = JSON.stringify({
  "description": "WiFi Water Temperature System",
  "properties": {
    "detail": "3 ft water sealed, external temperature probe.",
    "WiFi-range": "Up to 250 ft.* (Typical to standard WiFi devices)"
  },
  "Locations": [
    {"@iot.id":1}
  ]
});

$.ajax({
  url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things(2)",
  type: "PATCH",
  data: patchJson,
  contentType: "application/json; charset=utf-8",
  success: function(data){
    console.log(data);

  },
  error: function(response, status){
    console.log(response);
    console.log(status);
  }
});

[/tabpage] [tabpage header=cURL id=things-patch-3]

curl -X PATCH -H "Content-Type: application/json" -d '{
  "description": "WiFi Water Temperature System",
  "properties": {
    "detail": "3 ft water sealed, external temperature probe.",
    "WiFi-range": "Up to 250 ft.* (Typical to standard WiFi devices)"
  },
  "Locations": [
    {"@iot.id":1}
  ]
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things(2)"

[/tabpage] [/tabpanel]

[formpanel type=PATCH] [formtitle] /v1.0/Things(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

DELETE

刪除一個Thing。 [tabpanel] [tabpage header=HTTP id=Things-delete-1]

https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things(id)

[/tabpage] [tabpage header=JavaScript/jQuery id=Things-delete-2]

$.ajax({
  url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things(id)",
  type: "DELETE",
  contentType: "application/json; charset=utf-8",
  success: function(data){
    console.log(data);
  },
  error: function(response, status){
    console.log(response);
    console.log(status);
  }
});

[/tabpage] [tabpage header=cURL id=Things-delete-3]

curl -X DELETE -H "Content-Type: application/json" -H -d '' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things(id)"

[/tabpage] [/tabpanel]

[formpanel type=DELETE] [formtitle] /v1.0/Things(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

Locations

Location(位置)實體記錄Thing(s)關聯的位置。一個Thing的Location實體被定義為Thing最後已知的位置(物理位置)。 當一個location(物理位置)存在多種encodingType(編碼類型)時,此時的Thing可關聯多個Locations。

POST

Property Required Type
name mandatory String
description mandatory String
encodingType mandatory ValueCode
location mandatory Any (Depends on encodingType)

創建一個Location所需的實體:

Entity Required
Things optional
HistoricalLocations optional

示例 1: POST

創建一個Location。

[tabpanel] [tabpage header=HTTP id=Locaitons-post-1]

{
  "name": "UofC CCIT",
  "description": "University of Calgary, CCIT building",
  "encodingType": "application/vnd.geo+json",
  "location": {
    "type": "Point",
    "coordinates": [-114.133, 51.08]
  }
}

[/tabpage] [tabpage header=JavaScript/jQuery id=Locaitons-post-2]

var location = JSON.stringify({
  "name": "UofC CCIT",
  "description": "University of Calgary, CCIT building",
  "encodingType": "application/vnd.geo+json",
  "location": {
    "type": "Point",
    "coordinates": [-114.133, 51.08]
  }
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Locations",
    type: "POST",
    data: location,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=Locaitons-post-3]

curl -XPOST -H "Content-type: application/json" -d '{
  "name": "UofC CCIT",
  "description": "University of Calgary, CCIT building",
  "encodingType": "application/vnd.geo+json",
  "location": {
    "type": "Point",
    "coordinates": [-114.133, 51.08]
  }
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Locations"

[/tabpage] [/tabpanel]

[formpanel type=POST] [formtitle] /v1.0/Locations [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 鏈接已存在的Thing來POST

創建一個Location,並將其綁定一個已存在的Thing。

[tabpanel] [tabpage header=HTTP id=Locaitons-post2-1]

{
  "name": "UofC CCIT",
  "description": "University of Calgary, CCIT building",
  "encodingType": "application/vnd.geo+json",
  "location": {
    "type": "Point",
    "coordinates": [-114.133, 51.08]
  }
}

[/tabpage] [tabpage header=JavaScript/jQuery id=Locaitons-post2-2]

var location = JSON.stringify({
  "name": "UofC CCIT",
  "description": "University of Calgary, CCIT building",
  "encodingType": "application/vnd.geo+json",
  "location": {
    "type": "Point",
    "coordinates": [-114.133, 51.08]
  }
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things(705831)/Locations",
    type: "POST",
    data: location,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=Locaitons-post2-3]

curl -XPOST -H "Content-type: application/json" -d '{
  "name": "UofC CCIT",
  "description": "University of Calgary, CCIT building",
  "encodingType": "application/vnd.geo+json",
  "location": {
    "type": "Point",
    "coordinates": [-114.133, 51.08]
  }
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Things(705831)/Locations"

[/tabpage] [/tabpanel]

[formpanel type=POST] [formtitle] /v1.0/Things(id)/Locations [/formtitle] [formbody]

[/formbody] [/formpanel]

GET

示例 1: GET

取回所有的Location。

[tabpanel] [tabpage header=HTTP id=Locaitons-get-tab1-1]

https://toronto-bike-snapshot.sensorup.com/v1.0/Locations

[/tabpage] [tabpage header=JavaScript/jQuery id=Locaitons-get-tab1-2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/Locations",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=Locaitons-get-tab1-3]

curl -X GET -H "Content-Type: application/json" "https://toronto-bike-snapshot.sensorup.com/v1.0/Locations"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/Locations [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 使用id來GET

取回一個指定的Location。

[formpanel type=GET] [formtitle] /v1.0/Locations(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 3: 使用Thing id來GET

取回一個指定Thing的Locations。

[formpanel type=GET] [formtitle] /v1.0/Things(id)/Locations [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 4: 使用expand來GET

使用$expand查詢選項,取回一個指定的Location和其所包含的實體。

$expand相關實體 描述
Things 顯示Location內部的Thing詳細內容
HistoricalLocations 現實Location內部的HistoricalLocation詳細內容

[formpanel type=GET] [formtitle] /v1.0/Locations(id)?$expand=Things [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 5: 使用filter來GET(空間查詢)

取回指定的多邊形中的所有Locations,並擴展到Thing實體來取回所有元數據。

[formpanel type=GET] [formtitle] /v1.0/Locations?$expand=Things&$filter=st_within(location, geography’POLYGON ((-79.39 43.651,-79.371 43.651,-79.371 43.641,-79.39 43.641,-79.39 43.651))’) [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 6: 使用select來GET

從指定Location中取回特定的屬性。

$select查詢屬性 描述
name Location名稱
description Location描述
encodingType Location的編碼類型
location 編碼類型定義的location
Thing 從Location到Thing的鏈接
HistoricalLocations 從Location到HistoricalLocations的鏈接

[formpanel type=GET] [formtitle] /v1.0/Locations(id)?$select=description [/formtitle] [formbody]

[/formbody] [/formpanel]

PATCH

更新Location的屬性值。

[tabpanel] [tabpage header=HTTP id=Location-patch-1]

{
  "name": "Edworthy Park Area",
  "location": {
    "type": "Point",
    "coordinates": [-114.154,51.064]
  }
}

[/tabpage] [tabpage header=JavaScript/jQuery id=Location-patch-2]

var patchJson = JSON.stringify({
  "name": "Edworthy Park Area",
  "location": {
    "type": "Point",
    "coordinates": [-114.154,51.064]
  }
});

$.ajax({
  url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Location(1)",
  type: "PATCH",
  data: patchJson,
  contentType: "application/json; charset=utf-8",
  success: function(data){
    console.log(data);

  },
  error: function(response, status){
    console.log(response);
    console.log(status);
  }
});

[/tabpage] [tabpage header=cURL id=Location-patch-3]

curl -X PATCH -H "Content-Type: application/json" -d '{
  "name": "Edworthy Park Area",
  "location": {
    "type": "Point",
    "coordinates": [-114.154,51.064]
  }
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Location(2)"

[/tabpage] [/tabpanel]

[formpanel type=PATCH] [formtitle] /v1.0/Locations(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

DELETE

刪除一個Location。

[tabpanel] [tabpage header=HTTP id=Locations-delete-1]

https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Locations(id)

[/tabpage] [tabpage header=JavaScript/jQuery id=Locations-delete-2]

$.ajax({
  url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Locations(id)",
  type: "DELETE",
  contentType: "application/json; charset=utf-8",
  success: function(data){
    console.log(data);
  },
  error: function(response, status){
    console.log(response);
    console.log(status);
  }
});

[/tabpage] [tabpage header=cURL id=Locations-delete-3]

curl -X DELETE -H "Content-Type: application/json" -H -d '' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Locations(id)"

[/tabpage] [/tabpanel]

[formpanel type=DELETE] [formtitle] /v1.0/Locations(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

HistoricalLocations

Thing的HistoricalLocation(歷史位置)實體提供了Thing的當前(最後已知)和之前所有locations的時間。

GET

Exmaple 1: GET

取回所有的HistoricalLocations。

[tabpanel] [tabpage header=HTTP id=HistoricalLocations-get-tab-1]

https://toronto-bike-snapshot.sensorup.com/v1.0/HistoricalLocations

[/tabpage] [tabpage header=JavaScript/jQuery id=HistoricalLocations-get-tab-2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/HistoricalLocations",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=HistoricalLocations-get-tab-3]

curl -X GET -H "Content-Type: application/json" "https://toronto-bike-snapshot.sensorup.com/v1.0/HistoricalLocations"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/HistoricalLocations [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 使用id來GET

取回指定的HistoricalLocations。

[formpanel type=GET] [formtitle] /v1.0/HistoricalLocations(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 3: 使用expand來GET

使用$expand查詢選項取回指定的HistoricalLocations以及其包含的相關實體信息。

$expand相關實體 描述
Locations 顯示HistoricalLocations內部的Location詳細內容
Thing 顯示HistoricalLocations內部的Thing詳細內容

[formpanel type=GET] [formtitle] /v1.0/HistoricalLocations(id)?$expand=Locations [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 4: 使用select來GET

從指定的HistoricalLocation取回特定的屬性數據。

$select查詢屬性 描述
time HistoricalLocation的時間
Locations 從HistoricalLocation到Locations鏈接
Thing 從HistoricalLocation到Thing的鏈接

[formpanel type=GET] [formtitle] /v1.0/HistoricalLocations(id)?$select=time [/formtitle] [formbody]

[/formbody] [/formpanel]

PATCH

更新HistoricalLocation的屬性值。

[tabpanel] [tabpage header=HTTP id=HistoricalLocation-patch-tab-1]

{
  "time": "2015-02-07T19:22:11.297Z"
}

[/tabpage] [tabpage header=JavaScript/jQuery id=HistoricalLocation-patch-tab-2]

var patchJson = JSON.stringify({
  "time": "2015-02-07T19:22:11.297Z"
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/HistoricalLocations(id)",
    type: "PATCH",
    data: patchJson,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);

    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=HistoricalLocation-patch-tab-3]

curl -X PATCH -H "Content-Type: application/json" -d '{
  "time": "2015-02-07T19:22:11.297Z"
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/HistoricalLocations(id)"

[/tabpage] [/tabpanel]

[formpanel type=PATCH] [formtitle] /v1.0/HistoricalLocations(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

DELETE

刪除一個HistoricalLocation。

[tabpanel] [tabpage header=HTTP id=HistoricalLocation-delete-tab-1]

https://scratchpad.sensorup.com/OGCSensorThings/v1.0/HistoricalLocation(id)

[/tabpage] [tabpage header=JavaScript/jQuery id=HistoricalLocation-delete-tab-2]

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/HistoricalLocations(id)",
    type: "DELETE",
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=HistoricalLocation-delete-tab-3]

curl -X DELETE -H "Content-Type: application/json" -H -d '' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/HistoricalLocations(id)"

[/tabpage] [/tabpanel]

[formpanel type=DELETE] [formtitle] /v1.0/HistoricalLocations(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

Datastreams

同一個Sensor(傳感器)測量同一個ObservedProperty(觀測屬性)Observations(觀測)的集合,稱之為Datastream(數據流)。

POST

Property Required Type
name mandatory String
description mandatory String
unitOfMeasurement mandatory JSON Object
observationType mandatory ValueCode
observedArea optional GeoJSON Polygon Object
phenomenonTime optional Time Interval (ISO 8601)
resultTime optional Time Interval (ISO 8601)

創建一個Datastream所需的實體:

Entity Required
Thing mandatory
ObservedProperty mandatory
Sensor mandatory
Observations optional

示例 1: POST

創建一個Datastream。

[tabpanel] [tabpage header=HTTP id=datastream-post-tab-1]

{
  "name": "Air Temperature DS",
  "description": "Datastream for recording temperature",
  "observationType": "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement",
  "unitOfMeasurement": {
    "name": "Degree Celsius",
    "symbol": "degC",
    "definition": "http://www.qudt.org/qudt/owl/1.0.0/unit/Instances.html#DegreeCelsius"
  },
  "Thing":{"@iot.id":2},
  "ObservedProperty":{"@iot.id":7},
  "Sensor":{"@iot.id":6}
}

[/tabpage] [tabpage header=JavaScript/jQuery id=datastream-post-tab-2]

var json = JSON.stringify({
  "name": "Air Temperature DS",
  "description": "Datastream for recording temperature",
  "observationType": "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement",
  "unitOfMeasurement": {
    "name": "Degree Celsius",
    "symbol": "degC",
    "definition": "http://www.qudt.org/qudt/owl/1.0.0/unit/Instances.html#DegreeCelsius"
  },
  "Thing":{"@iot.id":2},
  "ObservedProperty":{"@iot.id":7},
  "Sensor":{"@iot.id":6}
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Datastreams",
    type: "POST",
    data: json,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=datastream-post-tab-3]

curl -X POST -H "Content-Type: application/json" -d '{
  "name": "Air Temperature DS",
  "description": "Datastream for recording temperature",
  "observationType": "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement",
  "unitOfMeasurement": {
    "name": "Degree Celsius",
    "symbol": "degC",
    "definition": "http://www.qudt.org/qudt/owl/1.0.0/unit/Instances.html#DegreeCelsius"
  },
  "Thing":{"@iot.id":2},
  "ObservedProperty":{"@iot.id":7},
  "Sensor":{"@iot.id":6}
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Datastreams"

[/tabpage] [/tabpanel]

[formpanel type=POST] [formtitle] /v1.0/Datastreams [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 鏈接已存在的Thing來POST

創建一個Datastream,並將其綁定一個已存在的Thing。

[tabpanel] [tabpage header=HTTP id=datastream-post-2-tab-1]

{
  "name": "Air Temperature DS",
  "description": "Datastream for recording temperature",
  "observationType": "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement",
  "unitOfMeasurement": {
    "name": "Degree Celsius",
    "symbol": "degC",
    "definition": "http://www.qudt.org/qudt/owl/1.0.0/unit/Instances.html#DegreeCelsius"
  },
  "ObservedProperty": {
    "name": "Area Temperature",
    "description": "The degree or intensity of heat present in the area",
    "definition": "http://www.qudt.org/qudt/owl/1.0.0/quantity/Instances.html#AreaTemperature"
  },
  "Sensor": {
    "name": "DHT22",
    "description": "DHT22 temperature sensor",
    "encodingType": "application/pdf",
    "metadata": "https://cdn-shop.adafruit.com/datasheets/DHT22.pdf"
  }
}

[/tabpage] [tabpage header=JavaScript/jQuery id=datastream-post-2-tab-2]

var json = JSON.stringify({
  "name": "Air Temperature DS",
  "description": "Datastream for recording temperature",
  "observationType": "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement",
  "unitOfMeasurement": {
    "name": "Degree Celsius",
    "symbol": "degC",
    "definition": "http://www.qudt.org/qudt/owl/1.0.0/unit/Instances.html#DegreeCelsius"
  },
  "ObservedProperty": {
    "name": "Area Temperature",
    "description": "The degree or intensity of heat present in the area",
    "definition": "http://www.qudt.org/qudt/owl/1.0.0/quantity/Instances.html#AreaTemperature"
  },
  "Sensor": {
    "name": "DHT22",
    "description": "DHT22 temperature sensor",
    "encodingType": "application/pdf",
    "metadata": "https://cdn-shop.adafruit.com/datasheets/DHT22.pdf"
  }
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Datastreams",
    type: "POST",
    data: json,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=datastream-post-2-tab-3]

curl -X POST -H "Content-Type: application/json" -d '{
  "name": "Air Temperature DS",
  "description": "Datastream for recording temperature",
  "observationType": "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement",
  "unitOfMeasurement": {
    "name": "Degree Celsius",
    "symbol": "degC",
    "definition": "http://www.qudt.org/qudt/owl/1.0.0/unit/Instances.html#DegreeCelsius"
  },
  "ObservedProperty": {
    "name": "Area Temperature",
    "description": "The degree or intensity of heat present in the area",
    "definition": "http://www.qudt.org/qudt/owl/1.0.0/quantity/Instances.html#AreaTemperature"
  },
  "Sensor": {
    "name": "DHT22",
    "description": "DHT22 temperature sensor",
    "encodingType": "application/pdf",
    "metadata": "https://cdn-shop.adafruit.com/datasheets/DHT22.pdf"
  }
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Datastreams"

[/tabpage] [/tabpanel]

[formpanel type=POST] [formtitle] /v1.0/Things(id)/Datastreams [/formtitle] [formbody]

[/formbody] [/formpanel]

GET

示例 1: GET

取回所有的Datastreams。

[tabpanel] [tabpage header=HTTP id=Datastreams-get-tab-1-1]

https://toronto-bike-snapshot.sensorup.com/v1.0/Datastreams

[/tabpage] [tabpage header=JavaScript/jQuery id=Datastreams-get-tab-1-2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/Datastreams",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=Datastreams-get-tab-1-3]

curl -X GET -H "Content-Type: application/json" "https://toronto-bike-snapshot.sensorup.com/v1.0/Datastreams"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/Datastreams [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 使用id來GET

取回指定的Datastream。

[formpanel type=GET] [formtitle] /v1.0/Datastreams(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 3: 使用Thing id來GET

取回指定Thing的Datastream。

[formpanel type=GET] [formtitle] /v1.0/Things(id)/Datastreams [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 4: 使用expand來GET

使用$expand查詢選項,取回一個指定的Datastream和其所包含的實體。

$expand相關實體 描述
Thing 顯示Datastreams內部的Thing詳細內容
Sensor 顯示Datastreams內部的Sensor詳細內容
ObservedProperty 時線Datastreams內部的ObservedProperty詳細內容
Observations 顯示Datastreams內部的Observations詳細內容

[formpanel type=GET] [formtitle] /v1.0/Datastreams(id)?$expand=Observations,ObservedProperty [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 5: 使用select來GET

從一個指定的Datastream取回特定的屬性數據。

$select查詢屬性 描述
name Datastream名稱
description Datastream描述
unitOfMeasurement 傳感器測量單位(Unit Of Measurement)的JSON對象
observationType 觀測類型
observedArea Datastream相關的Observations在空間範圍
phenomenonTime Datastream所有Observations的出現時間範圍
resultTime Datastream所有Observations的結果時間範圍
Thing 從Datastream到Thing的鏈接
Sensor 從Datastream到Sensor的鏈接
ObservedProperty 從Datastream到ObservedProperty的鏈接
Observations 從Datastream到Datastream的鏈接

[formpanel type=GET] [formtitle] /v1.0/Datastreams(id)?$select=description,unitOfMeasurement [/formtitle] [formbody]

[/formbody] [/formpanel]

PATCH

更新一個Datastream屬性值。 [tabpanel] [tabpage header=HTTP id=datastream-patch-tab-1]

{
  "unitOfMeasurement": {
    "name": "Degrees Fahrenheit",
    "symbol": "degF",
    "definition": "http://www.qudt.org/qudt/owl/1.0.0/unit/Instances.html#DegreeFahrenheit"
  },
  "description": "Water Temperature of Bow river"
}

[/tabpage] [tabpage header=JavaScript/jQuery id=datastream-patch-tab-2]

var patchJson = JSON.stringify({
  "unitOfMeasurement": {
    "name": "Degrees Fahrenheit",
    "symbol": "degF",
    "definition": "http://www.qudt.org/qudt/owl/1.0.0/unit/Instances.html#DegreeFahrenheit"
  },
  "description": "Water Temperature of Bow river"
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Datastreams(id)",
    type: "PATCH",
    data: patchJson,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);

    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=datastream-patch-tab-3]

curl -X PATCH -H "Content-Type: application/json" -d '{
  "unitOfMeasurement": {
    "name": "Degrees Fahrenheit",
    "symbol": "degF",
    "definition": "http://www.qudt.org/qudt/owl/1.0.0/unit/Instances.html#DegreeFahrenheit"
  },
  "description": "Water Temperature of Bow river"
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Datastreams(id)"

[/tabpage] [/tabpanel]

[formpanel type=PATCH] [formtitle] /v1.0/Datastreams(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

DELETE

刪除一個Datastream。 [tabpanel] [tabpage header=HTTP id=datastream-delete-tab-1]

https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Datastream(id)

[/tabpage] [tabpage header=JavaScript/jQuery id=datastream-delete-tab-2]

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Datastreams(id)",
    type: "DELETE",
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=datastream-delete-tab-3]

curl -X DELETE -H "Content-Type: application/json" -H -d '' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Datastreams(id)"

[/tabpage] [/tabpanel]

[formpanel type=DELETE] [formtitle] /v1.0/Datastreams(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

Sensors

傳感器(Sensor)在SensorThing API是測量儀器,負責觀測一個屬性或一種現象,並記錄其得到的觀測值。

POST

Property Required Type
name mandatory String
description mandatory String
encodingType mandatory ValueCode
metadata mandatory Any (depending on the value of the encodingType)

示例 1: POST

創建一個Sensor。

[tabpanel] [tabpage header=HTTP id=sensor-post-tab-1]

{
  "name": "DHT22",
  "description": "DHT22 temperature sensor",
  "encodingType": "application/pdf",
  "metadata": "https://cdn-shop.adafruit.com/datasheets/DHT22.pdf"
}

[/tabpage] [tabpage header=JavaScript/jQuery id=sensor-post-tab-2]

var json = JSON.stringify({
  "name": "DHT22",
  "description": "DHT22 temperature sensor",
  "encodingType": "application/pdf",
  "metadata": "https://cdn-shop.adafruit.com/datasheets/DHT22.pdf"
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Sensors",
    type: "POST",
    data: json,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        //To access a data field
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=sensor-post-tab-3]

curl -X POST -H "Content-Type: application/json" -d '{
  "name": "DHT22",
  "description": "DHT22 temperature sensor",
  "encodingType": "application/pdf",
  "metadata": "https://cdn-shop.adafruit.com/datasheets/DHT22.pdf"
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Sensors"

[/tabpage] [/tabpanel]

[formpanel type=POST] [formtitle] /v1.0/Sensors [/formtitle] [formbody]

[/formbody] [/formpanel]

GET

示例 1: GET

取回所有Sensor。

[tabpanel] [tabpage header=HTTP id=Sensors-get-tab-1-1]

https://toronto-bike-snapshot.sensorup.com/v1.0/Sensors

[/tabpage] [tabpage header=JavaScript/jQuery id=Sensors-get-tab-1-2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/Sensors",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=Sensors-get-tab-1-3]

curl -X GET -H "Content-Type: application/json" "https://toronto-bike-snapshot.sensorup.com/v1.0/Sensors"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/Sensors [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 使用id來Get

取回一個指定Sensor。

[formpanel type=GET] [formtitle] /v1.0/Sensors(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 3: 使用expand來GET

使用$expand查詢選項,取回一個Sensor和其所包含的實體,可取回多實體集合或單一實體。

$expand相關實體 Description
Datastreams 顯示Datastreams內部的Sensors詳細內容

[formpanel type=GET] [formtitle] /v1.0/Sensors(id)?$expand=Datastreams [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 4: 使用select來GET

從一個指定的Sensor中取回特定的屬性數據。

$select查詢屬性 Description
name Sensor實體名稱
description Sensor實體描述
encodingType 元數據屬性的編碼類型
metadata Sensor或系統的詳細描述,元數據類型由encodingType定義
Datastreams 從Sensor到Datastreams的鏈接

[formpanel type=GET] [formtitle] /v1.0/Sensors(id)?$select=description [/formtitle] [formbody]

[/formbody] [/formpanel]

PATCH

更新一個Sensor屬性值。 [tabpanel] [tabpage header=HTTP id=Sensors-patch-tab-1]

{
  "description": "DHT22 Temperature and Humidity sensor"
}

[/tabpage] [tabpage header=JavaScript/jQuery id=Sensors-patch-tab-2]

var patchJson = JSON.stringify({
  "description": "DHT22 Temperature and Humidity sensor"
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Sensors(id)",
    type: "PATCH",
    data: patchJson,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);

    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=Sensors-patch-tab-3]

curl -X PATCH -H "Content-Type: application/json" -d '{
  "description": "DHT22 Temperature and Humidity sensor"
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Sensors(id)"

[/tabpage] [/tabpanel]

[formpanel type=PATCH] [formtitle] /v1.0/Sensors(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

DELETE

刪除一個Sensor。 [tabpanel] [tabpage header=HTTP id=Sensors-delete-tab-1]

https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Sensors(id)

[/tabpage] [tabpage header=JavaScript/jQuery id=Sensors-delete-tab-2]

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Sensors(id)",
    type: "DELETE",
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=Sensors-delete-tab-3]

curl -X DELETE -H "Content-Type: application/json" -H -d '' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Sensors(id)"

[/tabpage] [/tabpanel]

[formpanel type=DELETE] [formtitle] /v1.0/Sensors(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

ObservedProperties

一個ObservedProperty特指一個觀測值(Observation)的現象。

POST

Property Required Type
name mandatory String
definition mandatory URI
description mandatory String

示例 1: POST

創建一個ObservedProperty。

[tabpanel] [tabpage header=HTTP id=ObservedProperties-post-tab-1]

{
  "name": "Area Temperature",
  "description": "The degree or intensity of heat present in the area",
  "definition": "http://www.qudt.org/qudt/owl/1.0.0/quantity/Instances.html#AreaTemperature"
}

[/tabpage] [tabpage header=JavaScript/jQuery id=ObservedProperties-post-tab-2]

var json = JSON.stringify({
  "name": "Area Temperature",
  "description": "The degree or intensity of heat present in the area",
  "definition": "http://www.qudt.org/qudt/owl/1.0.0/quantity/Instances.html#AreaTemperature"
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/ObservedProperties",
    type: "POST",
    data: json,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=ObservedProperties-post-tab-3]

curl -X POST -H "Content-Type: application/json" -d '{
  "name": "Area Temperature",
  "description": "The degree or intensity of heat present in the area",
  "definition": "http://www.qudt.org/qudt/owl/1.0.0/quantity/Instances.html#AreaTemperature"
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/ObservedProperties"

[/tabpage] [/tabpanel]

[formpanel type=POST] [formtitle] /v1.0/ObservedProperties [/formtitle] [formbody]

[/formbody] [/formpanel]

GET

示例 1: GET

取回所有的ObservedProperty。

[tabpanel] [tabpage header=HTTP id=ObservedProperties-get-tab-1-1]

https://toronto-bike-snapshot.sensorup.com/v1.0/ObservedProperties

[/tabpage] [tabpage header=JavaScript/jQuery id=ObservedProperties-get-tab-1-2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/ObservedProperties",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=ObservedProperties-get-tab-1-3]

curl -X GET -H "Content-Type: application/json" "https://toronto-bike-snapshot.sensorup.com/v1.0/ObservedProperties"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/ObservedProperties [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 使用id來GET

取回一個指定的ObservedProperty。

[formpanel type=GET] [formtitle] /v1.0/ObservedProperties(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 3: 使用Datastream id來GET

取回一個指定的Datastream的ObservedProperty。

[formpanel type=GET] [formtitle] /v1.0/Datastream(id)/ObservedProperty [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 4: 使用expand來GET

使用$expand查詢選項,取回一個指定的ObservedProperty和其所包含的實體。

$expand相關實體 描述
Datastreams 顯示這個ObservedProperties的Datastreams的詳細內容

[formpanel type=GET] [formtitle] /v1.0/ObservedProperties(id)?$expand=Datastreams [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 5: 使用select來GET

從特定的ObservedProperty取回特定的屬性數據。

$expand相關實體 描述
name ObservedProperty實體名稱
definition ObservedProperty定義的URI
description ObservedPropert實體描述
Datastreams 從ObservedProperty到Datastreams的鏈接

[formpanel type=GET] [formtitle] /ObservedProperties(id)?$select=description [/formtitle] [formbody]

[/formbody] [/formpanel]

PATCH

更新一個ObservedProperty屬性值。

[tabpanel] [tabpage header=HTTP id=ObservedProperties-patch-tab-1]

{
  "name": "Water Temperature"
}

[/tabpage] [tabpage header=JavaScript/jQuery id=ObservedProperties-patch-tab-2]

var patchJson = JSON.stringify({
  "name": "Water Temperature"
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/ObservedProperties(id)",
    type: "PATCH",
    data: patchJson,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);

    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=ObservedProperties-patch-tab-3]

curl -X PATCH -H "Content-Type: application/json" -d '{
  "name": "Water Temperature"
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/ObservedProperties(id)"

[/tabpage] [/tabpanel]

[formpanel type=PATCH] [formtitle] /v1.0/ObservedProperties(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

DELETE

刪除一個ObservedProperty。

[tabpanel] [tabpage header=HTTP id=ObservedProperties-delete-tab-1]

https://scratchpad.sensorup.com/OGCSensorThings/v1.0/ObservedProperties(id)

[/tabpage] [tabpage header=JavaScript/jQuery id=ObservedProperties-delete-tab-2]

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/ObservedProperties(id)",
    type: "DELETE",
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=ObservedProperties-delete-tab-3]

curl -X DELETE -H "Content-Type: application/json" -H -d '' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/ObservedProperties(id)"

[/tabpage] [/tabpanel]

[formpanel type=DELETE] [formtitle] /v1.0/ObservedProperties(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

Observations

一個Observation(觀測)是一種測量或者是測算一個屬性值的行為,SensorThings中的一個Observation代表一個ObservedPropert中單個Sensor的讀取值。一個物理設備(Sensor)發送Observations給一個指定的Datastream。同時,一個Observation需要一個FeatureOfInterest(被觀測物)實體。如果請求中什麽都沒有提供FeatureOfInterest,那麽這個Datastream所關聯的Thing的Location,將被作為FeatureOfInterest指定為新的Observation。

POST

Property Required Type
phenomenonTime mandatory Time(Interval) String (ISO 8601)
result mandatory Any (depends on the observationType defined in the associated Datastream)
resultTime mandatory Time(Interval) String (ISO 8601)
resultQuality optional DQ_Element
validTime optional Time Interval String (ISO 8601)
parameters optional JSON Object

創建一個Observation時所需的實體:

Entity Required
Datastream mandatory
FeatureOfInterest mandatory (如果沒有題佛難過FeatureOfInterest,系統會自動關聯Location作為FeatureOfInterest)

示例 1: POST

創建一個觀測。 [tabpanel] [tabpage header=HTTP id=Observations-post-tab-1]

{
  "phenomenonTime": "2017-02-07T18:02:00.000Z",
  "resultTime" : "2017-02-07T18:02:05.000Z",
  "result" : 21.6,
  "Datastream":{"@iot.id":8}
}

[/tabpage] [tabpage header=JavaScript/jQuery id=Observations-post-tab-2]

var json = JSON.stringify({
  "phenomenonTime": "2017-02-07T18:02:00.000Z",
  "resultTime" : "2017-02-07T18:02:05.000Z",
  "result" : 21.6,
  "Datastream":{"@iot.id":8}
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Observations",
    type: "POST",
    data: json,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=Observations-post-tab-3]

curl -X POST -H "Content-Type: application/json" -d '{
  "phenomenonTime": "2017-02-07T18:02:00.000Z",
  "resultTime" : "2017-02-07T18:02:05.000Z",
  "result" : 21.6,
  "Datastream":{"@iot.id":8}
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Observations"

[/tabpage] [/tabpanel]

[formpanel type=POST] [formtitle] /v1.0/Observations [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 使用FeatureOfInterest來POST

建立一個Observation,並嵌入新的FeatureOfInterest。

[formpanel type=POST] [formtitle] /v1.0/Observations [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 3: 鏈接已存在Datastream來POST

創建一個Observation,並連接已存在的Datastream。

[formpanel type=POST] [formtitle] /v1.0/Datastreams(id)/Observations [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 4: 鏈接已存在的Datastream和FeatureOfInterest來POST

創建一個Observation,並連接到已存在的Datastream和FeatureOfInterest。

[formpanel type=POST] [formtitle] /v1.0/Datastreams(id)/Observations [/formtitle] [formbody]

[/formbody] [/formpanel]

GET

示例 1: GET

取回所有的Observations。

[tabpanel] [tabpage header=HTTP id=Observations-get-tab-1-1]

https://toronto-bike-snapshot.sensorup.com/v1.0/Observations

[/tabpage] [tabpage header=JavaScript/jQuery id=Observations-get-tab-1-2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/Observations",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=Observations-get-tab-1-3]

curl -X GET -H "Content-Type: application/json" "https://toronto-bike-snapshot.sensorup.com/v1.0/Observations"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/Observations [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 使用Observation id來GET

取回一個指定的Observation。

[formpanel type=GET] [formtitle] /v1.0/Observations(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 3: 使用Datastream id來GET

從一個指定的Datastream中取回Observations。

[formpanel type=GET] [formtitle] /v1.0/Datastreams(id)/Observations [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 4: 使用expand來GET

使用$expand查詢選項,取回一個指定的Observation和其所包含的實體。

$expand相關實體 描述
Datastream 顯示這個Observations中Datastream的詳細內容
FeatureOfInterest 顯示這個Observations中FeatureOfInterest的詳細內容

[formpanel type=GET] [formtitle] /v1.0/Observations(id)?$expand=Datastream [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 5: 使用select來GET

從一個指定的Observation中取回特定的屬性數據。

$select查詢選項 描述
phenomenonTime 觀測發生時間
result Sensor中ObservedProperty的數值
resultTime 得到觀測結果的時間T
resultQuality 觀測結果的質量
validTime 可能使用此結果的時間周期
parameters 在測量期間描述環境情況的鍵-值對
Datastream 從Observation到Datastream的鏈接
FeatureOfInterest 從Observation到FeatureOfInterest的鏈接

[formpanel type=GET] [formtitle] /v1.0/Observations(id)?$select=phenomenonTime,result [/formtitle] [formbody]

[/formbody] [/formpanel]

PATCH

更新一個Observation屬性值。 [tabpanel] [tabpage header=HTTP id=Observations-patch-tab-1]

{
  "phenomenonTime": "2017-02-09T18:02:00.000Z",
  "resultTime" : "2017-02-09T18:02:05.000Z"
}

[/tabpage] [tabpage header=JavaScript/jQuery id=Observations-patch-tab-2]

var patchJson = JSON.stringify({
  "phenomenonTime": "2017-02-09T18:02:00.000Z",
  "resultTime" : "2017-02-09T18:02:05.000Z"
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Observations(id)",
    type: "PATCH",
    data: patchJson,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);

    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=Observations-patch-tab-3]

curl -X PATCH -H "Content-Type: application/json" -d '{
  "phenomenonTime": "2017-02-09T18:02:00.000Z",
  "resultTime" : "2017-02-09T18:02:05.000Z"
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Observations(id)"

[/tabpage] [/tabpanel]

[formpanel type=PATCH] [formtitle] /v1.0/Observations(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

DELETE

刪除一個Observation。 [tabpanel] [tabpage header=HTTP id=Observations-delete-tab-1]

https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Observations(id)

[/tabpage] [tabpage header=JavaScript/jQuery id=Observations-delete-tab-2]

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Observations(id)",
    type: "DELETE",
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=Observations-delete-tab-3]

curl -X DELETE -H "Content-Type: application/json" -H -d '' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Observations(id)"

[/tabpage] [/tabpanel]

[formpanel type=DELETE] [formtitle] /v1.0/Observations(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

FeaturesOfInterest

一個Observation(觀測)的動作實際是將一個數據被指定給了一種現象,這種現象可理解為一個特征屬性,也就是Observation[OGC and ISO 19156:2011]的FeatureOfInterest(被觀測物)。在物聯網的環境中,許多Observations的FeatureOfInterest就是這個Thing的Location。舉例來說,一個WiFi連接恒溫器的FeatureOfInterest可以是這個恒溫器的Location(比如放置這個恒溫器的客廳)。但在遙感中,FeatureOfInterest就是這個恒溫器被感測到的地理範圍。

POST

Property Required Type
name mandatory String
description mandatory String
encodingType mandatory ValueCode
feature mandatory Any (depending on the value of the encodingType)

示例 1: POST

創建一個FeatureOfInterest。

[tabpanel] [tabpage header=HTTP id=FeaturesOfInterest-post-tab-1]

{
  "name": "UofC CCIT",
  "description": "University of Calgary, CCIT building",
  "encodingType": "application/vnd.geo+json",
  "feature": {
    "type": "Point",
    "coordinates": [-114.133, 51.08]
  }
}

[/tabpage] [tabpage header=JavaScript/jQuery id=FeaturesOfInterest-post-tab-2]

var json = JSON.stringify({
  "name": "UofC CCIT",
  "description": "University of Calgary, CCIT building",
  "encodingType": "application/vnd.geo+json",
  "feature": {
    "type": "Point",
    "coordinates": [-114.133, 51.08]
  }
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/FeaturesOfInterest",
    type: "POST",
    data: json,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=FeaturesOfInterest-post-tab-3]

curl -X POST -H "Content-Type: application/json" -d '{
  "name": "UofC CCIT",
  "description": "University of Calgary, CCIT building",
  "encodingType": "application/vnd.geo+json",
  "feature": {
    "type": "Point",
    "coordinates": [-114.133, 51.08]
  }
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/FeaturesOfInterest"

[/tabpage] [/tabpanel]

[formpanel type=POST] [formtitle] /v1.0/FeaturesOfInterest [/formtitle] [formbody]

[/formbody] [/formpanel]

GET

示例 1: GET

取回所有FeatureOfInterest。

[tabpanel] [tabpage header=HTTP id=FeaturesOfInterest-get-tab-1-1]

https://toronto-bike-snapshot.sensorup.com/v1.0/FeaturesOfInterest

[/tabpage] [tabpage header=JavaScript/jQuery id=FeaturesOfInterest-get-tab-1-2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/FeaturesOfInterest",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=FeaturesOfInterest-get-tab-1-3]

curl -X GET -H "Content-Type: application/json" "https://toronto-bike-snapshot.sensorup.com/v1.0/FeaturesOfInterest"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/FeaturesOfInterest [/formtitle] [formbody]

[/formbody] [/formpanel]

Exmaple 2: GET by id

取回一個指定的FeatureOfInterest。

[formpanel type=GET] [formtitle] /v1.0/FeaturesOfInterest(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 3: 使用expand來GET

使用$expand查詢選項,取回一個指定的FeatureOfInteres和其所包含的實體。

$expand相關實體 描述
Observations 顯示Observations中FeaturesOfInterest的詳細內容

[formpanel type=GET] [formtitle] /v1.0/FeaturesOfInterest(id)?$expand=Observations [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 4: 使用select來GET

取回一個指定的FeatureOfInterest特定屬性。

$select查詢選項 描述
name FeatureOfInterest實體名稱
description FeatureOfInterest實體描述
encodingType 特征屬性的編碼類型
feature 被觀測物特征的詳細描述,數據類型可在encodingType中定義
Observations 從FeatureOfInterest到Observations的鏈接

[formpanel type=GET] [formtitle] /v1.0/FeaturesOfInterest(id)?$select=description [/formtitle] [formbody]

[/formbody] [/formpanel]

PATCH

更新一個FeatureOfInterest屬性值。 [tabpanel] [tabpage header=HTTP id=FeaturesOfInterest-patch-tab-1]

{
  "feature": {
    "coordinates": [
      -114.154,
      51.064
    ],
    "type": "Point"
  }
}

[/tabpage] [tabpage header=JavaScript/jQuery id=FeaturesOfInterest-patch-tab-2]

var patchJson = JSON.stringify({
  "feature": {
    "coordinates": [
      -114.154,
      51.064
    ],
    "type": "Point"
  }
});

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Observations(id)",
    type: "PATCH",
    data: patchJson,
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);

    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=FeaturesOfInterest-patch-tab-3]

curl -X PATCH -H "Content-Type: application/json" -d '{
  "feature": {
    "coordinates": [
      -114.154,
      51.064
    ],
    "type": "Point"
  }
}' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/Observations(id)"

[/tabpage] [/tabpanel]

[formpanel type=PATCH] [formtitle] /v1.0/FeaturesOfInterest(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

DELETE

刪除一個FeatureOfInterest。 [tabpanel] [tabpage header=HTTP id=FeaturesOfInterest-delete-tab-1]

https://scratchpad.sensorup.com/OGCSensorThings/v1.0/FeaturesOfInterest(id)

[/tabpage] [tabpage header=JavaScript/jQuery id=FeaturesOfInterest-delete-tab-2]

$.ajax({
    url: "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/FeaturesOfInterest(id)",
    type: "DELETE",
    contentType: "application/json; charset=utf-8",
    success: function(data){
        console.log(data);
    },
    error: function(response, status){
        console.log(response);
        console.log(status);
    }
});

[/tabpage] [tabpage header=cURL id=FeaturesOfInterest-delete-tab-3]

curl -X DELETE -H "Content-Type: application/json" -H -d '' "https://scratchpad.sensorup.com/OGCSensorThings/v1.0/FeaturesOfInterest(id)"

[/tabpage] [/tabpanel]

[formpanel type=DELETE] [formtitle] /v1.0/FeaturesOfInterest(id) [/formtitle] [formbody]

[/formbody] [/formpanel]

查詢選項

使用查詢選項可以簡化在SensorThings中獲得所需信息的請求。以下列出的所有查詢選項都可以使用在SensorThings的各個實體中,可能選項具體使用會有些微差別。 SensorThings查詢選項可以分為兩種類型,一類主要用於指定請求的返回屬性,$expand和$select屬於這類。另一類主要用於對返回的結果設限、過濾或者重新排序,$orderby、$top、$skip、$count和$filter屬於這類。

expand

使用$expand查詢選項來請求相關實體的信息集合。

查詢 選項 描述
$expand 使用逗號或前斜線間隔各子實體名稱 取回指定的相關實體和基實體的內部內容

示例 1: 返回Things的集合,並返回這些Thing相關的Datastreams。

[tabpanel] [tabpage header=HTTP id=expand1]

https://toronto-bike-snapshot.sensorup.com/v1.0/Things?$expand=Datastreams

[/tabpage] [tabpage header=JavaScript/jQuery id=expand2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/Things?$expand=Datastreams",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=expand3]

curl -X GET -H "Content-Type: application/json" "https://toronto-bike-snapshot.sensorup.com/v1.0/Things?%24expand=Datastreams"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/Things?$expand=Datastreams [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 返回Things的集合,並返回這些Thing相關的Datastreams,以及這些Datastream相關的ObservedProperty。

[formpanel type=GET] [formtitle] /v1.0/Thing?$expand=Datastreams/ObservedProperty [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 3: 返回指定id的Datastream,並返回內部相關的Observations和ObservedProperty。

[formpanel type=GET] [formtitle] /v1.0/Datastreams(id)?$expand=Observations,ObservedProperty [/formtitle] [formbody]

[/formbody] [/formpanel]

select

$select查詢選項從SensorThings服務中請求一個實體的特定屬性。這個查詢選項可用來簡化從服務器傳回的數據。

查詢 選項 描述
$select 用逗號間隔各屬性名稱(包括鏈接的屬性名稱) 如設置,結果將包含SensorThing實體的特定屬性

示例 1: 只返回Observation的result和phenomenonTime屬性。

[tabpanel] [tabpage header=HTTP id=select1]

https://toronto-bike-snapshot.sensorup.com/v1.0/Observations?$select=result,phenomenonTime

[/tabpage] [tabpage header=JavaScript/jQuery id=select2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/Observations?$select=result,phenomenonTime",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=select3]

curl -X GET -H "Content-Type: application/json" "https://toronto-bike-snapshot.sensorup.com/v1.0/Observations?%24select=result%2CphenomenonTime"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/Observations?$select=result,phenomenonTime [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 返回Datastream的name屬性和Observations屬性,以及Observations相關的FeatureOfInterest屬性。

[formpanel type=GET] [formtitle] /v1.0/Datastreams(id)?$select=name,Observations&$expand=Observations/FeatureOfInterest [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 3: 返回一個指定的Datastream,並同時返回這個Datastream相關的Observations,返回的這些Observations中只挑選result和phenomenonTime這兩種屬性。

[formpanel type=GET] [formtitle] /v1.0/Datastreams(id)?$expand=Observations($select=result,phenomenonTime) [/formtitle] [formbody]

[/formbody] [/formpanel]

orderby

使用$orderby查詢選項對指定屬性返回的結果進行升序(asc)或降序排列(desc)。

查詢 選項 描述
$orderby 逗號間隔屬性名稱,後綴asc為升序,後綴desc為降序 用來指定需要按順序排列的屬性

示例: 返回按照phenomenonTime屬性進行降序排列的所有Observations

[tabpanel] [tabpage header=HTTP id=orderby1]

https://toronto-bike-snapshot.sensorup.com/v1.0/Observations?$orderby=phenomenonTime

[/tabpage] [tabpage header=JavaScript/jQuery id=orderby2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/Observations?$orderby=phenomenonTime",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=orderby3]

curl -X GET -H "Content-Type: application/json" "https://toronto-bike-snapshot.sensorup.com/v1.0/Observations?%24orderby=phenomenonTime"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/Observations?$orderby=phenomenonTime desc [/formtitle] [formbody]

[/formbody] [/formpanel]

top

使用$top查詢選項來限制請求的實體數量

查詢 選項 描述
$top 非負整型 指定一個非負整形來限制返回實體的數量。服務器將返回最多,但不超多這個指定值的實體

示例 1: 返回Observations中最新5個實體

[tabpanel] [tabpage header=HTTP id=top1]

https://toronto-bike-snapshot.sensorup.com/v1.0/Observations?$top=5

[/tabpage] [tabpage header=JavaScript/jQuery id=top2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/Observations?$top=5",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=top3]

curl -X GET -H "Content-Type: application/json"  "https://toronto-bike-snapshot.sensorup.com/v1.0/Observations?%24top=5"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/Observations?$top=5 [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 返回Observation中最新3個實體,並按照phenomenonTime屬性進行降序排列。

[formpanel type=GET] [formtitle] /v1.0/Observations?$top=3&$orderby=phenomenonTime desc [/formtitle] [formbody]

[/formbody] [/formpanel]

skip

使用$skip來指定返回實體時應該跳過(忽略)的實體數量。

查詢 選項 描述
$skip 非負整型 指定將被跳過的實體數量

示例 1: 按照服務器中實體順序,跳過最近的6個Thing實體,返回從第7個開始的所有Thing。

[tabpanel] [tabpage header=HTTP id=skip1]

https://toronto-bike-snapshot.sensorup.com/v1.0/Things?$skip=5

[/tabpage] [tabpage header=JavaScript/jQuery id=skip2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/Things?$skip=5",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=skip3]

curl -X GET -H "Content-Type: application/json" "https://toronto-bike-snapshot.sensorup.com/v1.0/Things?%24skip=5"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/Things?$skip=5 [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 從Observation集合中返回第3個和第4個實體,並在結果中按照phenomenonTime屬性進行升序排列,

[formpanel type=GET] [formtitle] /v1.0/Observations?$skip=2&$top=2&$orderby=phenomenonTime [/formtitle] [formbody]

[/formbody] [/formpanel]

count

使用$count查詢選項獲得請求的實體總數。

查詢 選項 描述
$count true 或 false 用於是否返回實體總數的統計結果

示例: 返回Things集合中所有數據及統計總數 [tabpanel] [tabpage header=HTTP id=count1]

https://toronto-bike-snapshot.sensorup.com/v1.0/Things?$count=true

[/tabpage] [tabpage header=JavaScript/jQuery id=count2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/Things?$count=true",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=count3]

curl -X GET -H "Content-Type: application/json" "https://toronto-bike-snapshot.sensorup.com/v1.0/Things?%24count=true"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/Things?$count=true [/formtitle] [formbody]

[/formbody] [/formpanel]

filter

使用$filter查詢選項可以進行對返回的屬性值按條件進行篩選過濾。

  • 默認下,$filter視所有result為string(字符串型)
  • 例外情況,如返回Observations是作為Datastream的子結果返回,比如Datastreams(id)/Observations, 此時Datastream有一個observationType有一個observationType,此時$filter將視result為數字。
查詢 選項 描述
$filter '屬性/函數 操作符' 或者 函數 指定對結果進行過濾的方法

示例 1: 返回一個指定的Datastream中Observations,僅返回Observations的result比10小的所有數據。

[tabpanel] [tabpage header=JSON class=active id=filter1]

https://toronto-bike-snapshot.sensorup.com/v1.0/Datastreams(206051)/Observations?$filter=result lt 10

[/tabpage] [tabpage header=JavaScript/jQuery id=filter2]

$.get("https://toronto-bike-snapshot.sensorup.com/v1.0/Datastreams(206051)/Observations?$filter=result lt 10",function(response, status){
    console.log(response);
});

[/tabpage] [tabpage header=cURL id=filter3]

curl -X GET -H "Content-Type: application/json" "https://toronto-bike-snapshot.sensorup.com/v1.0/Datastreams(206051)/Observations?%24filter=result%20lt%2010"

[/tabpage] [/tabpanel]

[formpanel type=GET] [formtitle] /v1.0/Datastreams(id)/Observations?$filter=result lt 10 [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 2: 返回在一個指定時間之前的所有Observations。

[formpanel type=GET] [formtitle] /v1.0/Observations?$filter=phenomenonTime lt ‘2016-11-24T14:37:01.000Z’ [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 3: 返回所有location為Central Tech [-79.407,43.661]的所有Locations。

[formpanel type=GET] [formtitle] /v1.0/Locations?$filter=st_equals(location,geography’POINT(-79.407 43.661)’) [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 4: 返回Things的FeatureOfInterest,僅返回指定name以及指定時間為2017年1月至3月的數據。

[formpanel type=GET] [formtitle] /Things?$expand=Datastreams/Observations/FeatureOfInterest&$filter=Datastreams/Observations/FeatureOfInterest/name eq ‘7000:Ft. York / Capreol Crt.’ and Datastreams/Observations/phenomenonTime ge 2017-01-01T00:00:00.000Z and Datastreams/Observations/phenomenonTime le 2017-03-01T00:00:00.000Z [/formtitle] [formbody]

[/formbody] [/formpanel]

示例 5: 返回一個指定的,其內部Observations的result為2的Datastream。

[formpanel type=GET] [formtitle] /v1.0/Datastreams(id)?$expand=Observations($filter=result eq 2) [/formtitle] [formbody]

[/formbody] [/formpanel]

Built-in Filter Operators

操作符 描述 示例
比較運算符    
eq 等於 /ObservedProperties?$filter=name eq 'Area Temperature'
ne 不等於 /ObservedProperties?$filter=name ne 'Area Temperature'
gt 大於 /Datastreams(id)/Observations?$filter=result gt 20.0
ge 大於或等於 /Datastreams(id)/Observations?$filter=result ge 20.0
lt 小於 /Datastreams(id)/Observations?$filter=result lt 100
le 小於或等於 /Datastreams(id)/Observations?$filter=result le 100
邏輯運算符    
and 邏輯與 /Datastreams(id)/Observations?$filter=result le 3.5 and FeatureOfInterest/id eq '1'
or 邏輯或 /Datastreams(id)/Observations?$filter=result gt 20 or result le 3.5
not 邏輯非 /Things?$filter=not startswith(description,'test')
分組運算符    
( ) 優先分組 /Datastreams(id)/Observations?$filter=(result sub 5) gt 10

Built-in Query Functions

函數 Example
字符串函數  
bool substringof(string searchString,string baseString) substringof('Sensor Things',description)
bool endswith(string baseString, string suffix) endswith(description,'Things')
bool startswith(string baseString, string prefix) startswith(description,'Sensor')
int length(string p0) length(description) eq 13
string tolower(string p0) tolower(description) eq 'sensor things'
string toupper(string p0) toupper(description) eq 'SENSOR THINGS'
日期函數  
int year year(resultTime) eq 2015
int month month(resultTime) eq 12
int day day(resultTime) eq 8
int hour hour(resultTime) eq 1
int minute minute(resultTime) eq 0
int second second(resultTime) eq 0
數學函數  
round round(result) eq 32
floor floor(result) eq 32
ceiling ceiling(result) eq 33
地理空間函數  
double geo.distance(Point p0, Point p1) geo.distance(location, geography'POINT (30 10)')
double geo.length(LineString p0) geo.length(geography'LINESTRING (30 10, 10 30, 40 40)')
bool geo.intersects(Point p0, Polygon p1) geo.intersects(location,geography'POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))')
空間關系函數  
bool st_equals st_equals(location, geography'POINT (30 10)')
bool st_disjoint st_disjoint(location, geography'POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))')
bool st_touches st_touches(location, geography'LINESTRING (30 10, 10 30, 40 40)')
bool st_within st_within(location, geography'POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))')
bool st_overlaps st_overlaps(location, geography'POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))')
bool st_crosses st_crosses(location, geography'LINESTRING (30 10, 10 30, 40 40)')
bool st_intersects st_intersects(location, geography'LINESTRING (30 10, 10 30, 40 40)')
bool st_contains st_contains(location, geography'POINT (30 10)')
bool st_relate st_relate(location, geography'POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))', 'T****')

resultFormat

使用$resultFormat查詢選項以數組形式返回Observations。

Property Options Description
$resultFormat dataArray Enables returning Observations in data arrays.

示例 1: Returns all Observations of a specific Datastream in a data array to minimize metadata being returned from the server.

按照數組形式返回一個指定的Datastream的所有Observations,以最小化從服務器返回的元數據。

[formpanel type=GET] [formtitle] /v1.0/Datastreams(id)/Observations?$resultFormat=dataArray [/formtitle] [formbody]

[/formbody] [/formpanel]

Errors

SensorThings API 使用下列錯誤代碼:

錯誤代碼 含義
400 Bad Request – 您的請求不正確,可能是不正確的JSON內容,或者可能與服務器接受格式不符
401 Unauthorized – 未授權的,錯誤的API key
404 Not Found – 正在查找的資源不存在
405 Method not allowed – 請求了一種尚未在服務器上實現的方法
406 Not Acceptable – 請求的格式不是JSON
409 Conflict – 資源檢查約束發生了沖突
410 Gone – 請求的資源已被刪除
429 Too Many Requests – 目前負載太多,請稍後再試
500 Internal Server Error – 服務器有些問題,請稍後再試
503 Service Unavailable – 暫時離線進行維護,請稍後再試