Skip to main content

django-geojson

INSTALL

pip install django-geojson

If you need to load data from GeoJSON files (deserialize), you’ll also need shapely

pip install "django-geojson [shapely]"

USAGE

Add djgeojson to your applications :

# settings.py

INSTALLED_APPS += (
    'djgeojson',
)

(not required for views)

GeoJSON layer view

Very useful for web mapping :

# urls.py
from djgeojson.views import GeoJSONLayerView
...
url(r'^data.geojson$', GeoJSONLayerView.as_view(model=MushroomSpot), name='data'),

Consume the vector layer as usual, for example, with Leaflet :

var layer = L.GeoJSON();
map.addLayer(layer);
$.getJSON("{% url 'data' %}", function (data) {
    layer.addData(data);
});

Inherit only if you need a reusable set of options :

# views.py
from djgeojson.views import GeoJSONLayerView

class MapLayer(GeoJSONLayerView):
    # Options
    precision = 4   # float
    simplify = 0.5  # generalization


# urls.py
from .views import MapLayer, MeetingLayer
...
url(r'^mushrooms.geojson$', MapLayer.as_view(model=MushroomSpot, fields=('name',)), name='mushrooms')

Most common use-cases are low-fi precision, common list of fields, etc.

GeoJSON template filter

Will work either for a model, a geometry field or a queryset.

{% load geojson_tags %}

var feature = {{ object|geojsonfeature }};

var geom = {{ object.geom|geojsonfeature }};

var collection = {{ object_list|geojsonfeature }};

Dump GIS models

Register the serializer in your project :

# settings.py

SERIALIZATION_MODULES = {
    'geojson' : 'djgeojson.serializers'
}

Command-line dumpdata can export files, viewable in GIS software like QGis :

django dumpdata --format=geojson yourapp.Model > export.geojson

Works with loaddata as well, which can now import GeoJSON files.

AUTHORS

Relies massively on Sean Gillies’ geojson python module.

makinacom

LICENSE

  • Lesser GNU Public License

CHANGELOG

1.2.0 (2013-05-22)

  • Shapely is now optional (used for deserialization only)

  • Add Django to requirements

  • Skip a step in GeoJSON conversion of geometries (fixes #6)

1.1.0 (2013-03-06)

  • Django 1.5 support

  • Fix template tag geojsonfeature on empty geometries

1.0.0 (2012-08-03)

  • Initial working version.

Metadata

Release files for django-geojson 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-geojson 1.2.0
File Size Uploaded
django-geojson-1.2.0.zip 16.0 kB Details

Release files / django-geojson-1.2.0.zip

Download URL django-geojson-1.2.0.zip
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e349e71b18e2afc15566b83f591e443a3339b37874e32dd0bc9b6aaa00787efc
BLAKE2b-256 checksum
How to use checksums
8859019b998fef7df964f554d9bf4966097f6806ddf0a0186473c29f2fc69c9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

4.2.0

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.0

1 release file

2.12.0

1 release file

2.11.0

1 release file

2.10.0

1 release file

2.9.1

1 release file

2.9.0

1 release file

2.8.1

1 release file

2.8.0

1 release file

2.7.0

1 release file

2.6.0

1 release file

2.5.0

1 release file

2.4.0

1 release file

2.3.0

1 release file

2.2.0

1 release file

2.1.1

1 release file

2.1.0

1 release file

2.0.1

1 release file

2.0.0

1 release file

This release

1.2.0 This release

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page