63 lines
2.5 KiB
Python
63 lines
2.5 KiB
Python
from PyQt5.QtCore import QVariant
|
|
from qgis._core import QgsCoordinateReferenceSystem, QgsGeometry, QgsPointXY
|
|
from qgis.core import QgsFields, QgsFeature, QgsField
|
|
|
|
from .po_stations import PoStations
|
|
|
|
|
|
class PoStationsQgs(PoStations):
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.fields = None
|
|
self.crs = QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId)
|
|
|
|
def getStationsFeatures(self):
|
|
print("getStationsFeatures: Erzeuge Features...")
|
|
|
|
self.fields = QgsFields()
|
|
self.fields.append(QgsField('uuid', QVariant.String))
|
|
self.fields.append(QgsField('number', QVariant.LongLong))
|
|
self.fields.append(QgsField('shortname', QVariant.String))
|
|
self.fields.append(QgsField('longname', QVariant.String))
|
|
self.fields.append(QgsField('km', QVariant.Double))
|
|
self.fields.append(QgsField('agency', QVariant.String))
|
|
self.fields.append(QgsField('water', QVariant.String))
|
|
|
|
features = []
|
|
stations = self.getStations()
|
|
|
|
if stations is None or len(stations) == 0:
|
|
print("getStationsFeatures: Fehler: Keine Stationen erhalten")
|
|
return None
|
|
|
|
for station in stations:
|
|
feature = self._getFeatureForStation(station)
|
|
if feature is not None:
|
|
features.append(feature)
|
|
|
|
print("getStationsFeatures: %d Features erzeugt" % (len(features),))
|
|
return features
|
|
|
|
def _getFeatureForStation(self, station) -> None | QgsFeature:
|
|
# noinspection DuplicatedCode
|
|
if station['geometry']['longitude'] is None or station['geometry']['latitude'] is None:
|
|
print("_getFeatureForStation: WARN: Station hat fehlende Koordinaten: %s" % (station['attributes']['shortname'],))
|
|
return None
|
|
|
|
feature = QgsFeature(self.fields)
|
|
|
|
longitude = station['geometry']['longitude']
|
|
latitude = station['geometry']['latitude']
|
|
feature.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(longitude, latitude)))
|
|
|
|
feature.setAttribute('uuid', station['attributes']['uuid'])
|
|
feature.setAttribute('number', station['attributes']['number'])
|
|
feature.setAttribute('shortname', station['attributes']['shortname'])
|
|
feature.setAttribute('longname', station['attributes']['longname'])
|
|
feature.setAttribute('km', station['attributes']['km'])
|
|
feature.setAttribute('agency', station['attributes']['agency'])
|
|
feature.setAttribute('water', station['attributes']['water'])
|
|
|
|
return feature
|