I have the following layers in QGIS:
- origins points
- destination points
- a layer of lines that is the route
I want to calculate the matrix with the distance from origin to destination using Network Analysis.
I've tried to do a python script using this, but I'm not seeing any results.
I honestly do not know anything about gis or python. But I need to make a data analysis. This is what I have done, I can not even read the layers. I'm also not sure if the cost represents the distance traveled
#Definition of inputs and outputs #================================== ##[my scripts]=group ##origin_layer=vector ##origin_id_column_index=field origin_layer ##destination_layer=vector ##destination_id_column_index=field destination_layer ##route_layer=vector ##output=string #Algorithm body #================================== from PyQt4.QtCore import * from PyQt4.QtGui import * from qgis.core import * from qgis.gui import * from qgis.networkanalysis import * from processing.core.VectorWriter import VectorWriter import processing from scipy.spatial.distance import cdist import numpy as np from math import sqrt origin_layer = processing.getObject(origin_layer) origin_id_column_index = origin_layer.fieldNameIndex(origin_id_column_index) destination_layer = processing.getObject(destination_layer) destination_id_column_index = destination_layer.fieldNameIndex(destination_id_column_index) route_layer = processing.getObject(route_layer) # don't use information about road direction from layer attributes, # all roads are treated as two-way director = QgsLineVectorLayerDirector(route_layer, -1, '', '', '', 3) for origin_feature in origin_layer: pStart = origin_feature.geometry().centroid().asPoint() for destination_feature in destination_layer: pStop = destination_feature.geometry().centroid().asPoint() tiedPoints = director.makeGraph(builder, [pStart, pStop]) graph = builder.graph() tStart = tiedPoints tStop = tiedPoints idStart = graph.findVertex(tStart) idStop = graph.findVertex(tStop) (tree, cost) = QgsGraphAnalyzer.dijkstra(graph, idStart, 0)