Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25141 closed Cleanup/optimization (fixed)

Remove GDAL Dependency for GeoJSON Serialiser

Reported by: drepo Owned by: nobody
Component: GIS Version: dev
Severity: Normal Keywords: GDAL, Dependency, GeoDjango, Serialiser, GeoJSON
Cc: mesulphur@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The documentation for GeoJSON Serialiser introduced in Django 1.8 categorically states:

The GDAL library is required for this serializer.

The problem with GDAL is that it has a lot of system level dependencies and does not play well with virtualenv - which is very common in Django deployments. The system level dependencies also make to hard to integrate it with a pip based dependency management workflow.

While there is a package that claims to wrap GDAL in a virtualenv friendly manner, in my trials, it was not Python3 compatible which, I believe, is essential given that the Django tutorials themselves now default to Py3.x.

PS: I have come across a maintained pure python GeoJSON library. (Disclosure: I have no association with the library/maintainers)

Change History (7)

comment:1 by drepo, 9 years ago

Here is a very (crude and use case specific) serialiser I could implement using the library (also linked in PS of original post). Adding here just to give a feel of its flow.

    qset = GeoModel.objects.all()
    payload = {
      'type': 'Feature',
      'crs': {
        'type': 'name',
        'properties': {'name': 'EPSG:4326'}
      },
      'features': []
    }
    features = payload['features']
    for province in qset:
      features.append({
        'type': 'Feature',
        'geometry': dict(MultiPolygon(province.geom.coords)),
        'properties': {
          'name': province.name,
          'admin': province.admin
        }
      })


comment:2 by Claude Paroz, 9 years ago

I think that we are not far from generating a valid JSON output from our own geometry objects, I don't think that we need an external lib for that.
However, it might be a lot more difficult to not use GDAL when coordinate transformations must happen. I don't think that the GeoJSON library you mentioned handles that (or correct me).

I'll see if I can provide a patch to not require GDAL when the geojson serialized output doesn't need any coordinate transformation.

comment:3 by Claude Paroz, 9 years ago

Has patch: set
Triage Stage: UnreviewedAccepted
Version: 1.8master

comment:4 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Claude Paroz <claude@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 1da170a2:

Fixed #25141 -- Diminished GDAL dependence during geojson serialization

Only require GDAL if contained geometries need coordinate transformations.
Thanks drepo for the report and Tim Graham for the review.

comment:6 by Sergey Fedoseev <fedoseev.sergey@…>, 9 years ago

In 0224f1c:

Refs #25141 -- Removed note that says that GEOSGeometry.json requires GDAL.

comment:7 by Tim Graham <timograham@…>, 9 years ago

In 3f04850:

[1.9.x] Refs #25141 -- Removed note that says that GEOSGeometry.json requires GDAL.

Backport of 0224f1cb042cc14545369b230cf7036af6c296ab from master

Note: See TracTickets for help on using tickets.
Back to Top