Linking C++ and JS with PYTHON

involving QGIS C++ APIs, PyQGIS, QWebKit and PyQt

Case study: Geosisma a QGIS plugin


Who am I

15 year working on Spatial Ground Segments
Landsat, Cryosat, MODIS, Sentinel...

Since 2006 in QGIS/GRASS

QGIS Core developer
WMS Legend support in legend and composer
Saving style in Spatialite
Add SVG support to Mapserver/SLD interface
Bug fixing
Plugin porting and developing

Founder of GFOSS.it
Italian OSGEO Local Chapter

Co-Author of Mastering QGIS
















https://www.packtpub.com/application-development/mastering-qgis

Reviewer for

QGIS Python Programming Cookbook
















https://www.packtpub.com/application-development/qgis-python-programming-cookbook
QGIS (mainly C++)
http://www.qgis.org/api/
 
Geosisma (Online)
http://geosisma-test.faunalia.it/
http://www200.regione.toscana.it/emergenza/geosisma/

QT  (C++)
http://qt-project.org/

SIP (Python2C++/C binder)
http://www.riverbankcomputing.com/software/sip/intro
PyQt (SIP bind to QT)
http://www.riverbankcomputing.com/software/pyqt/intro
PyQGIS (SIP bind to QGIS)
http://www.qgis.org/en/docs/pyqgis_developer_cookbook/

What is QGIS

www.qgis.org - www.osgeo.org

Geographic Information System

What is Geosisma


Online/Offline Earthquake Damage Inventory Tool

Offline Functional Specifications 

  • Cache preparing integrating other project code

  • Download "Requests" based on User Credentials using REST APIs

  • Fill "Safety report" with "Request" data

  • Associate Cadastral Polygon to "Safety report"

  • Edit Cadastral Polygons

  • The same  Online behavior (zooming, auto-complete, data validation)  

  • Upload "Safety reports" and cadastral poligons using public REST APIs



I'm a lazy developer


reuse, reuse, reuse,  reuse,  reuse,  reuse,  reuse          

What About HTML5?


Main usable feature for Geosisma Offline


  • Caching (Offline capability)

  • Persistence (Session and Local storage)

  • Platform Independent


Re-use Online Form


  • Created using Django
  • Complex specification (Form validation and logic)
  • Re-using final form rendering
  • Minimal modifications
  • Follow evolution (next will be mobile)

....SO....

Insert the Online form inside QGIS

...Brighton 10th QGIS Hackfest...


Credits QGIS

"first" (secret) prototype

tech available since 2011

QgisD3 by Luca Casagrande


QgisD3 Python Plugin

a never published plugin

The architecture

Container

  • Instantiate WebView

  • Configure WebView (QWebSettings)

  • Instantiate Bridge class

  • (optional) add listener to Bridges's events

  • Inject Bridge in JS (addToJavaScriptWindowObject)

  • inject JS code to evaluate (eg. a JS bridge methods - evaluateJavaScript)


WebView2Container Bridge


  • Def PY slots called by JS
        @pyqtSlot(<params definition>)
        def slotName(self, records):

  • (optional) define out signals - pyqtSignal()



WebView (JS)


sourcing JS bridge (Container2WebView bridge)

Results

Luigi Pirelli

luipir@gmail.com - @ginetto
https://github.com/luipir
http://www.linkedin.com/in/luigipirelli
gis.stackexchange.com/users/19667/luigi-pirelli

Hire me: https://www.elance.com/s/edit/luigipirelli/


Geosisma:
funded by Regione Toscana - Settore Prevenzione Sismica
Work committed by: Faunalia (www.faunalia.eu)
Licence: (CC BY-SA 3.0)
Made with Slides.com