8

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?

asked Dec 1, 2015 at 7:09

1 Answer 1

12

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)
answered Dec 1, 2015 at 7:52
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.