Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/app/models/thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from app.db.sqlalchemy_db import SCHEMA_NAME, Base
from geoalchemy2 import Geometry
from sqlalchemy.dialects.postgresql.json import JSON
from sqlalchemy.orm import relationship
from sqlalchemy.sql.schema import Column, ForeignKey
Expand All @@ -36,6 +37,7 @@ class Thing(Base):
name = Column(String(255), nullable=False)
description = Column(Text, nullable=False)
properties = Column(JSON)
observed_area = Column("observedArea", Geometry)
commit_id = Column(Integer, ForeignKey(f"{SCHEMA_NAME}.Commit.id"))
location = relationship(
"Location", secondary=Thing_Location, back_populates="thing"
Expand Down
2 changes: 2 additions & 0 deletions api/app/sta2rest/sta2rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class STA2REST:
"name",
"description",
"properties",
"observed_area",
],
"ThingTravelTime": [
"id",
Expand All @@ -138,6 +139,7 @@ class STA2REST:
"name",
"description",
"properties",
"observed_area",
"system_time_validity",
],
"HistoricalLocation": [
Expand Down
11 changes: 11 additions & 0 deletions database/istsos_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ CREATE OR REPLACE FUNCTION "Datastreams@iot.navigationLink"(sensorthings."Thing"
SELECT '/Things(' || $1.id || ')/Datastreams';
$$ LANGUAGE SQL;

CREATE OR REPLACE FUNCTION "observedArea"(sensorthings."Thing") RETURNS geometry AS $$
BEGIN
RETURN (
SELECT ST_ConvexHull(ST_Collect(d."observedArea"))
FROM sensorthings."Datastream" d
WHERE d."thing_id" = $1.id
AND d."observedArea" IS NOT NULL
);
END;
$$ LANGUAGE plpgsql STABLE;

CREATE TABLE IF NOT EXISTS sensorthings."Thing_Location" (
"thing_id" BIGINT NOT NULL REFERENCES sensorthings."Thing"(id) ON DELETE CASCADE,
"location_id" BIGINT NOT NULL REFERENCES sensorthings."Location"(id) ON DELETE CASCADE,
Expand Down