Beispiel #1
0
    def work(self):
        self.einrichtungen.delete()
        query = GeoserverQuery()
        radius = self.radius * 1000
        centroid = self.project_frame.geom.asPoint()
        epsg = settings.EPSG
        centroid = Point(centroid.x(), centroid.y(), epsg=epsg)
        self.log('Frage Geoserver an...')
        features = query.get_features(centroid, radius, self.categories, epsg)
        self.log(f'Schreibe {len(features)} Einrichtungen in die Datenbank...')

        for feat in features:
            self.einrichtungen.add(name=feat.name,
                                   projektcheck_category=feat.category,
                                   geom=feat.geom)
    def work(self):
        mode, walk_speed = self.modes[self.modus]
        self.log(f'Ermittle die Isochronen für den Modus "{self.modus}"')
        conn_id = self.connector.id if self.connector else -1
        self.isochronen.filter(modus=self.modus, id_connector=conn_id)
        self.isochronen.delete()
        self.isochronen.reset()
        point = self.connector.geom.asPoint() if self.connector \
            else self.project_frame.geom.asPoint()

        epsg = settings.EPSG
        point = Point(point.x(), point.y(), epsg=epsg)
        cutoff_step = self.cutoff_sec / self.n_steps
        for i in reversed(range(self.n_steps)):
            sec = int(cutoff_step * (i + 1))
            self.log(f'...maximale Reisezeit von {sec} Sekunden')
            json_res = self._get_isochrone(point, mode, sec, walk_speed)
            if not json_res:
                continue
            iso_poly = ogr.CreateGeometryFromJson(json.dumps(json_res))
            geom = QgsGeometry.fromWkt(iso_poly.ExportToWkt())
            tr = QgsCoordinateTransform(
                QgsCoordinateReferenceSystem('epsg:4326'),
                QgsCoordinateReferenceSystem(f'epsg:{epsg}'),
                QgsProject.instance())
            geom.transform(tr)
            # the router sometimes returns broken geometries
            if not geom.isGeosValid():
                geom = geom.makeValid()
                # the junk is appended to a collection, discard it
                if geom.wkbType() == QgsWkbTypes.GeometryCollection:
                    geom = geom.asGeometryCollection()[0]
            self.isochronen.add(modus=self.modus,
                                sekunden=sec,
                                minuten=round(sec / 60, 1),
                                geom=geom,
                                id_connector=conn_id)
            self.set_progress(100 * (self.n_steps - i + 1) / self.n_steps)