Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ThomasG77/1aa1bf66d847be043a246df8bf74793e to your computer and use it in GitHub Desktop.
import glob
import os
from urllib.parse import quote
# Define path to directory of your csv files
path_to_csv = "your_path"
x_field = '經度' # longitude
y_field = '緯度' # latitude
# Set current directory to path of csv files
os.chdir(path_to_csv)
for fname in glob.glob("*.csv"):
uri = "file:///" + path_to_csv + quote(fname) + "?delimiter=%s&crs=epsg:4326&xField=%s&yField=%s" % (",", quote(x_field), quote(y_field))
name = fname.replace('.csv', '')
lyr = QgsVectorLayer(uri, name, 'delimitedtext')
QgsProject.instance().addMapLayer(lyr)
ID OccurrenceUUID 經度 緯度
1 001 18.78 89.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment