JoinAttributesByLocation चल रहे QgsProcessingException

Sep 18 2020

मैं निम्नलिखित कोड चलाने की कोशिश कर रहा हूं

import os
directory_in_str='/Users/name/Desktop/test/'
directory = os.fsencode(directory_in_str)
tre='?type=csv&quote=&escape=&trimFields=Yes&skipEmptyFields=Yes&maxFields=10000&detectTypes=yes&xyDms=yes&xField=lon&yField=lat&crs=EPSG:4326&spatialIndex=yes&subsetIndex=no&watchFile=no'
start='file:///Users/name/Desktop/test/'
for file in os.listdir(directory):
     filename = os.fsdecode(file)
     if filename.endswith(".csv"): 
        path_to_csv=start+filename+tre
        processing.run("qgis:joinattributesbylocation", {'INPUT':path_to_csv,'JOIN':'/Users/name/Desktop/gis/NUTS_uppdelade/NUTS_ID_SE11.gpkg|layername=NUTS_ID_SE11','PREDICATE':[0,5],'JOIN_FIELDS':[],'METHOD':0,'DISCARD_NONMATCHING':True,'PREFIX':'','OUTPUT':'/Users/name/Desktop/gis/regn/vikter/NUTS_ID_SE111900Q1.gpkg'})

मेरा इरादा फ़ोल्डर परीक्षण में सभी फ़ाइलों के लिए स्थान द्वारा जुड़ने की विशेषताओं को चलाने के लिए स्क्रिप्ट प्राप्त करना है। हालाँकि, यह निम्न त्रुटि देता है:

exec(open('/var/folders/ks/1x_p2hz95jldm5xvpjfg0gmm0000gn/T/tmpdq2z8ia3.py'.encode('utf-8')).read())
Traceback (most recent call last):
  File "/Applications/QGIS3.10.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.7/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "<string>", line 10, in <module>
  File "/Applications/QGIS3.10.app/Contents/MacOS/../Resources/python/plugins/processing/tools/general.py", line 106, in run
    return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
  File "/Applications/QGIS3.10.app/Contents/MacOS/../Resources/python/plugins/processing/core/Processing.py", line 137, in runAlgorithm
    raise QgsProcessingException(msg)
_core.QgsProcessingException: Kan inte köra algoritm
Kunde inte läsa in källager för INPUT: file:///Users/name/Desktop/test/1900Q1.csv?type=csv&quote=&escape=&trimFields=Yes&skipEmptyFields=Yes&maxFields=10000&detectTypes=yes&xyDms=yes&xField=lon&yField=lat&crs=EPSG:4326&spatialIndex=yes&subsetIndex=no&watchFile=no ej hittad

मतलब यह कि परत नहीं मिली। मैं वास्तव में अपना सिर इधर-उधर नहीं कर सकता, क्योंकि यह त्रुटि संदेश मुझे मिलता है क्योंकि जब यह संयोजन करने वाला होता है, तो स्ट्रिंग्स की प्रतिलिपि पेस्ट के साथ path_to_csv की जगह काम करता है।

इसलिए मुझे लगता है कि मैं किसी तरह से path_to_csv को गलत बताता हूं। कोई सलाह?

संपादित करें 1: यदि प्रासंगिक है, तो यह वह कोड है जिसे मैं चलाने में सफल रहा हूं:

processing.run("qgis:joinattributesbylocation", {'INPUT':'file:///Users/name/Desktop/test/1900Q1.csv?type=csv&quote=&escape=&trimFields=Yes&skipEmptyFields=Yes&maxFields=10000&detectTypes=yes&xyDms=yes&xField=lon&yField=lat&crs=EPSG:4326&spatialIndex=yes&subsetIndex=no&watchFile=no','JOIN':'/Users/name/Desktop/gis/NUTS_uppdelade/NUTS_ID_SE11.gpkg|layername=NUTS_ID_SE11','PREDICATE':[0,5],'JOIN_FIELDS':[],'METHOD':0,'DISCARD_NONMATCHING':True,'PREFIX':'','OUTPUT':'/Users/name/Desktop/gis/regn/vikter/NUTS_ID_SE111900Q1.gpkg'})

जवाब

2 timpan Sep 18 2020 at 20:41

मैंने निर्दिष्ट नहीं किया कि यह एक QgsVectorLayer था।

vlayer = QgsVectorLayer(path_to_csv, "temp", "delimitedtext")
processing.run("qgis:joinattributesbylocation", {'INPUT':vlayer,'JOIN':'/Users/name/Desktop/gis/NUTS_uppdelade/NUTS_ID_SE11.gpkg|layername=NUTS_ID_SE11','PREDICATE':[0,5],'JOIN_FIELDS':[],'METHOD':0,'DISCARD_NONMATCHING':True,'PREFIX':'','OUTPUT':'/Users/name/Desktop/gis/regn/vikter/NUTS_ID_SE111900Q1.gpkg'}

अब, यह आसानी से चलता है!