# -*- coding: utf-8 -*-
"""
Function for the SOS Transactional profile.
This set of function format requests to publish and handle data in a SOS using a RESTful API.
Requests need to be passed as the body of a HTTP request to the SOS server.
When more than one syntax is allowed, requests as passed using XML version 2.0
Author: Arno Kaimbacher
Created: 12-07-2021
"""
def insert_sensor(offering, procedure, foi, sensor_type):
"""
Prepares the body of a InsertSensor request for JSON biding.
:param offering: an instance of class Offering.Type object.
:param Procedure: instance of class Procedure. type object.
:param foi: feature of interest. Instance of FoI
:param sensor_type: SensorType object
:return: valid body for an InsertSensor request.
"""
# shortName = offering.name # string
# longName = 'Sibratsgfall test' # string
# Offering values
off_name = '\"' + str(offering.name) + '\"' # Offering name, double quoted
offering_name = offering.name
offering_label = offering.label
# offID = offering.fullId # URL format of full id
# featureName = featureID = cordX = cordY = height = h_unit = z_unit = coordinates = ""
if foi is not None: # check if feature of interest should be declare
# feature_id = 'https://geomon.geologie.ac.at/52n-sos-webapp/api/features/' + \
# str(foi.fid) # URL format
cordX = str(foi.x) # longitude degrees, float
cordY = str(foi.y) # latitude degrees, float
coordinates = cordX + " " + cordY
height = str(foi.z) # altitude in meters, float
# h_unit = foi.Hunit # units for horizontal coordinates
# z_unit = foi.Vunit # units for altitude
feature_id = foi.fid # "feature location"
feature_name = foi.name # "feature location"
else:
pass
procedure_name = procedure.name
procedure_identifier = procedure.id # URL,
obs_types = []
output_list = '' # output list element for describe procedure
properties_list = []
for a in sensor_type.pattern["attributes"]:
ObsPropName = '\"' + a[0] + '\"' # attribute name
# print(ObsPropName)
unit_name = sensor_type.om_types[a[1]] # om type
# magnitud = a # ??
obs_name = ObsPropName.replace('\"', '')
obs_name = "".join(obs_name.split()) # observable property name
output = ''
output_list = output_list + output
# add property identifier to the list.
properties_list.append(obs_name)
# prepare list of measurement types
# A sensor can not registry duplicated sensor types.
this_type = "http://www.opengis.net/def/observationType/OGC-OM/2.0/"+unit_name
if this_type not in obs_types: # when new type appears
obs_types.append(this_type)
else:
continue
# Unit of measurement:
unit_name = '\"' + procedure.name + '\"' # double quoted string
# unit = omType # one of the MO measurement types
body = {
"request": "InsertSensor",
"service": "SOS",
"version": "2.0.0",
"procedureDescriptionFormat": "http://www.opengis.net/sensorml/2.0",
"procedureDescription": f'{procedure_identifier}shortName{procedure_name}{offering_label}{offering_name}featuresOfInterest{feature_id}{feature_name}{coordinates}Slope{cordX}{cordY}{height}',
"observableProperty": [
"Slope",
"Roll",
"InSystemTemperature"
],
"observationType": [
"http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement"
],
"featureOfInterestType": "http://www.opengis.net/def/samplingFeatureType/OGC-OM/2.0/SF_SamplingPoint"
}
return body