girder / django-large-image

🩻 🗺️ Django endpoints for working with large images for tile serving
Apache License 2.0
61 stars 3 forks source link

django-raster demo #28

Closed banesullivan closed 2 years ago

banesullivan commented 2 years ago

Show how django-large-image can be used with django-raster

banesullivan commented 2 years ago

I've put together a demo here: https://github.com/ResonantGeoData/django-raster-demo

At it's core, it is as simple as:

from raster.models import RasterLayer
from rest_framework import mixins, serializers, viewsets

from django_large_image.rest import LargeImageDetailMixin
from django_large_image.utilities import make_vsi

def get_raster_layer_path(instance: RasterLayer):
    if instance.rasterfile:
        return instance.rasterfile.name
    if instance.source_url:
        return make_vsi(instance.source_url)

class RasterLayerSerializer(serializers.ModelSerializer):
    class Meta:
        model = RasterLayer
        fields = '__all__'

class DjangoRasterViewSet(
    mixins.ListModelMixin,
    viewsets.GenericViewSet,
    LargeImageDetailMixin,
):
    queryset = RasterLayer.objects.all()
    serializer_class = RasterLayer

    def get_path(self, request, pk=None):
        object = self.get_object()
        return get_raster_layer_path(object)
banesullivan commented 2 years ago

@yellowcap, would you be interested in learning more about this or helping us combine the two apps to solve a wider set of geospatial raster and tiling needs?