7

I have been able to load a GeoJSON file into QGIS by simply clicking "Add Vector Layer", and selecting my file to load.

Now I'm using the qgis.core Python package, and I'm trying to load the GeoJSON file as a layer. I'm following instructions from the QGIS Python Cookbook - Loading Layers section; but I can't find how to specify that I'm loading a GeoJSON file.

I've tried:

QgsVectorLayer("my_geo.json","mygeojson","geojson")

and

QgsVectorLayer("my_geo.json","mygeojson","json")

to no avail. Any advice on what I could do?

1 Answer 1

10

Use the OGR library, there is a complete list of supported filetypes.

From the QGIS Python Cookbook - Loading Layers:

OGR library (shapefiles and many other file formats) — data source is the path to the file

vlayer = QgsVectorLayer("my_geo.json","mygeojson","ogr")
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
0

Your Answer

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

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