2

I am trying to calculate the costpath from a location (polygon) to a point dataset using QGIS. I found two tools (r.cost.raster & accumulated cost (isotropic)), which both would work, if I would use only raster datasets. Unfortunatly one of my Datasets is a polygon so I can't use these tools. Any ideas how I could work around this problem?

closed as too broad by mgri, whyzar, tinlyx, Michael Stimson, nmtoken Jun 19 '17 at 7:27

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Why don't you preliminarily convert your shapefiles to rasters and then convert the outputs to shapefiles again? As it is currently written, your question is too broad because it doesn't describe a specific problem (so, my question could be wrong because it doesn't refer to a specific situation). – mgri Jun 18 '17 at 19:08
2

You have to use PyQGIS for that, here is an example:

# define the point 
pt = QgsPoint(572470.29638,191838.143182) 
pt =  QgsGeometry.fromPoint(pt)

# get the active polygon 
layer = qgis.utils.iface.activeLayer() 
polygon = layer.getFeatures().next() 
geom = polygon.geometry()

# do the business     
distanceToPolygon = QgsGeometry.distance(pt, geom) 
print distanceToPolygon

Not the answer you're looking for? Browse other questions tagged or ask your own question.