Skip to content

sentido/django-geojson

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-geojson

INSTALL

pip install django-geojson

USAGE

Add djgeojson to your applications :

# settings.py

INSTALLED_APPS += (
    'djgeojson',
)

(not required for views)

GeoJSON layer view

Very useful for web mapping :

from djgeojson.views import GeoJSONLayerView


class MeetingLayer(GeoJSONLayerView):
    model = Meeting
    fields = ('title', 'datetime',)
    # Options
    srid = 4326     # projection
    precision = 4   # float
    simplify = 0.5  # generalization

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

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

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

  • Mathieu Leplatre <[email protected]>
  • Daniel Sokolowski, author of original serializer snippet
  • ozzmo, python 2.6 compatibility

Relies massively on Sean Gillies' geojson python module.

makinacom

LICENSE

  • Lesser GNU Public License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%