Using the __geo_interface__ protocol
The __geo_interface__ is a newer protocol, created by Sean Gillies and targeted mainly at Python, to provide a string representation of geographical data following Python's built-ins protocol. The string representation for geographical data is basically GeoJSON. You can read more about this protocol here:
https://gist.github.com/sgillies/2217756
Two developers, Nathan Woodrow and Martin Laloux, refined a version of this protocol for QGIS Python data objects. This recipe borrows from their examples to provide a code snippet, which you can put at the beginning of your Python scripts to retrofit QGIS feature and geometry objects with a __geo_interface__
method.
Getting ready
This recipe requires no preparation. ...
Get QGIS Python Programming Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.