GitHub

Chapter 31 · What changed

31.18 What changed in GeoDjango

The map widgets and BaseGeometryWidget.base_layer; OGRGeometry’s Z and M dimensions and curves; the milliseconds of DataSource’s dates and times; GeoIP2’s one database; and new spatial functions and lookups.

Since 6.0 the map widgets write no inline JavaScript into the page, only their options, as data. 5.1 told OGRGeometry’s Z and M dimensions apart. 6.0 removed the old way of setting a dimension. 5.2 gave OGRGeometry curves, which GeoDjango’s GEOS side cannot hold. Since 6.2 a DataSource keeps the milliseconds of dates and times. Since 5.1 GeoIP2 opens one database.

The security fixes to django.contrib.gis, for rasters and for nested geometry collections, are in Security fixes: SQL injection, Security fixes: disclosure, spoofing and privilege and Security fixes: limits against denial of service. The oldest GDAL, GEOS and PostGIS by release are in The versions Django needs: Python, databases and libraries.

The map widgets: options as data, and base_layer

Since 6.0 the map widgets, OpenLayersWidget and OSMWidget, write no inline JavaScript into the page. Their template writes the options as JSON, and the widget’s script, OLMapWidget.js, builds each map from them (django/contrib/gis/templates/gis/openlayers.html, django/contrib/gis/static/gis/js/OLMapWidget.js; GeoDjango’s forms, admin, feeds and data tools).

Under 5.2.17 the template gis/openlayers.html ended in a <script> with two blocks, base_layer and options, which made the base layer and the map’s options. OSMWidget’s gis/openlayers-osm.html filled the two blocks. The lines give each script element’s opening tag: 5.2.17’s is that inline script, the later releases’ the options as JSON:

OpenLayersWidget().render("position", None, attrs={"id": "id_position"}): the opening tag of each script element
    5.2.17       ['<script>']
    6.0.8        ['<script id="id_position_mapwidget_options" type="application/json">']
    6.1.1        ['<script id="id_position_mapwidget_options" type="application/json">']
    this commit  ['<script id="id_position_mapwidget_options" type="application/json">']

BaseGeometryWidget.base_layer, new in 6.0, names a layer builder in the script’s MapWidget.layerBuilder: "nasaWorldview" for OpenLayersWidget and "osm" for OSMWidget, which now renders the same template. A project’s own script can add a builder there. A name not there gives OpenStreetMap.

Since 6.1 OpenLayersWidget loads OpenLayers 10.9.0, where it loaded 7.2.2. 5.0 removed the admin’s GeoModelAdmin, OSMGeoAdmin and django.contrib.gis.admin.OpenLayersWidget, leaving GISModelAdmin. 5.1 removed BaseGeometryWidget’s map_width and map_height.

GDAL’s geometries: Z, M and curves

Since 6.0 setting OGRGeometry.coord_dim, a geometry’s coordinate dimension, raises AttributeError. OGRGeometry is GDAL’s geometry in GeoDjango, and until 5.1 it knew the dimension only as coord_dim. 5.1 told the Z and M dimensions apart: OGRGeometry.is_3d and OGRGeometry.is_measured read them, OGRGeometry.set_3d and OGRGeometry.set_measured add or drop them, and points and lines give their M coordinates. 5.1 also deprecated setting coord_dim. Only 5.2.17 still lets a point’s third dimension be set the old way:

OGRGeometry("POINT (1 2)").coord_dim = 3
    5.2.17       coord_dim is 3, warns RemovedInDjango60Warning
    6.0.8        AttributeError: property 'coord_dim' of 'Point' object has no setter
    6.1.1        AttributeError: property 'coord_dim' of 'Point' object has no setter
    this commit  AttributeError: property 'coord_dim' of 'Point' object has no setter

