Skip to content

Commit

Permalink
Merge pull request #173 from empowerplan/feature/fix_mvt_clipping
Browse files Browse the repository at this point in the history
Fix MVT clipping
  • Loading branch information
nesnoj authored Nov 25, 2024
2 parents f27388a + bd6c057 commit 41d84b6
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 8 deletions.
3 changes: 2 additions & 1 deletion digiplan/map/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ def _filter_query( # noqa: PLR0913
def _get_mvt_geom_query(self, x: int, y: int, z: int) -> django.db.models.QuerySet:
"""Intersect bbox from given coordinates and return related MVT."""
bbox = Polygon.from_bbox(tile_edges(x, y, z))
# Build bbox with same projection as geometry in model
bbox.srid = 4326
query = self.annotate(
mvt_geom=AsMVTGeom(Transform(self.geo_col, 3857), Transform(bbox, 3857), 4096, 0, False), # noqa: FBT003
mvt_geom=AsMVTGeom(self.geo_col, Transform(bbox, 3857), 4096, 256, True), # noqa: FBT003
)
intersect = {f"{self.geo_col}__intersects": bbox}
return query.filter(**intersect)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
# Generated by Django 4.2.16 on 2024-11-25 10:49

import django.contrib.gis.db.models.fields
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("map", "0054_pvgroundcriteriamerged"),
]

operations = [
migrations.AlterField(
model_name="airtraffic",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="biomass",
name="geom",
field=django.contrib.gis.db.models.fields.PointField(srid=3857),
),
migrations.AlterField(
model_name="biospherereserve",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="combustion",
name="geom",
field=django.contrib.gis.db.models.fields.PointField(srid=3857),
),
migrations.AlterField(
model_name="drinkingwaterarea",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="faunaflorahabitat",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="floodplain",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="forest",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="grid",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="gsgk",
name="geom",
field=django.contrib.gis.db.models.fields.PointField(srid=3857),
),
migrations.AlterField(
model_name="hydro",
name="geom",
field=django.contrib.gis.db.models.fields.PointField(srid=3857),
),
migrations.AlterField(
model_name="industry",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="landscapeprotectionarea",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="lessfavouredareasagricultural",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="military",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="moor",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="municipality",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="natureconservationarea",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="naturepark",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="potentialareapvgroundpermanentcrops",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="potentialareapvgroundsoilqualitylow",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="potentialareapvgroundsoilqualitymedium",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="potentialareapvroof",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="potentialareawindstp2018eg",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="potentialareawindstp2024vr",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="priorityclimateresistentagri",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="prioritygrassland",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="prioritypermanentcrops",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="pvground",
name="geom",
field=django.contrib.gis.db.models.fields.PointField(srid=3857),
),
migrations.AlterField(
model_name="pvgroundareasapproved",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="pvgroundareasoperating",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="pvgroundareasplanned",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="pvgroundcriteriaaviation",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="pvgroundcriteriabiotope",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="pvgroundcriteriamerged",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="pvgroundcriterianaturemonuments",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="pvgroundcriteriaopenspaces",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="pvgroundcriteriasettlements",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="pvgroundcriteriasettlements200m",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="pvroof",
name="geom",
field=django.contrib.gis.db.models.fields.PointField(srid=3857),
),
migrations.AlterField(
model_name="railway",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="regionboundaries",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="road",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="specialprotectionarea",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="storage",
name="geom",
field=django.contrib.gis.db.models.fields.PointField(srid=3857),
),
migrations.AlterField(
model_name="waterbodies",
name="geom",
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
migrations.AlterField(
model_name="waterfirstorder",
name="geom",
field=django.contrib.gis.db.models.fields.MultiLineStringField(srid=3857),
),
migrations.AlterField(
model_name="windturbine",
name="geom",
field=django.contrib.gis.db.models.fields.PointField(srid=3857),
),
migrations.AlterField(
model_name="windturbine2approved",
name="geom",
field=django.contrib.gis.db.models.fields.PointField(srid=3857),
),
migrations.AlterField(
model_name="windturbine2operating",
name="geom",
field=django.contrib.gis.db.models.fields.PointField(srid=3857),
),
migrations.AlterField(
model_name="windturbine2planned",
name="geom",
field=django.contrib.gis.db.models.fields.PointField(srid=3857),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
class Migration(migrations.Migration):

dependencies = [
('map', '0054_pvgroundcriteriamerged'),
('map', '0055_alter_airtraffic_geom_alter_biomass_geom_and_more'),
]

operations = [
migrations.AlterField(
model_name='waterfirstorder',
name='geom',
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=4326),
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857),
),
]
10 changes: 5 additions & 5 deletions digiplan/map/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Meta: # noqa: D106
class Municipality(models.Model):
"""Model for region level municipality."""

geom = models.MultiPolygonField(srid=4326)
geom = models.MultiPolygonField(srid=3857)
name = models.CharField(max_length=50, unique=True)
area = models.FloatField()

Expand Down Expand Up @@ -101,7 +101,7 @@ def quantity_per_municipality_per_year(cls) -> pd.DataFrame:
class RegionBoundaries(models.Model):
"""Region Boundaries model."""

geom = models.MultiPolygonField(srid=4326)
geom = models.MultiPolygonField(srid=3857)

objects = models.Manager()
vector_tiles = StaticMVTManager(columns=[])
Expand All @@ -118,7 +118,7 @@ class Meta: # noqa: D106
class RenewableModel(models.Model):
"""Base class for renewable cluster models."""

geom = models.PointField(srid=4326)
geom = models.PointField(srid=3857)
name = models.CharField(max_length=255, null=True)
geometry_approximated = models.BooleanField()
unit_count = models.BigIntegerField(null=True)
Expand Down Expand Up @@ -525,7 +525,7 @@ class Meta: # noqa: D106
class StaticRegionModel(models.Model):
"""Base class for static region models."""

geom = models.MultiPolygonField(srid=4326)
geom = models.MultiPolygonField(srid=3857)

objects = models.Manager()
vector_tiles = StaticMVTManager(columns=[])
Expand Down Expand Up @@ -789,7 +789,7 @@ class WindTurbine2(models.Model):
hub_height = models.FloatField(null=True)
rotor_diameter = models.FloatField(null=True)
status = models.CharField(max_length=50, null=True)
geom = models.PointField(srid=4326)
geom = models.PointField(srid=3857)

mun_id = models.ForeignKey(Municipality, on_delete=models.DO_NOTHING, null=True)

Expand Down

0 comments on commit 41d84b6

Please sign in to comment.