Saturday 27 February 2016

fields attributes - Is there are way to import non-geo JSON files into QGIS?


Here is a json file containing various attributes relating to countries. However, it does not contain any geographic data.


http://bost.ocks.org/mike/nations/nations.json


I would like to join these attributes with another file that has the geographic data for the countries. But I can't figure out how to get it into QGIS.


Is there a way of loading non-geojson json files into QGIS?



Answer



Yes, you can import non-geo JSON files into QGIS but there are no native method for this in QGIS. It's because in your link, it's non tabular data. For each "column" (like income) per country, you have year and value. You need to preprocess the data to change the structure to flatten it to 2 dimensions.


One choice could be to use PyQGIS console to solve this issue. In first, you get the data with standard Python urllib2 and json libraries and process it with Python. Then, using a memory provider, you can integrate the data as a layer and make your join. Be aware that if you need to reuse the data later, you will need to execute again the operations. So, you will need to save your memory layer or use the "Memory Layer Saver" plugin (but this plugin keeps data persistent per project).



Another choice could be to avoid QGIS completely at the beginning and generate a CSV from the data using Python (outside QGIS). Then, you can load the CSV file in QGIS.


For PyQGIS, look at the PYQGIS cookbook.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...