5.2 added the curved geometries, CircularString, CompoundCurve, CurvePolygon, MultiCurve and MultiSurface, with OGRGeometry.has_curve, OGRGeometry.get_linear_geometry and OGRGeometry.get_curve_geometry. GeoDjango’s GEOS classes have none for curves. The curved ones set OGRGeometry.geos_support false, and their OGRGeometry.geos raises GEOSException. On the GEOS side, GEOSGeometryBase.equals_identical, new in 5.0, compares geometries point by point. GEOSGeometryBase.hasm, new in 6.0, reads the M dimension. Both need GEOS 3.12 (GEOSGeometryBase.equals_identical, GEOSGeometryBase.hasm; Geometries in Python: GEOS and GDAL).

DataSource: dates and times keep their milliseconds

Since 6.2 a DataSource keeps the milliseconds of dates and times, and nothing warns. It gives date-time and time fields as OFTDateTime and OFTTime, whose values come from Field.as_datetime. Until 6.2 that method asked GDAL for whole seconds, into a ctypes.c_int. At this commit it calls GDAL’s OGR_F_GetFieldAsDateTimeEx, whose seconds are a ctypes.c_float. OFTDateTime.value and OFTTime.value round the fraction to milliseconds.

GDAL reads the GeoJSON property the block names as a date and time. Only this commit’s line keeps the milliseconds, as 250000 microseconds:

DataSource("seen.geojson")[0][0]["seen"].value: a property written "2026-10-17T10:00:30.250"
    5.2.17       datetime.datetime(2026, 10, 17, 10, 0, 30)
    6.0.8        datetime.datetime(2026, 10, 17, 10, 0, 30)
    6.1.1        datetime.datetime(2026, 10, 17, 10, 0, 30)
    this commit  datetime.datetime(2026, 10, 17, 10, 0, 30, 250000)

At this commit as_datetime itself gives seconds of 30.25, where 6.1.1 gave 30. The 6.2 notes list that change as backwards incompatible.

GeoIP2: one database, and the old methods gone

Since 5.1 GeoIP2 opens one database. Until then, given a directory, it opened both the city and the country database in it. The 5.1 notes say the country one is “a subset of the city database”. Now GeoIP2.__init__ opens the path itself if it is a file, else the city database in it, else the country one. GeoIP2.country reads whichever is open.

6.0 removed the methods coords and open, which 5.1 had deprecated for GeoIP2.lon_lat and the constructor (GeoDjango’s forms, admin, feeds and data tools).

Functions, lookups and backends

Smaller changes since 5.0, and what each database gained (Spatial lookups, functions and distances):

what change where
ClosestPoint change New in 5.0: the point of a geometry nearest another; PostGIS and SpatiaLite where ClosestPoint django/contrib/gis/db/models/functions.py
the spatial aggregates change Since 5.0, take filter= where GeoAggregate django/contrib/gis/db/models/aggregates.py
FromWKB, FromWKT change Since 5.1, take srid=, which Oracle ignores where FromWKB django/contrib/gis/db/models/functions.py
the measure Area change Since 5.1, takes the unit "ha" where Area django/contrib/gis/measure.py
Rotate change New in 6.0: a geometry turned about the origin or a point; PostGIS only where Rotate django/contrib/gis/db/models/functions.py
GeometryType, "geom_type" change New in 6.0: a geometry’s type; on Oracle from 23 where GeometryType django/contrib/gis/db/models/functions.py
NumDimensions, "num_dimensions" change New in 6.1: a geometry’s number of dimensions; PostGIS and SpatiaLite where NumDimensions django/contrib/gis/db/models/functions.py
MySQL change New in 5.1: Collect; new in 5.2: the lookups "coveredby" and "covers" where MySQLOperations django/contrib/gis/db/backends/mysql/operations.py
MariaDB change New in 6.0, from MariaDB 12.0.1: Collect, GeoHash, IsValid and the lookups "coveredby" and "isvalid" where MySQLOperations django/contrib/gis/db/backends/mysql/operations.py
SpatiaLite change New in Django 5.1, from SpatiaLite 5.1: BoundingCircle; new in 6.1: IsEmpty and the lookup "isempty" where SpatiaLiteOperations django/contrib/gis/db/backends/spatialite/operations.py
OGRGeometry.centroid change Since 5.1, on every type of geometry where OGRGeometry.centroid django/contrib/gis/gdal/geometries.py