1

I am trying to import a .shp file and CSV file so that I can join data. I have written below code in Python console within QGIS. For Layer.isvalid(), I am getting False. I am using QGIS 3 and on Windows 7. I don't know where I am doing mistake. Since I am using Python console inside QGIS should I need to set enviorment variables?

layer = QgsVectorLayer("file:///C:Test/t1_2013_06_tract/t1_2013_06_tract.shp","BuildingLayer","ogr")

layer.isValid()
  • 1
    If that is for a shapefile, simply the path should be enough (i.e. layer=QgsVectorLayer("C:Test/t1_2013_06_tract/t1_2013_06_tract.shp","BuildingLayer","ogr") – Joseph Aug 27 '18 at 9:49
  • @Joseph and in case of csv Files I tried above by replacing t1_2013_06_tract.shp by ca_tracts_pop.csv it is still showing invalid – ps1 Aug 27 '18 at 9:58
  • Your csv path will need to include additional information as to how QGIS should read it (i.e. if you want to load it as vector layer with geometries, you would need to define specific parameters). This post should help: How to load a data table as a 'vector layer' using PyQGIS? – Joseph Aug 27 '18 at 10:07

Your Answer

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

Browse other questions tagged or ask your own question.