Welcome friends GeoDjango and GeoJSON serlizer. I followed the official GeoDjango tutorial:
https://docs.djangoproject.com/en/1.8/ref/contrib/gis/tutorial/
So, in the end, I have PostgreSQL + PostGIS, full of countries, them name, their code iso3and so on. And especially their geometry in mpolylike MultiPolygon (stored in wkb). I want to get contingents from a database using GeoDjango. I struggle with that.
I can get the properties of one object one by one:
from django.http import HttpResponse
from django.shortcuts import render
from django.core.serializers import serialize
from AppName.models import WorldBorder
[...]
WorldBorder.objects.filter(name='Germany')[0].name
WorldBorder.objects.filter(name='Germany')[0].iso3
WorldBorder.objects.filter(name='Germany')[0].mpoly.geojson
, , . geojson . Django GeoJSON :
https://docs.djangoproject.com/en/1.8/ref/contrib/gis/serializers/
:
serialize('geojson',
WorldBorder.objects.filter(name='Germany'),
geometry_field='mpoly',
fields=('name',)
)
:
u'{"type": "FeatureCollection", "crs":{"type": "name", "properties": {"name": "EPSG:4326"}},
"features": [{"geometry": null,"type": "Feature",
"properties":{"name": "Germany" }}]}'
, "geometry": null
, , . ? ? ? PostGIS GeoJSON GeoDjango? .
:)