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 making a mistake.

Since I am using Python console inside QGIS do I need to set environment variables?

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

layer.isValid()
3
  • 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
    Commented Aug 27, 2018 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
    Commented Aug 27, 2018 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
    Commented Aug 27, 2018 at 10:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.