From dc58b7235fdd28fa6387c5981b21996ebb23d3fa Mon Sep 17 00:00:00 2001 From: Arno Kaimbacher Date: Thu, 10 Mar 2022 18:30:36 +0100 Subject: [PATCH] - insert Sensor via SensorML20 soap --- pechgraben_images/InsertSensorTest.xml | 120 +++++++++++++++++++++ pechgraben_images/import_feature_sensor.py | 89 +++++++++++++-- 2 files changed, 199 insertions(+), 10 deletions(-) create mode 100644 pechgraben_images/InsertSensorTest.xml diff --git a/pechgraben_images/InsertSensorTest.xml b/pechgraben_images/InsertSensorTest.xml new file mode 100644 index 0000000..c536174 --- /dev/null +++ b/pechgraben_images/InsertSensorTest.xml @@ -0,0 +1,120 @@ + + + + + http://www.opengis.net/sensorML/2.0 + + + + {procedure_identifier} + + + + + longName + {procedure_name} + + + + + shortName + {procedure_name} + + + + + + + + + {offering_label} + {offering_name} + + + + + + + + + true + + + + + false + + + + + + + featuresOfInterest + + + {feature_id} + {feature_name} + + + + + {coordinates} + + + + + + + + + + + + + + + + + + + + + {cord_x} + + + + + + {cord_y} + + + + + + {height} + + + + + + + http://www.opengis.net/def/property/humanVisualPerception + + + http://www.opengis.net/def/observationType/OGCOM/2.0/OM_CategoryObservation + http://www.opengis.net/def/samplingFeatureType/OGCOM/2.0/SF_SamplingPoint + + + + + \ No newline at end of file diff --git a/pechgraben_images/import_feature_sensor.py b/pechgraben_images/import_feature_sensor.py index 27bffdc..758d838 100644 --- a/pechgraben_images/import_feature_sensor.py +++ b/pechgraben_images/import_feature_sensor.py @@ -58,16 +58,21 @@ def main(): "camera1", "camera1, Pechgraben" ) - procedure = Procedure("camera1", "Kamera camera1 am Pechgraben") + procedure = Procedure("camera1", "Procedure camera1 am Pechgraben") foi = FoI("degree", "m", (14.54621, 47.92861, 0.0), "pechgraben", "Katastropheneinsatz in Pechgraben") sensor_type = SensorType("camera") - post_data = insert_sensor(offering, procedure, foi, sensor_type) - print(post_data) - headers = {'Accept': 'application/json'} - request = requests.post(sos_url, headers=headers, json=post_data) + # post_data = insert_sensor(offering, procedure, foi, sensor_type) + # print(post_data) + # headers = {'Accept': 'application/json'} + # request = requests.post(sos_url, headers=headers, json=post_data) + # print(request.text) + headers = {'Content-Type': 'application/soap+xml'} # set what your server accepts + xml = get_xml(offering, procedure, foi, sensor_type) + # print(xml) + request = requests.post(sos_url, data = xml, headers=headers) print(request.text) # { @@ -77,6 +82,72 @@ def main(): # "assignedProcedure" : "inclino1_14", # "assignedOffering" : "inclino1_14" # } +def get_xml(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 + cord_x = str(foi.x) # longitude degrees, float + cord_y = str(foi.y) # latitude degrees, float + coordinates = cord_x + " " + cord_y + 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 attr in sensor_type.pattern["attributes"]: + obs_prop_name = '\"' + attr[0] + '\"' # attribute name + # print(obs_prop_name) + unit_name = sensor_type.om_types[attr[1]] # om type + # magnitud = a # ?? + + obs_name = obs_prop_name.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 + xml = f'http://www.opengis.net/sensorML/2.0{procedure_identifier}longName{procedure_name}shortName{procedure_name}{offering_label}{offering_name}truefalsefeaturesOfInterest{feature_id}{feature_name}{coordinates}{cord_x}{cord_y}{height}http://www.opengis.net/def/property/humanVisualPerceptionhttp://www.opengis.net/def/observationType/OGCOM/2.0/OM_CategoryObservationhttp://www.opengis.net/def/samplingFeatureType/OGCOM/2.0/SF_SamplingPoint' + return xml def insert_sensor(offering, procedure, foi, sensor_type): @@ -149,14 +220,12 @@ def insert_sensor(offering, procedure, foi, sensor_type): "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}{cord_x}{cord_y}{height}', + "procedureDescription": f'{procedure_identifier}{procedure_identifier} Procedure {procedure_name} {procedure_name}{offering_label}{offering_name}featuresOfInterest{feature_id}{feature_name}{coordinates}{cord_x}{cord_y}{height}', "observableProperty": [ - "Image", - # "Roll", - # "InSystemTemperature" + "http://www.opengis.net/def/property/humanVisualPerception" ], "observationType": [ - "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement" + "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_CategoryObservation" ], "featureOfInterestType": "http://www.opengis.net/def/samplingFeatureType/OGC-OM/2.0/SF_SamplingPoint" }