All Projects → submarcos → django-vectortiles

submarcos / django-vectortiles

Licence: other
Mapbox VectorTiles for django, with PostGIS or Python

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to django-vectortiles

cloud-tileserver
Serve mapbox vectortiles via AWS stack
Stars: ✭ 48 (+118.18%)
Mutual labels:  postgis, mapbox-vector-tile
tilenol
Scalable, multi-backend geo vector tile server
Stars: ✭ 16 (-27.27%)
Mutual labels:  postgis, mapbox-vector-tile
Baremaps
Custom vector tiles from OpenStreetMap and other data sources.
Stars: ✭ 100 (+354.55%)
Mutual labels:  postgis
ui
PostgreSQL Editor and Dashboard
Stars: ✭ 128 (+481.82%)
Mutual labels:  postgis
Php Crud Api
Single file PHP script that adds a REST API to a SQL database
Stars: ✭ 2,904 (+13100%)
Mutual labels:  postgis
Knex Postgis
postgis extension for knex
Stars: ✭ 142 (+545.45%)
Mutual labels:  postgis
311-data
Empowering Neighborhood Associations to improve the analysis of their initiatives using 311 data
Stars: ✭ 48 (+118.18%)
Mutual labels:  postgis
Python Postgis
PostGIS helpers for psycopg2 and asyncpg
Stars: ✭ 59 (+168.18%)
Mutual labels:  postgis
osmot
Preprocessor for make public transit maps from Openstreetmap data
Stars: ✭ 14 (-36.36%)
Mutual labels:  postgis
Mobilitydb
MobilityDB is a geospatial trajectory data management & analysis platform, built on PostgreSQL and PostGIS.
Stars: ✭ 229 (+940.91%)
Mutual labels:  postgis
QWAT
TEKSI Water module (project QWAT) - QGIS project
Stars: ✭ 52 (+136.36%)
Mutual labels:  postgis
Cartodb
Location Intelligence & Data Visualization tool
Stars: ✭ 2,537 (+11431.82%)
Mutual labels:  postgis
Mapwarper
free open source public map georeferencer, georectifier and warper
Stars: ✭ 152 (+590.91%)
Mutual labels:  postgis
parse-hipaa
HIPAA & GDPR compliant ready parse-server with postgres/mongo, parse-hipaa-dashboard. Compatible with ParseCareKit
Stars: ✭ 74 (+236.36%)
Mutual labels:  postgis
Terrain Classic
World-wide CartoCSS port of Stamen's classic terrain style
Stars: ✭ 110 (+400%)
Mutual labels:  postgis
tilekiln
No description or website provided.
Stars: ✭ 3 (-86.36%)
Mutual labels:  postgis
Geotools
Official GeoTools repository
Stars: ✭ 1,109 (+4940.91%)
Mutual labels:  postgis
Docker Osm
A docker compose project to setup an OSM PostGIS database with automatic updates from OSM periodically
Stars: ✭ 172 (+681.82%)
Mutual labels:  postgis
Atlas Of Thrones
An interactive "Game of Thrones" map powered by Leaflet, PostGIS, and Redis.
Stars: ✭ 253 (+1050%)
Mutual labels:  postgis
GeoNature
Application de saisie et de synthèse des observations faune et flore
Stars: ✭ 81 (+268.18%)
Mutual labels:  postgis

Tests Coverage

Python Version Django Version

Generate MapBox VectorTiles from GeoDjango models

Directly with PostgreSQL/PostGIS 2.4+ or python native mapbox_vector_tile

Read full documentation

Installation

Basic

pip install django-vectortiles
  • Without any other option, use only vectortiles.postgis
  • Ensure you have psycopg2 set and installed

If you don't want to use Postgis

pip install django-vectortiles[mapbox]
  • This will incude mapbox_vector_tiles package and its dependencies
  • Use only vectortiles.mapbox

Examples

  • assuming you have django.contrib.gis in your INSTALLED_APPS and a gis compatible database backend
# in your app models.py

from django.contrib.gis.db import models


class Layer(models.Model):
    name = models.CharField(max_length=250)


class Feature(models.Model):
    geom = models.GeometryField(srid=4326)
    name = models.CharField(max_length=250)
    layer = models.ForeignKey(Layer, on_delete=models.CASCADE, related_name='features')

Simple model:

# in your view file

from django.views.generic import ListView
from vectortiles.postgis.views import MVTView
from yourapp.models import Feature


class FeatureTileView(MVTView, ListView):
    model = Feature
    vector_tile_layer_name = "features"
    vector_tile_fields = ('other_field_to_include', )


# in your urls file
from django.urls import path
from yourapp import views


urlpatterns = [
    ...
    path('tiles/<int:z>/<int:x>/<int:y>', views.FeatureTileView.as_view(), name="feature-tile"),
    ...
]

Related model:

# in your view file

from django.views.generic import DetailView
from vectortiles.mixins import BaseVectorTileView
from vectortiles.postgis.views import MVTView
from yourapp.models import Layer


class LayerTileView(MVTView, DetailView):
    model = Layer
    vector_tile_fields = ('other_field_to_include', )

    def get_vector_tile_layer_name(self):
        return self.get_object().name

    def get_vector_tile_queryset(self):
        return self.get_object().features.all()

    def get(self, request, *args, **kwargs):
        self.object = self.get_object()
        return BaseVectorTileView.get(self,request=request, z=kwargs.get('z'), x=kwargs.get('x'), y=kwargs.get('y'))


# in your urls file
from django.urls import path
from yourapp import views


urlpatterns = [
    ...
    path('layer/<int:pk>/tile/<int:z>/<int:x>/<int:y>', views.LayerTileView.as_view(), name="layer-tile"),
    ...
]

Usage without PostgreSQL / PostGIS

Just import and use vectortiles.mapbox.view.MVTView instead of vectortiles.postgis.view.MVTView

Usage with DRF

django-vectortiles can be used with DRF if renderer_classes of the view is overridden (see DRF docs). Simply use the right BaseMixin and action on viewsets, or directly a GET method in an APIView, i.e.:

from rest_framework import renderers, views
from vectortiles.postgis.views import MVTView


class MVTRenderer(renderers.BaseRenderer):
    media_type = "application/vnd.mapbox-vector-tile"
    format = "pbf"

    def render(self, data, accepted_media_type=None, renderer_context=None):
        return data


class TileServerView(MVTView, views.APIView):
    renderer_classes = [MVTRenderer]

    def get(...): ...

Development

With docker and docker-compose
docker pull makinacorpus/geodjango:bionic-3.6
docker-compose build
# docker-compose up
docker-compose run /code/venv/bin/python ./manage.py test
Local
  • Install python and django requirements (python 3.6+, django 2.2+)
  • Install geodjango requirements
  • Have a postgresql / postgis 2.4+ enabled database
  • Use a virtualenv
pip install .[dev] -U
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].