I am dealing with a vector layer containing ~3400 points. All of them have an individual identifying code (Name
) and another one (Network
) they share with others of the dataset since they belong a larger network. Thus the attribute table looks somewhat like this:
Network Name AdditionalInformation
a Name1 Some
a Name2 Information
a Name3 Is
a Name4 Written
b Name5 In
b Name6 This
b Name7 Field
What needs to be done is calculating the maximum distance between several points belonging to the same network (these are more than 500). However, my knowledge of calculation tools of this kind is limited to QGIS' Distance Matrix tool and I do not see a suitable solution for this entire dataset.
What might be the best way to proceed here?
Is there any way, for instance, to use the Python console in order to calculate distance matrices for each and every network based on the common denominator Network
and save all maximum values to a CSV file afterwards?
I split the layer into smaller ones and saved them accordingly. The script, copied from Joseph, is now:
import glob, os, processing
path = "G:\ZIM\Analyse_Foerderprogramme\_ZIM-SOLO und ZIM-KOOP 2014\GIS\Adressen_TOMTOM\Split"
output_path = "G:\ZIM\Analyse_Foerderprogramme\_ZIM-SOLO und ZIM-KOOP 2014\GIS\Adressen_TOMTOM\Split\Ergebnisse"
field_1 = "NAME"
field_2 = "GEOCODE"
for layer in glob.glob(path + "*.shp"):
processing.runalg("qgis:distancematrix", layer, field_1, layer, field_2, 2, 0, output_path + os.path.basename(layer) + ".csv")
Yet nothing is happening so far after typing it into the console. I am but a beginner in the usage of the Python console so surely I made a mistake. What next?
The earlier mistake was the use of \
instead of the proper /
. Now, the script (with more readable paths) looks like:
import glob, os, processing
path = "H:/Split/"
output_path = "H:/Split/Ergebnisse/"
field_1 = "NAME"
field_2 = "GEOCODE"
for layer in glob.glob(path + "*.shp"):
processing.runalg("qgis:distancematrix", layer, field_1, layer, field_2, 2, 0, output_path + os.path.basename(layer) + ".csv")
This results in the error [Errno 2] No such file or directory: 'H:/Split/Ergebnisse/Adressen_projiziert_Info_NAME__G533.shp.csv' See log for more details
Why does Python look for a CSV file at the very beginning instead of calculating first and writing the results in a file of this sort second?
Joseph's script works. However, the error message remains the same for the file I'm trying to work with. Can anyone tell me what the log message might point to?
2016-09-23T16:22:45 2 Uncaught error while executing algorithm
Traceback (most recent call last):
File "C:/PROGRA~1/QGIS2~1.14/apps/qgis-ltr/./python/plugins\processing\core\GeoAlgorithm.py", line 203, in execute
self.processAlgorithm(progress)
File "C:/PROGRA~1/QGIS2~1.14/apps/qgis-ltr/./python/plugins\processing\algs\qgis\PointDistance.py", line 89, in processAlgorithm
self.writer = outputFile.getTableWriter([])
File "C:/PROGRA~1/QGIS2~1.14/apps/qgis-ltr/./python/plugins\processing\core\outputs.py", line 245, in getTableWriter
return TableWriter(self.value, self.encoding, fields)
File "C:/PROGRA~1/QGIS2~1.14/apps/qgis-ltr/./python/plugins\processing\tools\vector.py", line 668, in __init__
with open(self.fileName, 'wb') as csvFile:
IOError: [Errno 2] No such file or directory: 'C:/Users/klinge/GIS/Split/Ergebnisse/Ausgangsdaten_Vorhaben__ZKN060503.csv'
2016-09-23T16:22:45 1 There were errors executing the algorithm.
The error message did not occur on another (Linux) computer.
r
before your path. I.e.path = "G:\ZIM\Analyse_Foerderprogramme\_ZIM-SOLO und ZIM-KOOP 2014\GIS\Adressen_TOMTOM\\Split"
; orpath = r'G:\ZIM\Analyse_Foerderprogramme\_ZIM-SOLO und ZIM-KOOP 2014\GIS\Adressen_TOMTOM\Split'
C:/
drive. I'm guessing theH:/
drive is external?