Skip to content

Commit

Permalink
Merge pull request #20 from gis-ops/cb-isopolys
Browse files Browse the repository at this point in the history
Proper support for Polygons and MultiPolygons
  • Loading branch information
chrstnbwnkl committed Feb 20, 2024
2 parents 61b3953 + 62e650b commit ed1a708
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
27 changes: 21 additions & 6 deletions valhalla/common/isochrones_core.py
Expand Up @@ -126,22 +126,37 @@ def get_features(self, id_field_value, options={}):
:rtype: QgsFeature
"""

features = [feature for feature in self.response['features'] if feature['geometry']['type'] in ('LineString', 'Polygon')]

features = [feature for feature in self.response['features'] if feature['geometry']['type'] in ('LineString', 'Polygon', 'MultiPolygon')]
# Sort features based on the isochrone value, so that longest isochrone
# is added first. This will plot the isochrones on top of each other.
l = lambda x: x['properties']['contour']
for isochrone in sorted(features, key=l, reverse=True):
feat = QgsFeature()
coordinates = isochrone['geometry']['coordinates']
geom_type = isochrone['geometry']['type']
iso_value = isochrone['properties']['contour']
#metric = isochrone['properties']['metric']
if self.geometry == 'Polygon':
qgis_coords = [[QgsPointXY(coord[0], coord[1]) for coord in coordinates[0]]]
qgis_coords = []
if geom_type == 'Polygon':
for ring in coordinates:
ring_coords = []
for coord in ring:
ring_coords.append(QgsPointXY(coord[0], coord[1]))
qgis_coords.append(ring_coords)
feat.setGeometry(QgsGeometry.fromPolygonXY(qgis_coords))
if self.geometry == 'LineString':
if geom_type == 'LineString':
qgis_coords = [QgsPointXY(coord[0], coord[1]) for coord in coordinates]
feat.setGeometry(QgsGeometry.fromPolylineXY(qgis_coords))
if geom_type == 'MultiPolygon':
for poly in coordinates:
poly_coords = []
for ring in poly:
ring_coords = []
for coord in ring:
ring_coords.append(QgsPointXY(coord[0], coord[1]))
poly_coords.append(ring_coords)
qgis_coords.append(poly_coords)
feat.setGeometry(QgsGeometry.fromMultiPolygonXY(qgis_coords))

feat.setAttributes([
id_field_value,
float(iso_value),
Expand Down
1 change: 0 additions & 1 deletion valhalla/gui/ValhallaDialog.py
Expand Up @@ -343,7 +343,6 @@ def run_gui_control(self):
layer_out.dataProvider().addFeature(feat)

layer_out.updateExtents()
# isochrones.stylePoly(layer_out, metric)
self.project.addMapLayer(layer_out)

if not no_points:
Expand Down
4 changes: 2 additions & 2 deletions valhalla/gui/isochrones_gui.py
Expand Up @@ -72,9 +72,9 @@ def get_parameters(self, metric):
'id': 1,
}

if denoise:
if denoise is not None:
params['denoise'] = denoise
if generalize:
if generalize is not None:
params['generalize'] = generalize

# Get Advanced parameters
Expand Down

0 comments on commit ed1a708

Please sign in to comment.