#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 , 10 years ago
comment:2 by , 10 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 , 10 years ago
| Has patch: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Version: | 1.8 → master |
comment:4 by , 10 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
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 } })