Skip to main content

Django speaking WFS 2.0 (exposing GeoDjango model fields)

Project description

Documentation Actions PyPI MPL License Coverage

django-gisserver

Django speaking WFS 2.0 to expose geo data.

Features

  • WFS 2.0 Basic implementation.
  • GML 3.2 output.
  • Standard and spatial filtering (FES 2.0)
  • GeoJSON and CSV export formats.
  • Extensible view/operations.
  • Uses GeoDjango queries for filtering.
  • Streaming responses for large datasets.

Documentation

For more details, see: https://django-gisserver.readthedocs.io/

Test drive

  • Run docker compose up.
  • Open http://localhost:8000/ to see this works.
  • Connect to http://localhost:8000/wfs/ in your GIS client (e.g. QGis) and zoom to Amsterdam.
  • Add more data on the map using the Django admin, username and password are both "admin".

Quickstart

Install the module in your project:

pip install django-gisserver

Add it to the INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    "gisserver",
]

Create a model that exposes a GeoDjango field:

from django.contrib.gis.db.models import PointField
from django.db import models


class Restaurant(models.Model):
    name = models.CharField(max_length=200)
    location = PointField(null=True)

    def __str__(self):
        return self.name

Write a view that exposes this model as a WFS feature:

from gisserver.crs import CRS, CRS84, WEB_MERCATOR
from gisserver.features import FeatureType, ServiceDescription
from gisserver.views import WFSView
from .models import Restaurant

# As example, the local coordinate system for The Netherlands
RD_NEW = CRS.from_string("urn:ogc:def:crs:EPSG::28992")


class PlacesWFSView(WFSView):
    """An simple view that uses the WFSView against our test model."""

    xml_namespace = "http://example.org/gisserver"

    # The service metadata
    service_description = ServiceDescription(
        title="Places",
        abstract="Unittesting",
        keywords=["django-gisserver"],
        provider_name="Django",
        provider_site="https://www.example.com/",
        contact_person="django-gisserver",
    )

    # Each Django model is listed here as a feature.
    feature_types = [
        FeatureType(
            Restaurant.objects.all(),
            fields="__all__",
            other_crs=[RD_NEW, CRS84, WEB_MERCATOR]
        ),
    ]

Use that view in the URLConf:

from django.urls import path
from . import views

urlpatterns = [
    path("/wfs/places/", views.PlacesWFSView.as_view()),
]

You can now use http://localhost:8000/wfs/places/ in your GIS application. It will perform requests such as:

By adding &OUTPUTFORMAT=geojson or &OUTPUTFORMAT=csv to the GetFeature request, the GeoJSON and CSV outputs are returned. The CSV output has an unlimited page size, as it's quite performant.

Why this code is shared

The "datapunt" team of the Municipality of Amsterdam develops software for the municipality. Much of this software is then published as Open Source so that other municipalities, organizations and citizens can use the software as a basis and inspiration to develop similar software themselves. The Municipality of Amsterdam considers it important that software developed with public money is also publicly available.

This package is initially developed by the City of Amsterdam, but the tools and concepts created in this project can be used in any city.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_gisserver-2.4.0.tar.gz (185.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_gisserver-2.4.0-py3-none-any.whl (206.1 kB view details)

Uploaded Python 3

File details

Details for the file django_gisserver-2.4.0.tar.gz.

File metadata

  • Download URL: django_gisserver-2.4.0.tar.gz
  • Upload date:
  • Size: 185.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_gisserver-2.4.0.tar.gz
Algorithm Hash digest
SHA256 3ce9fc97af631c07e21556140563baed812b0bb1e2b6638c9c6c100b2741b4b7
MD5 ecd43263d15f2fea0873aafd7843a494
BLAKE2b-256 762923e3b274f3f6506a1851f9421dc83ea507259743d14df1ed000b902672a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_gisserver-2.4.0.tar.gz:

Publisher: publish-to-pypi.yml on Amsterdam/django-gisserver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_gisserver-2.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_gisserver-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 083efe521356d9ed51f034b0dbb8910bb2e23bfb312d69b74099ac64afb355bd
MD5 063b1cc2b7e27b9b9c5c29ae2a9284cc
BLAKE2b-256 207bbe860fa287839ce91ab1e0aa92220bb970a197935aa51bb1363fef2096f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_gisserver-2.4.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on Amsterdam/django-gisserver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page