mongiris package
This Python package is an interface for querying French administrative areas (IRIS, similar to neighborhoods) stored as documents in MongoDB.
Each IRIS includes indicators (e.g., average income, types of housings, number of bakeries or schools) that are useful for social sciences studies, for house/neighborhood recommendation, etc.
In this package, the ~50,000 IRIS and their 350-650 indicators have been integrated and stored in the GeoJSON format, and an API enables the manipulation of these data.
Prerequisites
- Python, version >=3
- MongoDB, version >=4, in which it is necessary to import the IRIS database (see Installation).
Installation
To install mongiris (and its dependencies):
python3 -m pip install git+https://fduchate@gitlab.liris.cnrs.fr/fduchate/mongiris.git#egg=mongiris
Next, you need to load the IRIS data into MongoDB (using the mongorestore
tool).
- download the dump of the database (724 MB)
- open a terminal and run:
mongorestore --archive=/path/to/dump-dbinsee.bin
where /path/to/
indicates the path to the downloaded dump database.
This restoration may take a few minutes as the geospatial indexes are rebuilt.
Usage
In MongoDB, the database is named dbinsee
. It contains three collections:
-
collsources
stores information about original data sources (title, release date, geographical information) -
collindic
stores information about indicators (short label, full label, data sources in which it appears). -
colliris
is the main collection, which stores each IRIS with its indicators (according to the GeoJSON format)
To manipulate the database, simply connect to MongoDB by creating an object of the Mongiris
class.
Using this object, twenty methods are available for querying the data.
Below is a minimal example of connection and queries (from tests/dummy.py
file):
from mongiris.api import Mongiris
db = Mongiris()
# return the number of documents in a collection
counts = db.count_documents(db.collection_indic, {})
# get complete information about iris identified with code 593500203
iris = db.find_one_document(db.collection_iris, {"properties.CODE_IRIS": "593500203"})
print(iris)
# get iris which contains coordinates 3.685111, 46.514643
iris2 = db.point_in_which_iris([3.685111, 46.514643])
print(iris2)
More examples, including testing geospatial queries, are available in the tests/api_tests.py
file.
Contributors
-
Fabien Duchateau, Franck Favetta (laboratory LIRIS, Université Lyon 1)
-
Loïc Bonneval (laboratory CMW, Université Lyon 2)
Acknowledgments
Data source provider :
Financial support :