I am trying to import several CSV-files using Python. However, my code does not work. Furthermore, the coordinates are in DMS-format and I am unsure on how to implement that to my code.
import os.path, glob
layers=[]
for file in glob.glob('/Users/NAME/Desktop/gis/weights/*'):
uri="file:///"+file+"?type=csv&xField=LON&yField=LAT&spatialIndex=no&subsetIndex=no&watchFile=no&crs=epsg:4326"
vlayer = QgsVectorLayer(uri, os.path.basename(file), "delimitedtext")
vlayer.addAttributeAlias(0,'x')
vlayer.addAttributeAlias(1,'y')
layers.append(vlayer)
QgsMapLayerRegistry.instance().addMapLayers(layers)
When running my code I get the following error-messages:
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> NameError: name 'QgsMapLayerRegistry' is not defined
Below is a sample of the data in the CSV-file.