QuantStack / jupytergis

JupyterGIS
BSD 3-Clause "New" or "Revised" License
8 stars 4 forks source link

QGIS loader and exporter #8

Open martinRenou opened 1 week ago

martinRenou commented 1 week ago

We will implement a QGIS loader.

This will be initially implemented in jupytergis, though it could probably be extracted into its own jupytergis-qgis extension in the long term.

Similar to the jupytercad-freecad package (JupyterCAD is to FreeCAD what JupyterGIS will be to QGIS), it will implement a bridge between the QGIS format and our internal JGIS format.

martinRenou commented 1 week ago

This should be fairly easy using the QGIS Python API:

In [1]: from qgis.core import QgsProject

In [2]: project = QgsProject.instance()
Application path not initialized
Application path not initialized
Application path not initialized
Application path not initialized
Application path not initialized
Application path not initialized

In [3]: print(project.fileName())

In [4]: project.read('examples/doc.qgz')
Out[4]: True

In [5]: project.layerTreeRoot
Out[5]: <function QgsProject.layerTreeRoot>

In [6]: project.layerTreeRoot()
Out[6]: <qgis._core.QgsLayerTree object at 0x000055913b5201a0>

In [7]: root = project.layerTreeRoot()

In [8]: root.children
Out[8]: <function QgsLayerTree.children>

In [9]: root.children()
Out[9]: 
[<QgsLayerTreeLayer: OpenStreetMap>,
 <QgsLayerTreeLayer: Mapzen Global Terrain>]

In [10]: project.crs
Out[10]: <function QgsProject.crs>

In [11]: project.crs()
Out[11]: <QgsCoordinateReferenceSystem: EPSG:3857>
davidbrochart commented 1 week ago

Just linking to the Felt QGIS plugin for inspiration, that allows to export a QGIS project to Felt from QGIS. There is a video.

martinRenou commented 1 week ago

Adding another note that, QGIS files being plain xml, we may also look into reading those files in Python without using pyqgis