{"id":18045117,"url":"https://github.com/submarcos/django-vectortiles","last_synced_at":"2025-04-05T08:06:09.503Z","repository":{"id":40267753,"uuid":"305703767","full_name":"submarcos/django-vectortiles","owner":"submarcos","description":"Mapbox VectorTiles for django, with PostGIS or Python","archived":false,"fork":false,"pushed_at":"2024-11-04T16:02:00.000Z","size":219,"stargazers_count":45,"open_issues_count":11,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T07:07:34.836Z","etag":null,"topics":["django","django-vectortiles","mapbox-vector-tile","mapbox-vectortiles","maplibre","postgis","python","vectortiles"],"latest_commit_sha":null,"homepage":"https://django-vectortiles.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/submarcos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://www.paypal.com/paypalme/jecasta"}},"created_at":"2020-10-20T12:40:52.000Z","updated_at":"2025-03-28T16:52:03.000Z","dependencies_parsed_at":"2024-10-19T08:23:12.371Z","dependency_job_id":"61bb8923-0abe-4922-aab4-ba9580edfa13","html_url":"https://github.com/submarcos/django-vectortiles","commit_stats":{"total_commits":96,"total_committers":4,"mean_commits":24.0,"dds":0.25,"last_synced_commit":"86f00879a27a0c5aaf1eebad6448ca27993a3d13"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/submarcos%2Fdjango-vectortiles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/submarcos%2Fdjango-vectortiles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/submarcos%2Fdjango-vectortiles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/submarcos%2Fdjango-vectortiles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/submarcos","download_url":"https://codeload.github.com/submarcos/django-vectortiles/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305933,"owners_count":20917208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-vectortiles","mapbox-vector-tile","mapbox-vectortiles","maplibre","postgis","python","vectortiles"],"created_at":"2024-10-30T18:12:09.293Z","updated_at":"2025-04-05T08:06:09.479Z","avatar_url":"https://github.com/submarcos.png","language":"Python","funding_links":["https://www.paypal.com/paypalme/jecasta"],"categories":[],"sub_categories":[],"readme":"![Tests](https://github.com/submarcos/django-vectortiles/workflows/Unit%20tests/badge.svg)\n[![Coverage](https://codecov.io/gh/submarcos/django-vectortiles/branch/master/graph/badge.svg)](https://codecov.io/gh/submarcos/django-vectortiles)\n![Python Version](https://img.shields.io/badge/python-%3E%3D%203.8-blue.svg)\n![Django Version](https://img.shields.io/badge/django-%3E%3D%204.2-blue.svg)\n\n# Generate MapBox VectorTiles from GeoDjango models\n![image](https://github.com/user-attachments/assets/46d5b475-c5c1-48b2-959d-9689968fdfef)\n\n## Directly with PostgreSQL/PostGIS 2.4+ or python native mapbox_vector_tile\n\n## [Read full documentation](https://django-vectortiles.readthedocs.io/)\n\n### Installation\n\n#### Basic\n```bash\npip install django-vectortiles\n```\n\n* By default, postgis backend is enabled.\n* Ensure you have psycopg installed\n\n#### If you don't want to use Postgis and / or PostgreSQL\n```bash\npip install django-vectortiles[python]\n```\n* This will include mapbox_vector_tiles package and its dependencies\n* Set ```VECTOR_TILES_BACKEND=\"vectortiles.backends.python\"``` in your project settings.\n\n### Examples\n\nLet's create vector tiles with your city geometries.\n\n* assuming you have ```django.contrib.gis``` in your ```INSTALLED_APPS``` and a gis compatible database backend\n\n```python\n# in your app models.py\n\nfrom django.contrib.gis.db import models\n\n\nclass City(models.Model):\n    name = models.CharField(max_length=250)\n    city_code = models.CharField(max_length=10, unique=True)\n    population = models.IntegerField(default=0)\n    geom = models.MultiPolygonField(srid=4326)\n```\n\n\n#### Simple Example:\n\n```python\nfrom yourapp.models import City\n\n# in a vector_layers.py file\nfrom vectortiles import VectorLayer\n\n\nclass CityVL(VectorLayer):\n    model = City\n    id = \"cities\"  # layer id / name in tile\n    tile_fields = (\"name\", \"city_code\")  # add name and city_code properties in each tile feature\n    min_zoom = 9  # don't embed city borders at low zoom levels\n\n# in your view file\n\nfrom yourapp.vector_layers import CityVL\n\nfrom vectortiles.views import MVTView\n\n\nclass CityTileView(MVTView):\n    layer_classes = [CityVL]\n\n\n# in your urls file\nfrom django.urls import path\nfrom yourapp import views\n\nurlpatterns = [\n    ...\n    CityTileView.get_url(),  # serve tiles at default /tiles/\u003cint:z\u003e/\u003cint:x\u003e/\u003cint:y\u003e. You can override url prefix and tile scheme in class attributes.\n    ...\n]\n```\n#### Example with multiple layers\n\nSuppose you want to make a map with your city borders, and a point in each city center that shows a popup with city name, population an area.\n\n```python\nfrom django.contrib.gis.db.models.functions import Centroid, Area\nfrom yourapp.models import City\n\n# in a vector_layers.py file\nfrom vectortiles import VectorLayer\n\n\nclass CityVectorLayer(VectorLayer):\n    model = City\n    id = \"cities\"\n    tile_fields = ('city_code', \"name\")\n    min_zoom = 10\n\n    \nclass CityCentroidVectorLayer(VectorLayer):\n    queryset = City.objects.annotate(\n        centroid=Centroid(\"geom\"), # compute the city centroïd\n        area=Area(\"geom\"), # compute the city area\n    )  \n    geom_field = \"centroid\"  # use the centroid field as geometry feature\n    id = \"city_centroïds\"\n    tile_fields = ('name', 'city_code', 'area', 'population')  # add area and population properties in each tile feature\n    min_zoom = 7  # let's show city name at zoom 7\n\n\n    \n# in your view file\n\nfrom yourapp.vector_layers import CityVectorLayer, CityCentroidVectorLayer\n\nfrom vectortiles.views import MVTView\n\n\nclass CityTileView(MVTView):\n    layer_classes = [CityVectorLayer, CityCentroidVectorLayer]\n\n\n# in your urls file\nfrom yourapp import views\n\nurlpatterns = [\n    ...\n    views.CityTileView.get_url(),  # serve tiles at default /tiles/\u003cint:z\u003e/\u003cint:x\u003e/\u003cint:y\u003e\n    ...\n]\n```\n\nNow, any tile requested at http://you_url/tiles/{z}/{x}/{y} that intersects a city will return a vector tile with two layers, `cities` with border geometries and `city_code` property, and `city_centroïds` with center geometry and `city_name` property.\n![image](https://github.com/user-attachments/assets/d472639a-db4c-40aa-984a-c68a8e841283)\n\n[Read full documentation](https://django-vectortiles.readthedocs.io/) for examples, as multiple layers, cache policy, mapblibre integration, etc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubmarcos%2Fdjango-vectortiles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsubmarcos%2Fdjango-vectortiles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubmarcos%2Fdjango-vectortiles/lists"}