django-vectortiles
django-vectortiles copied to clipboard
Multiple table model in MVTView
Is it possible to have multiple table in MVTView model , i'm able to do with a single table but my requirement is to have more than one table in one MVTView model
Please share some more information. It is difficult to imagine what you are trying to accomplish.
- Are you trying to combine multiple querysets?
- How do your models look like?
- How does your current implementation look like?
- What does not work with your current implementation?
- Yes i'm trying to combine multiple querysets.
- Below is my model look like in models.py, but i have more then 100 models
class layer1models.Model): lonx = models.FloatField()
laty = models.FloatField()
geometry = models.GeometryField(blank=True, null=True)
layer=models.CharField(default="ly1",max_length=200,blank=True, null=True)
class layer2(models.Model): lonx = models.FloatField()
laty = models.FloatField()
geometry = models.GeometryField(blank=True, null=True)
layer=models.CharField(default="ly2",max_length=200,blank=True, null=True)
class layer3(models.Model): lonx = models.FloatField()
laty = models.FloatField()
geometry = models.GeometryField(blank=True, null=True)
layer=models.CharField(default="ly3",max_length=200,blank=True, null=True)
3.current implementation look like in views.py
class RunwayMVT(MVTView, APIView):
vector_tile_queryset = Layer1.objects.all() ====> need to combine all models querysets
vector_tile_layer_name = "layer"
vector_tile_fields = ("") ====> need to combine all models fields
vector_tile_geom_name = "geometry"
renderer_classes = (MVTRenderer,)
vector_tile_content_type = "application/x-protobuf"
Union should work to combine querysets: https://docs.djangoproject.com/en/4.2/ref/models/querysets/#union
vector_tile_queryset = Layer1.objects.all().union(Layer2.objects.all(), Layer3.objects.all())
For the fields, you must be attentive to the documentation of Queryset.union
: The first queryset defines the available field names.
Hi @jeyasurya520
Take a look to v1 branch and v1 beta pypi release
Multiple layers (and models) per tile is now possible. You should define VectorLayer instance (one layer in tile) then combine them in MVTView
I am working on test to release 1.0 next
It's working well, juste need to refactor and 100% test coverage (example here)
Hi @submarcos In MVTView api call ,why the coordinates values are changing in feature .
for example :
(views.py )
class Arinc424TileView(MVTView):
layers = [AirportLayer(),VorLayer(),NdbLayer()]
(urls.py )
path('tiles/<int:z>/<int:x>/<int:y>', views.Arinc424TileView.as_view(), name="arinc424chart")
In client side
In database if the coordinates value is [12.564477 , 88.338876] ,but in the client side iam getting coordinates value with some offset value.
@jeyasurya520 offset ? Hum I don't know. Features are transformed in EPSG 3857 by ST_ASMVTGeom postgis function. Transformation can generate offset with unsufficient precision. Can you attach your generated tile ?
https://epsg.io/3857
Your point is out of EPSG 3857 bounds
Indeed, Web Mercator is not defined in the pole regions. In theory, it should be possible to transform geometry and envelope to a polar CRS like WGS 84 / Antarctic Polar Stereographic - EPSG:3031. Currently, we hardcode 3857
:
https://github.com/submarcos/django-vectortiles/blob/a21e571d0165e46a4cea1a81d7dec1ae08c7ce7b/vectortiles/postgis/mixins.py#L23-L31
PS.: I think this should be a new issue.
@submarcos Is Multiple layers (and models) per tile functionality available in master?
@submarcos Is Multiple layers (and models) per tile functionality available in master?
For now, yes it is.
I'm going to fix CI, tests and release in next days