django-vectortiles icon indicating copy to clipboard operation
django-vectortiles copied to clipboard

Multiple table model in MVTView

Open jeyasurya520 opened this issue 1 year ago • 10 comments

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

jeyasurya520 avatar Sep 06 '23 05:09 jeyasurya520

Please share some more information. It is difficult to imagine what you are trying to accomplish.

  1. Are you trying to combine multiple querysets?
  2. How do your models look like?
  3. How does your current implementation look like?
  4. What does not work with your current implementation?

StefanBrand avatar Sep 06 '23 08:09 StefanBrand

  1. Yes i'm trying to combine multiple querysets.
  2. 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" 

jeyasurya520 avatar Sep 07 '23 06:09 jeyasurya520

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.

StefanBrand avatar Sep 07 '23 08:09 StefanBrand

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)

submarcos avatar Sep 14 '23 11:09 submarcos

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 avatar Nov 28 '23 10:11 jeyasurya520

@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 ?

submarcos avatar Nov 28 '23 13:11 submarcos

https://epsg.io/3857

Your point is out of EPSG 3857 bounds

submarcos avatar Nov 28 '23 13:11 submarcos

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.

StefanBrand avatar Nov 28 '23 13:11 StefanBrand

@submarcos Is Multiple layers (and models) per tile functionality available in master?

kannan-ts avatar Nov 29 '23 07:11 kannan-ts

@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

submarcos avatar Feb 08 '24 15:02 submarcos