I'm completely new using PyQGIS and developing plugins.
Currently I have a layer with the X and Y coordinates of electric distribution poles, where each pole is a feature. What I need to do is measure the distance between all the features in the map, but it must be done pole by pole. By example, take the first pole and get all the distances between the first pole and all the others, then, take the second pole and repeat until the end of the dataset.
Any ideas or references for doing this?
As a reference, I was doing the same thing in Matlab with a dataset of 20 features with something like this:
for i=1:20
for j=1:20
if i~=j
distance = euclidean(P1(i), P1(j));
Where P1(i) and P1(j) are the X-Y coordinates of two different points (Each one Written as a complex number) and "euclidean" is a function that calculates the distance between these two points.
Best Answer
By using PyQGIS this code works:
I tried out the code at the Python Console with the layer point (projected in meters) of next image:
and the result was (for upper triangular distance matrix):
Editing Note:
The code with gene suggestions:
and the results in a QGIS plugin with the same suggestions: