submarcos / django-vectortiles

Mapbox VectorTiles for django, with PostGIS or Python
https://django-vectortiles.readthedocs.io
MIT License
38 stars 11 forks source link

Multiple table model in MVTView #44

Open jeyasurya520 opened 10 months ago

jeyasurya520 commented 10 months ago

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

StefanBrand commented 10 months ago

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?
jeyasurya520 commented 10 months ago
  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" 
StefanBrand commented 10 months ago

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.

submarcos commented 10 months ago

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)

jeyasurya520 commented 7 months ago

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.

submarcos commented 7 months ago

@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 commented 7 months ago

https://epsg.io/3857

Your point is out of EPSG 3857 bounds

StefanBrand commented 7 months ago

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.

kannan-ts commented 7 months ago

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

submarcos commented 5 months ago

@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