GeoDjango - Support for the Python Geo Interface / __geo_interface__

Hello, according to this page there was effort to add support for __geo_interface__ to GEOSGeometry:

It seems that this is not available in Django (at least not in <3.2). Can anybody clarify?

If you look at the history of that page, you’ll see that that page was last edited about 11 years ago, I wouldn’t rely upon that as being useful information.

Is this supported by an existing Python library? (If so, would that be sufficient for what you’re trying to do?)

1 Like

rasterio.features.rasterize :

The geometry can either be an object that implements the geo interface or GeoJSON-like object.

The workaround is to get the WKB from the GEOSGeometry and load it using shapely:

from shapely.wkb import loads

geometry = loads(model_instance.geometry.wkb.tobytes())

This page also lists GeoDjango as supporting the __geo_interface__:

In general, I’d say it is pretty widespread in the non-GeoDjango GIS community (fiona, shapely, rasterio, etc.).