''' https://lists.ogc.org/pipermail/sensorml/2008-September/000573.html
qweqwe
'''
import csv
import requests
from pyproj import Transformer
from insert_sensor.wrapper import (Offering, FoI, Procedure, SensorType)
class Sensor:
"""
A class to represent an input sensor.
...
Attributes
----------
name : str
first name of the person
x : float
token to access soso service
y : float
token to access soso service
"""
def __init__(self, name: str, x_coord: float, y_coord: float):
self.name = name
self.x_coord = x_coord
self.y_coord = y_coord
# delimiter: it refers to the character used to
# separate values (or fields) in the CSV file. It defaults to comma (,)
# quotechar : it refers to the single character string that will be used to quote values
# if special characters (like delimiter) appears inside the field. It defaults to ".
def main():
''' main method '''
with open('voegelsberg/insert_sensors/sensors_origin.csv', 'rt', encoding="utf-8") as csvfile:
spamreader = csv.DictReader(csvfile, delimiter=';', quotechar='"')
for row in spamreader:
# print(row)
transprojr = Transformer.from_crs(31254, 4326, always_xy=True)
x_1, y_1, z_1 = (float(row['Y']), float(row['X']), float(row['H']))
x_2, y_2 = map(float, transprojr.transform(x_1, y_1))
print((x_2, y_2)) # (11.597409730065536, 47.27196543449542)
sensor_name = row['Punktnummer']
# platform ampflwang_kb1_inclinometer
offering = Offering(
"https://geomon.geologie.ac.at/52n-sos-webapp/api/offerings/",
sensor_name,
"Vögelsberg Tachymeter"
)
procedure = Procedure(sensor_name, sensor_name)
foi_name = "origin of " + sensor_name
foi = FoI("degree", "m", (x_2, y_2, z_1),
sensor_name, foi_name)
# now insert sensor via rest service:
sensor_type = SensorType("tachymeter")
sos_url = 'https://geomon.geologie.ac.at/52n-sos-webapp/service'
# set what your server accepts
headers = {'Content-Type': 'application/soap+xml'}
xml = get_xml(offering, procedure, foi, sensor_type)
# print(xml)
# exit()
request = requests.post(sos_url, data=xml, headers=headers)
print(request.text)
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
# gml_id = '\"' + str(procedure.id) + '\"' # Offering name, double quoted
# 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}truetruefeaturesOfInterest{feature_id}{feature_name}{coordinates}{cord_x}{cord_y}{height}TachymeterLocationhttp://www.opengis.net/def/observationType/OGC-OM/2.0/OM_GeometryObservationhttp://www.opengis.net/def/samplingFeatureType/OGC-OM/2.0/SF_SamplingPoint'
return xml
if __name__ == '__main__':
main()