I couldn't find any proper example of how to import a .csv with WKT coordinates (Polygon) in PyQGIS.

Here are more details on my .csv. I am working with polygons. The delimiter is a semi colum, and the name of the variable that contains the relevant coordinates is WKT . Thus I wrote :

1) uri = "data/idf.csv?delimiter=%s&crs=ESPG:2154&wktField=%s" % (";", "WKT")

2) idf_stats_csv = QgsVectorLayer(uri,"idf","delimitedtext")

But this does not work. Do you have any more advice?

  • Perhaps this link might help. – Joseph Apr 9 '15 at 11:33
  • Hi Flo, perhaps you can edit your question to include the information from your comment please? That way, it's more readable to those who are in a position to help you. At the moment, this is beyond me =) – Joseph Apr 9 '15 at 11:44
  • Thx for your advice Joseph – Flo Apr 9 '15 at 11:53
  • 1
    Apparently, you're missing the file:/// prefix, try something like: uri = "file:///path/to/your/data/idf.csv?delimiter=%s&crs=epsg:2154&wktField=%s" % (";", "WKT") – Germán Carrillo Apr 9 '15 at 12:21
  • I also tried it before but this does not seem to be the problem. – Flo Apr 9 '15 at 12:33
uri ='file:///C://Users//Documents//Filepath//WKT_file.csv?delimiter=%s&crs=epsg:2154&wktField=%s' % (";", "WKT")
lyr = QgsVectorLayer(uri, 'Name_of_new_temp_output_layer','delimitedtext')

This should work. It worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.