0

I'm trying to use a script that loads in a point layer from CSV. The code that I used is:

uri = "file:///some_path/PyQGIS/Some.csv?delimiter={}&xField={}&yField={}".format(os.getcwd(), ";", "X", "Y")

vlayer = QgsVectorLayer(uri, "Name", "delimitedtext")

QgsProject.instance().addMapLayer(vlayer)

The structure of the .csv file is as follows: SomeValue ----- X ----- Y

Hereby, the coordinates are put according to Amersfoort (EPSG:4289) e.g.: X = 213404, Y = 500846. When trying to load this in manually, everything is going fine. However in the script, it does not seem to work. To clarify: The delimiter used is a ;

Thanks in advance.

Bram
  • 31
  • 3

2 Answers2

0

You can specify the projection of your data set by adding &crs=epsg:4723 to the URI definition. So your case becomes:

uri = "file:///some_path/PyQGIS/Some.csv?delimiter={}&crs=epsg:4289&xField={}&yField={}".format(os.getcwd(), ";", "X", "Y")

vlayer = QgsVectorLayer(uri, "Name", "delimitedtext")

QgsProject.instance().addMapLayer(vlayer)
Ian Turton
  • 10,018
  • 1
  • 28
  • 47
0

The answer to this is issue has been solved by removing the "os.getcwd()" part of the code. Hope this will help anyone with similar issues.

Bram
  • 31
  • 3