- add geoalchemy2 for inserting geometry observation
- tested original InsertObservation request - see ImportMobileObservation_example.xml
This commit is contained in:
parent
56e3df1cf4
commit
278537d85d
11
db/models.py
11
db/models.py
|
@ -13,6 +13,8 @@ from sqlalchemy import (Column, Integer, Sequence,
|
|||
String, DateTime, ForeignKey, Numeric, SmallInteger, create_engine)
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import session, relationship, sessionmaker
|
||||
# from geoalchemy2 import Geometry
|
||||
from geoalchemy2.types import Geometry
|
||||
#from marshmallow import Schema
|
||||
from marshmallow_sqlalchemy import SQLAlchemySchema, SQLAlchemyAutoSchema
|
||||
from marshmallow import fields
|
||||
|
@ -26,7 +28,7 @@ Base = declarative_base()
|
|||
def create_pg_session() -> sessionmaker:
|
||||
""" create postgres db session """
|
||||
load_dotenv(find_dotenv())
|
||||
dbschema = ''
|
||||
dbschema = 'gba'
|
||||
db_user = os.environ.get("POSTGIS_DBUSER")
|
||||
db_password = os.environ.get("POSTGIS_DBPASSWORD")
|
||||
db_url = os.environ.get("POSTGIS_DBURL")
|
||||
|
@ -186,8 +188,9 @@ class Observation(Base):
|
|||
result_time = Column('result_time', DateTime)
|
||||
sta_identifier = Column('sta_identifier', String)
|
||||
value_identifier = Column('value_identifier', String)
|
||||
value_quantity = Column('value_quantity', Numeric(20, 10))
|
||||
value_text = Column('value_text', String)
|
||||
value_quantity = Column('value_quantity', Numeric(20, 10), nullable=True)
|
||||
value_text = Column('value_text', String, nullable=True)
|
||||
value_geometry = Column(Geometry(geometry_type='POLYGON', srid=4326, dimension=3), nullable=True)
|
||||
|
||||
fk_dataset_id = Column(Integer, ForeignKey(
|
||||
'gba.dataset.dataset_id'), nullable=False)
|
||||
|
@ -263,7 +266,7 @@ def create_db():
|
|||
isolation_level="READ UNCOMMITTED", echo=True)
|
||||
# session_maker = sessionmaker(bind=engine)
|
||||
# session = session_maker()
|
||||
Base.metadata.drop_all(bind=engine)
|
||||
# Base.metadata.drop_all(bind=engine)
|
||||
# Base.metadata.create_all(engine)
|
||||
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ python -m pip install fdb
|
|||
python -m pip install sqlalchemy-firebird
|
||||
python -m pip uninstall psycopg2
|
||||
python -m pip install pyproj
|
||||
python -m pip install GeoAlchemy2
|
||||
|
||||
Marshmallow provides functionality to serialize and deserialize Python objects as they flow out of and into our JSON-based REST API. Marshmallow converts Python class instances to objects that can be converted to JSON.
|
||||
python -m pip install marshmallow-sqlalchemy marshmallow
|
||||
|
|
63
voegelsberg/ImportMobileObservation_example.xml
Normal file
63
voegelsberg/ImportMobileObservation_example.xml
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope/soap-envelope.xsd">
|
||||
<env:Body>
|
||||
<sos:InsertObservation service="SOS" version="2.0.0"
|
||||
xmlns:sos="http://www.opengis.net/sos/2.0"
|
||||
xmlns:swes="http://www.opengis.net/swes/2.0"
|
||||
xmlns:swe="http://www.opengis.net/swe/2.0"
|
||||
xmlns:sml="http://www.opengis.net/sensorML/1.0.1"
|
||||
xmlns:gml="http://www.opengis.net/gml/3.2"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:om="http://www.opengis.net/om/2.0"
|
||||
xmlns:sams="http://www.opengis.net/samplingSpatial/2.0"
|
||||
xmlns:sf="http://www.opengis.net/sampling/2.0"
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://www.opengis.net/sos/2.0 http://schemas.opengis.net/sos/2.0/sos.xsd http://www.opengis.net/samplingSpatial/2.0 http://schemas.opengis.net/samplingSpatial/2.0/spatialSamplingFeature.xsd"> <!-- multiple offerings are possible -->
|
||||
<sos:offering>D5_2</sos:offering>
|
||||
<sos:observation>
|
||||
<om:OM_Observation gml:id="voegelsberg_0">
|
||||
<om:type xlink:href="http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_GeometryObservation"/>
|
||||
<om:phenomenonTime>
|
||||
<gml:TimeInstant gml:id="phenomenonTime">
|
||||
<gml:timePosition>2021-09-01T00:00:00</gml:timePosition>
|
||||
</gml:TimeInstant>
|
||||
</om:phenomenonTime>
|
||||
<om:resultTime xlink:href="#phenomenonTime"/>
|
||||
<om:procedure xlink:href="D5_2"/>
|
||||
<om:parameter>
|
||||
<om:NamedValue>
|
||||
<om:name xlink:href="http://www.opengis.net/def/param-name/OGC-OM/2.0/samplingGeometry"/>
|
||||
<om:value xsi:type="gml:GeometryPropertyType">
|
||||
<gml:Point gml:id="SamplingPoint1">
|
||||
<gml:description>description</gml:description>
|
||||
<gml:identifier codeSpace="">D5_2</gml:identifier>
|
||||
<gml:name>hereIam</gml:name>
|
||||
<gml:pos srsName="http://www.opengis.net/def/crs/EPSG/0/4326">11.597688540227727 47.271865827824854 909.7036</gml:pos>
|
||||
</gml:Point>
|
||||
</om:value>
|
||||
</om:NamedValue>
|
||||
</om:parameter>
|
||||
<om:observedProperty xlink:href="TachymeterLocation"/>
|
||||
<om:featureOfInterest>
|
||||
<sams:SF_SpatialSamplingFeature gml:id="ssf_instance">
|
||||
<gml:identifier codeSpace="">D5_2</gml:identifier>
|
||||
<gml:name>origin of D5_2</gml:name>
|
||||
<sf:type xlink:href="http://www.opengis.net/def/samplingFeatureType/OGC-OM/2.0/SF_SamplingPoint"/>
|
||||
<sf:sampledFeature xlink:href="http://www.opengis.net/def/nil/OGC/0/unknown"/>
|
||||
<sams:shape>
|
||||
<ns:Point xmlns:ns="http://www.opengis.net/gml/3.2" ns:id="Point_ssf_b3a826dd44012201b013c90c51da28c041f7a92e0cc47260eb9888f6a4e9f747">
|
||||
<ns:pos srsName="http://www.opengis.net/def/crs/EPSG/0/4326">11.597409730065536 47.27196543449542</ns:pos>
|
||||
</ns:Point>
|
||||
</sams:shape>
|
||||
</sams:SF_SpatialSamplingFeature>
|
||||
</om:featureOfInterest>
|
||||
<om:result xsi:type="gml:GeometryPropertyType">
|
||||
<gml:Point gml:id="value">
|
||||
<gml:pos srsName="http://www.opengis.net/def/crs/EPSG/0/4326">11.597688540227727 47.271865827824854 909.7036</gml:pos>
|
||||
</gml:Point>
|
||||
</om:result>
|
||||
</om:OM_Observation>
|
||||
</sos:observation>
|
||||
</sos:InsertObservation>
|
||||
</env:Body>
|
||||
</env:Envelope>
|
6556
voegelsberg/data.txt
Normal file
6556
voegelsberg/data.txt
Normal file
File diff suppressed because it is too large
Load Diff
171
voegelsberg/import_tachymeter_observations.py
Normal file
171
voegelsberg/import_tachymeter_observations.py
Normal file
|
@ -0,0 +1,171 @@
|
|||
''' module for importing observations '''
|
||||
import csv
|
||||
# import requests
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
from pyproj import Transformer
|
||||
# from insert_sensor.wrapper import (Offering, FoI, Procedure)
|
||||
from sqlalchemy.orm import session
|
||||
from db.models import (
|
||||
Observation,
|
||||
create_pg_session,
|
||||
Dataset,
|
||||
Procedure,
|
||||
Phenomenon,
|
||||
Platform,
|
||||
Format
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
''' main method '''
|
||||
pg_session: session = create_pg_session()
|
||||
platform_sta_identifier = "voegelsberg_tachymeter"
|
||||
|
||||
with open('voegelsberg/data.txt', 'rt', encoding="utf-8") as csvfile:
|
||||
spamreader = csv.DictReader(csvfile, delimiter=';', quotechar='"')
|
||||
for row in spamreader:
|
||||
# print(row)
|
||||
|
||||
sensor: str = row['Punktnummer']
|
||||
pg_query = pg_session.query(Dataset) \
|
||||
.join(Procedure) \
|
||||
.join(Phenomenon) \
|
||||
.filter(Procedure.sta_identifier == sensor)
|
||||
location_dataset: Dataset = pg_query.filter(
|
||||
Phenomenon.sta_identifier == "TachymeterLocation").first()
|
||||
if not location_dataset:
|
||||
print("Sensor " + sensor +
|
||||
" ist noch nicht in der Datenbank angelegt!")
|
||||
continue
|
||||
|
||||
platform_exists: bool = pg_session.query(Platform.id).filter_by(
|
||||
sta_identifier=platform_sta_identifier).scalar() is not None
|
||||
if not platform_exists:
|
||||
sensor_platform = Platform()
|
||||
# max_id = pg_session.query(func.max(Platform.id)).scalar()
|
||||
# sensor_platform.id = max_id + 1
|
||||
sensor_platform.sta_identifier = platform_sta_identifier.lower()
|
||||
sensor_platform.identifier = platform_sta_identifier.lower()
|
||||
sensor_platform.name = platform_sta_identifier.lower()
|
||||
location_dataset.platform = sensor_platform
|
||||
else:
|
||||
sensor_platform = pg_session.query(Platform.id) \
|
||||
.filter(Platform.sta_identifier == platform_sta_identifier) \
|
||||
.first()
|
||||
location_dataset.fk_platform_id = sensor_platform.id
|
||||
|
||||
format_exists: bool = pg_session.query(Format.id).filter_by(
|
||||
definition="http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_GeometryObservation"
|
||||
).scalar() is not None
|
||||
if format_exists:
|
||||
sensor_format = pg_session.query(Format.id) \
|
||||
.filter(Format.definition ==
|
||||
"http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_GeometryObservation"
|
||||
) \
|
||||
.first()
|
||||
location_dataset.fk_format_id = sensor_format.id
|
||||
pg_session.commit()
|
||||
successfully_inserted = create_observation(location_dataset, row, pg_session)
|
||||
|
||||
if successfully_inserted:
|
||||
if not location_dataset.is_published:
|
||||
location_dataset.is_published = 1
|
||||
location_dataset.is_hidden = 0
|
||||
location_dataset.dataset_type = "timeseries"
|
||||
location_dataset.observation_type = "simple"
|
||||
location_dataset.value_type = "geometry"
|
||||
|
||||
# if sensor_id in data:
|
||||
# create_observation(elevation_dataset, sensor_id, data, pg_session)
|
||||
# pg_session.commit()
|
||||
|
||||
# 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", (cord_x, cord_y, z_1),
|
||||
# sensor_name, foi_name)
|
||||
# xml = get_xml(offering, procedure, foi, result_time, identifier)
|
||||
# print(xml)
|
||||
exit()
|
||||
|
||||
|
||||
def create_observation(location_dataset: Dataset, data: dict[any, any], pg_session: session):
|
||||
''' create observation in db'''
|
||||
# print("Sesnor key exist in JSON data")
|
||||
transprojr = Transformer.from_crs(31254, 4326, always_xy=True)
|
||||
x_1, y_1 = (float(data['Y']), float(data['X']))
|
||||
cord_x, cord_y = map(float, transprojr.transform(x_1, y_1))
|
||||
print((cord_x, cord_y)) # (11.597409730065536, 47.27196543449542)
|
||||
|
||||
sensor: str = data['Punktnummer']
|
||||
|
||||
zeitstempel = data['Epoche']
|
||||
date_obj = datetime.strptime(zeitstempel, '%d.%m.%Y').isoformat()
|
||||
|
||||
existing_observation: bool = (
|
||||
pg_session.query(Observation)
|
||||
.filter(Observation.result_time ==
|
||||
date_obj, Observation.fk_dataset_id == location_dataset.id)
|
||||
.one_or_none()
|
||||
)
|
||||
|
||||
# Can we insert this observation?
|
||||
if existing_observation is None:
|
||||
# insert bew observation
|
||||
new_observation: Observation = Observation()
|
||||
# new_observation.id = max_id
|
||||
new_observation.sta_identifier = str(uuid.uuid4())
|
||||
new_observation.result_time = date_obj
|
||||
new_observation.sampling_time_start = new_observation.result_time
|
||||
new_observation.sampling_time_end = new_observation.result_time
|
||||
new_observation.value_type = "quantity"
|
||||
new_observation.value_geometry = f'SRID=4326;POINT({cord_x} {cord_y})'
|
||||
new_observation.fk_dataset_id = location_dataset.id
|
||||
pg_session.add(new_observation)
|
||||
print(f"new observation with result time {new_observation.result_time} "
|
||||
f"for drill hole {sensor} succesfully imported!")
|
||||
return True
|
||||
else:
|
||||
print(f"observation with result time {existing_observation.result_time} "
|
||||
f"for tachymeter {sensor} already exists!")
|
||||
return False
|
||||
|
||||
|
||||
def get_xml(offering, procedure, foi, result_time, identifier):
|
||||
''' """
|
||||
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.
|
||||
"""'''
|
||||
offering_name = offering.name
|
||||
# offering_label = offering.label
|
||||
|
||||
# procedure_name = procedure.name
|
||||
procedure_identifier = procedure.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
|
||||
cord_z = str(foi.z)
|
||||
coordinates = cord_x + " " + cord_y + " " + cord_z
|
||||
feature_id = foi.fid # "feature location"
|
||||
feature_name = foi.name # "feature location"
|
||||
else:
|
||||
pass
|
||||
xml = f'<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope/soap-envelope.xsd"><env:Body><sos:InsertObservation service="SOS" version="2.0.0" xmlns:sos="http://www.opengis.net/sos/2.0" xmlns:swes="http://www.opengis.net/swes/2.0" xmlns:swe="http://www.opengis.net/swe/2.0" xmlns:sml="http://www.opengis.net/sensorML/1.0.1" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:om="http://www.opengis.net/om/2.0" xmlns:sams="http://www.opengis.net/samplingSpatial/2.0" xmlns:sf="http://www.opengis.net/sampling/2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://www.opengis.net/sos/2.0 http://schemas.opengis.net/sos/2.0/sos.xsd http://www.opengis.net/samplingSpatial/2.0 http://schemas.opengis.net/samplingSpatial/2.0/spatialSamplingFeature.xsd"><!-- multiple offerings are possible --><sos:offering>{offering_name}</sos:offering><sos:observation><om:OM_Observation gml:id="{identifier}"><om:type xlink:href="http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_GeometryObservation"/><om:phenomenonTime><gml:TimeInstant gml:id="phenomenonTime"><gml:timePosition>{result_time}</gml:timePosition></gml:TimeInstant></om:phenomenonTime><om:resultTime xlink:href="#phenomenonTime"/><om:procedure xlink:href="{procedure_identifier}"/><om:parameter><om:NamedValue><om:name xlink:href="http://www.opengis.net/def/param-name/OGC-OM/2.0/samplingGeometry"/><om:value xsi:type="gml:GeometryPropertyType"><gml:Point gml:id="SamplingPoint1"><gml:description>description</gml:description><gml:identifier codeSpace="">hereIdentifier</gml:identifier><gml:name>hereIam</gml:name><gml:pos srsName="http://www.opengis.net/def/crs/EPSG/0/4326">{coordinates}</gml:pos></gml:Point></om:value></om:NamedValue></om:parameter><om:observedProperty xlink:href="TachymeterLocation"/><om:featureOfInterest><sams:SF_SpatialSamplingFeature gml:id="ssf_instance"><gml:identifier codeSpace="">{feature_id}</gml:identifier><gml:name>{feature_name}</gml:name><sf:type xlink:href="http://www.opengis.net/def/samplingFeatureType/OGC-OM/2.0/SF_SamplingPoint"/><sf:sampledFeature xlink:href="http://www.opengis.net/def/nil/OGC/0/unknown"/><sams:shape><ns:Point xmlns:ns="http://www.opengis.net/gml/3.2" ns:id="Point_ssf_b3a826dd44012201b013c90c51da28c041f7a92e0cc47260eb9888f6a4e9f747"><ns:pos srsName="http://www.opengis.net/def/crs/EPSG/0/4326">11.597409730065536 47.27196543449542</ns:pos></ns:Point></sams:shape></sams:SF_SpatialSamplingFeature></om:featureOfInterest><om:result xsi:type="gml:GeometryPropertyType"><gml:Point gml:id="value"><gml:pos srsName="http://www.opengis.net/def/crs/EPSG/0/4326">{coordinates}</gml:pos></gml:Point></om:result></om:OM_Observation></sos:observation></sos:InsertObservation></env:Body></env:Envelope>'
|
||||
return xml
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
63
voegelsberg/insert_mobile_observation.xml
Normal file
63
voegelsberg/insert_mobile_observation.xml
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope/soap-envelope.xsd">
|
||||
<env:Body>
|
||||
<sos:InsertObservation service="SOS" version="2.0.0"
|
||||
xmlns:sos="http://www.opengis.net/sos/2.0"
|
||||
xmlns:swes="http://www.opengis.net/swes/2.0"
|
||||
xmlns:swe="http://www.opengis.net/swe/2.0"
|
||||
xmlns:sml="http://www.opengis.net/sensorML/1.0.1"
|
||||
xmlns:gml="http://www.opengis.net/gml/3.2"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:om="http://www.opengis.net/om/2.0"
|
||||
xmlns:sams="http://www.opengis.net/samplingSpatial/2.0"
|
||||
xmlns:sf="http://www.opengis.net/sampling/2.0"
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://www.opengis.net/sos/2.0 http://schemas.opengis.net/sos/2.0/sos.xsd http://www.opengis.net/samplingSpatial/2.0 http://schemas.opengis.net/samplingSpatial/2.0/spatialSamplingFeature.xsd"> <!-- multiple offerings are possible -->
|
||||
<sos:offering>{offering_name}</sos:offering>
|
||||
<sos:observation>
|
||||
<om:OM_Observation gml:id="{identifier}">
|
||||
<om:type xlink:href="http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_GeometryObservation"/>
|
||||
<om:phenomenonTime>
|
||||
<gml:TimeInstant gml:id="phenomenonTime">
|
||||
<gml:timePosition>{result_time}</gml:timePosition>
|
||||
</gml:TimeInstant>
|
||||
</om:phenomenonTime>
|
||||
<om:resultTime xlink:href="#phenomenonTime"/>
|
||||
<om:procedure xlink:href="{procedure_identifier}"/>
|
||||
<om:parameter>
|
||||
<om:NamedValue>
|
||||
<om:name xlink:href="http://www.opengis.net/def/param-name/OGC-OM/2.0/samplingGeometry"/>
|
||||
<om:value xsi:type="gml:GeometryPropertyType">
|
||||
<gml:Point gml:id="SamplingPoint1">
|
||||
<gml:description>description</gml:description>
|
||||
<gml:identifier codeSpace="">hereIdentifier</gml:identifier>
|
||||
<gml:name>hereIam</gml:name>
|
||||
<gml:pos srsName="http://www.opengis.net/def/crs/EPSG/0/4326">{coordinates}</gml:pos>
|
||||
</gml:Point>
|
||||
</om:value>
|
||||
</om:NamedValue>
|
||||
</om:parameter>
|
||||
<om:observedProperty xlink:href="TachymeterLocation"/>
|
||||
<om:featureOfInterest>
|
||||
<sams:SF_SpatialSamplingFeature gml:id="ssf_instance">
|
||||
<gml:identifier codeSpace="">{feature_id}</gml:identifier>
|
||||
<gml:name>{feature_name}</gml:name>
|
||||
<sf:type xlink:href="http://www.opengis.net/def/samplingFeatureType/OGC-OM/2.0/SF_SamplingPoint"/>
|
||||
<sf:sampledFeature xlink:href="http://www.opengis.net/def/nil/OGC/0/unknown"/>
|
||||
<sams:shape>
|
||||
<ns:Point xmlns:ns="http://www.opengis.net/gml/3.2" ns:id="Point_ssf_b3a826dd44012201b013c90c51da28c041f7a92e0cc47260eb9888f6a4e9f747">
|
||||
<ns:pos srsName="http://www.opengis.net/def/crs/EPSG/0/4326">11.597409730065536 47.27196543449542</ns:pos>
|
||||
</ns:Point>
|
||||
</sams:shape>
|
||||
</sams:SF_SpatialSamplingFeature>
|
||||
</om:featureOfInterest>
|
||||
<om:result xsi:type="gml:GeometryPropertyType">
|
||||
<gml:Point gml:id="value">
|
||||
<gml:pos srsName="http://www.opengis.net/def/crs/EPSG/0/4326">{coordinates}</gml:pos>
|
||||
</gml:Point>
|
||||
</om:result>
|
||||
</om:OM_Observation>
|
||||
</sos:observation>
|
||||
</sos:InsertObservation>
|
||||
</env:Body>
|
||||
</env:Envelope>
|
|
@ -1 +1,110 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope/soap-envelope.xsd http://www.opengis.net/sos/2.0 http://schemas.opengis.net/sos/2.0/sosInsertSensor.xsd http://www.opengis.net/swes/2.0 http://schemas.opengis.net/swes/2.0/swes.xsd"><env:Body><swes:InsertSensor service="SOS" version="2.0.0" xmlns:swes="http://www.opengis.net/swes/2.0" xmlns:sos="http://www.opengis.net/sos/2.0" xmlns:swe="http://www.opengis.net/swe/2.0" xmlns:sml="http://www.opengis.net/sensorml/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd"><swes:procedureDescriptionFormat>http://www.opengis.net/sensorml/2.0</swes:procedureDescriptionFormat><swes:procedureDescription><sml:PhysicalSystem gml:id="{procedure_identifier}"><gml:identifier codeSpace="uniqueID">{procedure_identifier}</gml:identifier><sml:identification><sml:IdentifierList><sml:identifier><sml:Term definition="urn:ogc:def:identifier:OGC:1.0:longName"><sml:label>longName</sml:label><sml:value>{procedure_name}</sml:value></sml:Term></sml:identifier><sml:identifier><sml:Term definition="urn:ogc:def:identifier:OGC:1.0:shortName"><sml:label>shortName</sml:label><sml:value>{procedure_name}</sml:value></sml:Term></sml:identifier></sml:IdentifierList></sml:identification><sml:capabilities name="offerings"><sml:CapabilityList><!-- Parsed and removed during InsertSensor/UpdateSensorDescription, added during DescribeSensor. --><!-- Offering is generated if not specified. --><sml:capability name="offeringID"><swe:Text definition=\"urn:ogc:def:identifier:OGC:offeringID\"><swe:label>{offering_label}</swe:label><swe:value>{offering_name}</swe:value></swe:Text></sml:capability></sml:CapabilityList></sml:capabilities><sml:capabilities name="metadata"><sml:CapabilityList><!-- status indicates, whether sensor is insitu (true) or remote (false) --><sml:capability name="insitu"><swe:Boolean definition="insitu"><swe:value>true</swe:value></swe:Boolean></sml:capability><!-- status indicates, whether sensor is mobile (true) or fixed/stationary (false) --><sml:capability name="mobile"><swe:Boolean definition="mobile"><swe:value>true</swe:value></swe:Boolean></sml:capability></sml:CapabilityList></sml:capabilities><sml:featuresOfInterest><sml:FeatureList definition=\"http://www.opengis.net/def/featureOfInterest/identifier\"><swe:label>featuresOfInterest</swe:label><sml:feature><sams:SF_SpatialSamplingFeature xmlns:sams=\"http://www.opengis.net/samplingSpatial/2.0\" gml:id=\"ssf_b3a826dd44012201b01323232323041f7a92e0cc47260eb9888f6a4e9f747\"><gml:identifier codeSpace=\"http://www.opengis.net/def/nil/OGC/0/unknown\">{feature_id}</gml:identifier><gml:name codeSpace=\"http://www.opengis.net/def/nil/OGC/0/unknown\">{feature_name}</gml:name><sf:type xmlns:sf=\"http://www.opengis.net/sampling/2.0\" xlink:href=\"http://www.opengis.net/def/samplingFeatureType/OGC-OM/2.0/SF_SamplingPoint\"/><sf:sampledFeature xmlns:sf=\"http://www.opengis.net/sampling/2.0\" xlink:href=\"http://www.opengis.net/def/nil/OGC/0/unknown\"/><sams:shape><ns:Point xmlns:ns=\"http://www.opengis.net/gml/3.2\" ns:id=\"Point_ssf_b3a826dd44012201b013c90c51da28c041f7a92e0cc47260eb9888f6a4e9f747\"><ns:pos srsName=\"http://www.opengis.net/def/crs/EPSG/0/4326\">{coordinates}</ns:pos></ns:Point></sams:shape></sams:SF_SpatialSamplingFeature></sml:feature></sml:FeatureList></sml:featuresOfInterest><sml:position><swe:Vector referenceFrame="urn:ogc:def:crs:EPSG::4326"><swe:coordinate name="easting"><swe:Quantity axisID="x"><swe:uom code="degree"/><swe:value>{cord_x}</swe:value></swe:Quantity></swe:coordinate><swe:coordinate name="northing"><swe:Quantity axisID="y"><swe:uom code="degree"/><swe:value>{cord_y}</swe:value></swe:Quantity></swe:coordinate><swe:coordinate name="altitude"><swe:Quantity axisID="z"><swe:uom code="m"/><swe:value>{height}</swe:value></swe:Quantity></swe:coordinate></swe:Vector></sml:position></sml:PhysicalSystem></swes:procedureDescription><!-- multiple values possible --><swes:observableProperty>TachymeterLocation</swes:observableProperty><swes:metadata><sos:SosInsertionMetadata><sos:observationType>http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_GeometryObservation</sos:observationType><sos:featureOfInterestType>http://www.opengis.net/def/samplingFeatureType/OGC-OM/2.0/SF_SamplingPoint</sos:featureOfInterestType></sos:SosInsertionMetadata></swes:metadata></swes:InsertSensor></env:Body></env:Envelope>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope/soap-envelope.xsd http://www.opengis.net/sos/2.0 http://schemas.opengis.net/sos/2.0/sosInsertSensor.xsd http://www.opengis.net/swes/2.0 http://schemas.opengis.net/swes/2.0/swes.xsd">
|
||||
<env:Body>
|
||||
<swes:InsertSensor service="SOS" version="2.0.0"
|
||||
xmlns:swes="http://www.opengis.net/swes/2.0"
|
||||
xmlns:sos="http://www.opengis.net/sos/2.0"
|
||||
xmlns:swe="http://www.opengis.net/swe/2.0"
|
||||
xmlns:sml="http://www.opengis.net/sensorml/2.0"
|
||||
xmlns:gml="http://www.opengis.net/gml/3.2"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:gco="http://www.isotc211.org/2005/gco"
|
||||
xmlns:gmd="http://www.isotc211.org/2005/gmd">
|
||||
<swes:procedureDescriptionFormat>http://www.opengis.net/sensorml/2.0</swes:procedureDescriptionFormat>
|
||||
<swes:procedureDescription>
|
||||
<sml:PhysicalSystem gml:id="{procedure_identifier}">
|
||||
<gml:identifier codeSpace="uniqueID">{procedure_identifier}</gml:identifier>
|
||||
<sml:identification>
|
||||
<sml:IdentifierList>
|
||||
<sml:identifier>
|
||||
<sml:Term definition="urn:ogc:def:identifier:OGC:1.0:longName">
|
||||
<sml:label>longName</sml:label>
|
||||
<sml:value>{procedure_name}</sml:value>
|
||||
</sml:Term>
|
||||
</sml:identifier>
|
||||
<sml:identifier>
|
||||
<sml:Term definition="urn:ogc:def:identifier:OGC:1.0:shortName">
|
||||
<sml:label>shortName</sml:label>
|
||||
<sml:value>{procedure_name}</sml:value>
|
||||
</sml:Term>
|
||||
</sml:identifier>
|
||||
</sml:IdentifierList>
|
||||
</sml:identification>
|
||||
<sml:capabilities name="offerings">
|
||||
<sml:CapabilityList> <!-- Parsed and removed during InsertSensor/UpdateSensorDescription, added during DescribeSensor. --> <!-- Offering is generated if not specified. -->
|
||||
<sml:capability name="offeringID">
|
||||
<swe:Text definition=\"urn:ogc:def:identifier:OGC:offeringID\">
|
||||
<swe:label>{offering_label}</swe:label>
|
||||
<swe:value>{offering_name}</swe:value>
|
||||
</swe:Text>
|
||||
</sml:capability>
|
||||
</sml:CapabilityList>
|
||||
</sml:capabilities>
|
||||
<sml:capabilities name="metadata">
|
||||
<sml:CapabilityList> <!-- status indicates, whether sensor is insitu (true) or remote (false) -->
|
||||
<sml:capability name="insitu">
|
||||
<swe:Boolean definition="insitu">
|
||||
<swe:value>true</swe:value>
|
||||
</swe:Boolean>
|
||||
</sml:capability> <!-- status indicates, whether sensor is mobile (true) or fixed/stationary (false) -->
|
||||
<sml:capability name="mobile">
|
||||
<swe:Boolean definition="mobile">
|
||||
<swe:value>true</swe:value>
|
||||
</swe:Boolean>
|
||||
</sml:capability>
|
||||
</sml:CapabilityList>
|
||||
</sml:capabilities>
|
||||
<sml:featuresOfInterest>
|
||||
<sml:FeatureList definition=\"http://www.opengis.net/def/featureOfInterest/identifier\">
|
||||
<swe:label>featuresOfInterest</swe:label>
|
||||
<sml:feature>
|
||||
<sams:SF_SpatialSamplingFeature xmlns:sams=\"http://www.opengis.net/samplingSpatial/2.0\" gml:id=\"ssf_b3a826dd44012201b01323232323041f7a92e0cc47260eb9888f6a4e9f747\">
|
||||
<gml:identifier codeSpace=\"http://www.opengis.net/def/nil/OGC/0/unknown\">{feature_id}</gml:identifier>
|
||||
<gml:name codeSpace=\"http://www.opengis.net/def/nil/OGC/0/unknown\">{feature_name}</gml:name>
|
||||
<sf:type xmlns:sf=\"http://www.opengis.net/sampling/2.0\" xlink:href=\"http://www.opengis.net/def/samplingFeatureType/OGC-OM/2.0/SF_SamplingPoint\"/>
|
||||
<sf:sampledFeature xmlns:sf=\"http://www.opengis.net/sampling/2.0\" xlink:href=\"http://www.opengis.net/def/nil/OGC/0/unknown\"/>
|
||||
<sams:shape>
|
||||
<ns:Point xmlns:ns=\"http://www.opengis.net/gml/3.2\" ns:id=\"Point_ssf_b3a826dd44012201b013c90c51da28c041f7a92e0cc47260eb9888f6a4e9f747\">
|
||||
<ns:pos srsName=\"http://www.opengis.net/def/crs/EPSG/0/4326\">{coordinates}</ns:pos>
|
||||
</ns:Point>
|
||||
</sams:shape>
|
||||
</sams:SF_SpatialSamplingFeature>
|
||||
</sml:feature>
|
||||
</sml:FeatureList>
|
||||
</sml:featuresOfInterest>
|
||||
<sml:position>
|
||||
<swe:Vector referenceFrame="urn:ogc:def:crs:EPSG::4326">
|
||||
<swe:coordinate name="easting">
|
||||
<swe:Quantity axisID="x">
|
||||
<swe:uom code="degree"/>
|
||||
<swe:value>{cord_x}</swe:value>
|
||||
</swe:Quantity>
|
||||
</swe:coordinate>
|
||||
<swe:coordinate name="northing">
|
||||
<swe:Quantity axisID="y">
|
||||
<swe:uom code="degree"/>
|
||||
<swe:value>{cord_y}</swe:value>
|
||||
</swe:Quantity>
|
||||
</swe:coordinate>
|
||||
<swe:coordinate name="altitude">
|
||||
<swe:Quantity axisID="z">
|
||||
<swe:uom code="m"/>
|
||||
<swe:value>{height}</swe:value>
|
||||
</swe:Quantity>
|
||||
</swe:coordinate>
|
||||
</swe:Vector>
|
||||
</sml:position>
|
||||
</sml:PhysicalSystem>
|
||||
</swes:procedureDescription> <!-- multiple values possible -->
|
||||
<swes:observableProperty>TachymeterLocation</swes:observableProperty>
|
||||
<swes:metadata>
|
||||
<sos:SosInsertionMetadata>
|
||||
<sos:observationType>http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_GeometryObservation</sos:observationType>
|
||||
<sos:featureOfInterestType>http://www.opengis.net/def/samplingFeatureType/OGC-OM/2.0/SF_SamplingPoint</sos:featureOfInterestType>
|
||||
</sos:SosInsertionMetadata>
|
||||
</swes:metadata>
|
||||
</swes:InsertSensor>
|
||||
</env:Body>
|
||||
</env:Envelope>
|
|
@ -1,9 +1,12 @@
|
|||
# https://lists.ogc.org/pipermail/sensorml/2008-September/000573.html
|
||||
''' 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.
|
||||
|
@ -24,47 +27,51 @@ class Sensor:
|
|||
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 (,)
|
||||
# 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
|
||||
# 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') as csvfile:
|
||||
''' 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:
|
||||
for row in spamreader:
|
||||
# print(row)
|
||||
proj = Transformer.from_crs(31254, 4326, always_xy=True)
|
||||
|
||||
x1, y1, z1 = (float(row['Y']), float(row['X']), float(row['H']))
|
||||
x2, y2 = proj.transform(x1, y1)
|
||||
print((x2, y2)) # (11.597409730065536, 47.27196543449542)
|
||||
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)
|
||||
|
||||
|
||||
procedure = Procedure(sensor_name, sensor_name)
|
||||
|
||||
foi_name = "origin of " + sensor_name
|
||||
foi = FoI("degree", "m", (x2, y2, z1),
|
||||
sensor_name, foi_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")
|
||||
|
||||
sensor_type = SensorType("tachymeter")
|
||||
|
||||
sos_url = 'https://geomon.geologie.ac.at/52n-sos-webapp/service'
|
||||
headers = {'Content-Type': 'application/soap+xml'} # set what your server accepts
|
||||
# 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)
|
||||
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.
|
||||
|
@ -79,8 +86,8 @@ def get_xml(offering, procedure, foi, sensor_type):
|
|||
# longName = 'Sibratsgfall test' # string
|
||||
|
||||
# Offering values
|
||||
gml_id='\"' + str(procedure.id) + '\"' # Offering name, double quoted
|
||||
off_name = '\"' + str(offering.name) + '\"' # Offering name, double quoted
|
||||
# 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
|
||||
|
@ -133,7 +140,6 @@ def get_xml(offering, procedure, foi, sensor_type):
|
|||
xml = f'<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope/soap-envelope.xsd http://www.opengis.net/sos/2.0 http://schemas.opengis.net/sos/2.0/sosInsertSensor.xsd http://www.opengis.net/swes/2.0 http://schemas.opengis.net/swes/2.0/swes.xsd"><env:Body><swes:InsertSensor service="SOS" version="2.0.0" xmlns:swes="http://www.opengis.net/swes/2.0" xmlns:sos="http://www.opengis.net/sos/2.0" xmlns:swe="http://www.opengis.net/swe/2.0" xmlns:sml="http://www.opengis.net/sensorml/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd"><swes:procedureDescriptionFormat>http://www.opengis.net/sensorml/2.0</swes:procedureDescriptionFormat><swes:procedureDescription><sml:PhysicalSystem gml:id="{procedure_identifier}"><gml:identifier codeSpace="uniqueID">{procedure_identifier}</gml:identifier><sml:identification><sml:IdentifierList><sml:identifier><sml:Term definition="urn:ogc:def:identifier:OGC:1.0:longName"><sml:label>longName</sml:label><sml:value>{procedure_name}</sml:value></sml:Term></sml:identifier><sml:identifier><sml:Term definition="urn:ogc:def:identifier:OGC:1.0:shortName"><sml:label>shortName</sml:label><sml:value>{procedure_name}</sml:value></sml:Term></sml:identifier></sml:IdentifierList></sml:identification><sml:capabilities name="offerings"><sml:CapabilityList><!-- Parsed and removed during InsertSensor/UpdateSensorDescription, added during DescribeSensor. --><!-- Offering is generated if not specified. --><sml:capability name="offeringID"><swe:Text definition=\"urn:ogc:def:identifier:OGC:offeringID\"><swe:label>{offering_label}</swe:label><swe:value>{offering_name}</swe:value></swe:Text></sml:capability></sml:CapabilityList></sml:capabilities><sml:capabilities name="metadata"><sml:CapabilityList><!-- status indicates, whether sensor is insitu (true) or remote (false) --><sml:capability name="insitu"><swe:Boolean definition="insitu"><swe:value>true</swe:value></swe:Boolean></sml:capability><!-- status indicates, whether sensor is mobile (true) or fixed/stationary (false) --><sml:capability name="mobile"><swe:Boolean definition="mobile"><swe:value>true</swe:value></swe:Boolean></sml:capability></sml:CapabilityList></sml:capabilities><sml:featuresOfInterest><sml:FeatureList definition=\"http://www.opengis.net/def/featureOfInterest/identifier\"><swe:label>featuresOfInterest</swe:label><sml:feature><sams:SF_SpatialSamplingFeature xmlns:sams=\"http://www.opengis.net/samplingSpatial/2.0\" gml:id=\"ssf_b3a826dd44012201b01323232323041f7a92e0cc47260eb9888f6a4e9f747\"><gml:identifier codeSpace=\"http://www.opengis.net/def/nil/OGC/0/unknown\">{feature_id}</gml:identifier><gml:name codeSpace=\"http://www.opengis.net/def/nil/OGC/0/unknown\">{feature_name}</gml:name><sf:type xmlns:sf=\"http://www.opengis.net/sampling/2.0\" xlink:href=\"http://www.opengis.net/def/samplingFeatureType/OGC-OM/2.0/SF_SamplingPoint\"/><sf:sampledFeature xmlns:sf=\"http://www.opengis.net/sampling/2.0\" xlink:href=\"http://www.opengis.net/def/nil/OGC/0/unknown\"/><sams:shape><ns:Point xmlns:ns=\"http://www.opengis.net/gml/3.2\" ns:id=\"Point_ssf_b3a826dd44012201b013c90c51da28c041f7a92e0cc47260eb9888f6a4e9f747\"><ns:pos srsName=\"http://www.opengis.net/def/crs/EPSG/0/4326\">{coordinates}</ns:pos></ns:Point></sams:shape></sams:SF_SpatialSamplingFeature></sml:feature></sml:FeatureList></sml:featuresOfInterest><sml:position><swe:Vector referenceFrame="urn:ogc:def:crs:EPSG::4326"><swe:coordinate name="easting"><swe:Quantity axisID="x"><swe:uom code="degree"/><swe:value>{cord_x}</swe:value></swe:Quantity></swe:coordinate><swe:coordinate name="northing"><swe:Quantity axisID="y"><swe:uom code="degree"/><swe:value>{cord_y}</swe:value></swe:Quantity></swe:coordinate><swe:coordinate name="altitude"><swe:Quantity axisID="z"><swe:uom code="m"/><swe:value>{height}</swe:value></swe:Quantity></swe:coordinate></swe:Vector></sml:position></sml:PhysicalSystem></swes:procedureDescription><!-- multiple values possible --><swes:observableProperty>TachymeterLocation</swes:observableProperty><swes:metadata><sos:SosInsertionMetadata><sos:observationType>http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_GeometryObservation</sos:observationType><sos:featureOfInterestType>http://www.opengis.net/def/samplingFeatureType/OGC-OM/2.0/SF_SamplingPoint</sos:featureOfInterestType></sos:SosInsertionMetadata></swes:metadata></swes:InsertSensor></env:Body></env:Envelope>'
|
||||
return xml
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user