Pegelonline/po_modules/po_station.py

35 lines
1.3 KiB
Python

from qgis._core import QgsFeature, QgsGeometry, QgsPointXY
class PoStation(object):
def __init__(self, json):
self.longitude = json['longitude'] if 'longitude' in json else None
self.latitude = json['latitude'] if 'latitude' in json else None
self.uuid = json['uuid']
self.number = json['number']
self.shortname = json['shortname']
self.longname = json['longname']
self.km = json['km'] if 'km' in json else None
self.agency = json['agency']
self.water = json['water']['longname']
def new_feature(self, fields) -> None | QgsFeature:
if self.longitude is None or self.latitude is None:
print("PoStation::new_feature: WARN: Station hat fehlende Koordinaten: %s" % (self.shortname,))
return None
feature = QgsFeature(fields)
feature.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(self.longitude, self.latitude)))
feature.setAttribute('uuid', self.uuid)
feature.setAttribute('number', self.number)
feature.setAttribute('shortname', self.shortname)
feature.setAttribute('longname', self.longname)
feature.setAttribute('km', self.km)
feature.setAttribute('agency', self.agency)
feature.setAttribute('water', self.water)
return feature