예제 #1
0
 def get_queryset(self):
     queryset = sensitivity_models.SensitiveArea.objects.existing() \
         .filter(published=True) \
         .select_related('species', 'structure') \
         .prefetch_related('species__practices') \
         .annotate(geom_type=GeometryType(F('geom')))
     if 'bubble' in self.request.GET:
         queryset = queryset.annotate(
             geom_transformed=Transform(F('geom'), settings.API_SRID))
     else:
         queryset = queryset.annotate(geom_transformed=Case(
             When(geom_type='POINT',
                  then=Transform(Buffer(F('geom'), F('species__radius'), 4),
                                 settings.API_SRID)),
             When(geom_type='POLYGON',
                  then=Transform(F('geom'), settings.API_SRID)),
             When(geom_type='MULTIPOLYGON',
                  then=Transform(F('geom'), settings.API_SRID)),
         ))
     # Ensure smaller areas are at the end of the list, ie above bigger areas on the map
     # to ensure we can select every area in case of overlapping
     # Second sort key pk is required for reliable pagination
     queryset = queryset.annotate(area=Area('geom_transformed')).order_by(
         '-area', 'pk')
     return queryset
예제 #2
0
 def get_queryset(self):
     queryset = sensitivity_models.SensitiveArea.objects.existing() \
         .filter(published=True) \
         .select_related('species', 'structure') \
         .prefetch_related('species__practices') \
         .annotate(geom_type=GeometryType(F('geom')))
     if 'bubble' in self.request.GET:
         queryset = queryset.annotate(geom2d_transformed=Transform(F('geom'), settings.API_SRID))
     else:
         queryset = queryset.annotate(geom2d_transformed=Case(
             When(geom_type='POINT', then=Transform(Buffer(F('geom'), F('species__radius'), 4), settings.API_SRID)),
             When(geom_type='POLYGON', then=Transform(F('geom'), settings.API_SRID))
         ))
     return queryset
예제 #3
0
    def get_queryset(self):
        qs = SensitiveArea.objects.existing()
        qs = qs.filter(published=True)
        qs = qs.prefetch_related('species')
        qs = qs.annotate(geom_type=GeometryType(F('geom')))
        qs = qs.annotate(geom2d_transformed=Case(
            When(geom_type='POINT',
                 then=Transform(Buffer(F('geom'), F('species__radius'), 4),
                                settings.API_SRID)),
            When(geom_type='POLYGON',
                 then=Transform(F('geom'), settings.API_SRID))))

        if 'practices' in self.request.GET:
            qs = qs.filter(species__practices__name__in=self.request.
                           GET['practices'].split(','))

        return qs
예제 #4
0
    def get_queryset(self):
        qs = SensitiveArea.objects.existing()
        qs = qs.filter(published=True)
        qs = qs.prefetch_related('species')
        qs = qs.annotate(geom_type=GeometryType(F('geom')))
        qs = qs.annotate(geom2d_transformed=Case(
            When(geom_type='POINT', then=Transform(Buffer(F('geom'), F('species__radius'), 4), settings.API_SRID)),
            When(geom_type__in=('POLYGON', 'MULTIPOLYGON'), then=Transform(F('geom'), settings.API_SRID))
        ))
        # Ensure smaller areas are at the end of the list, ie above bigger areas on the map
        # to ensure we can select every area in case of overlapping
        qs = qs.annotate(area=Area('geom2d_transformed')).order_by('-area')

        if 'practices' in self.request.GET:
            qs = qs.filter(species__practices__name__in=self.request.GET['practices'].split(','))

        return qs
예제 #5
0
        def get_queryset(self):
            pk = self.kwargs['pk']
            dive = get_object_or_404(Dive.objects.existing(), pk=pk)
            if not dive.is_public:
                raise Http404
            qs = dive.published_sensitive_areas
            qs = qs.prefetch_related('species')
            qs = qs.annotate(geom_type=GeometryType(F('geom')))
            qs = qs.annotate(geom2d_transformed=Case(
                When(geom_type='POINT', then=Transform(Buffer(F('geom'), F('species__radius'), 4), settings.API_SRID)),
                When(geom_type='POLYGON', then=Transform(F('geom'), settings.API_SRID))
            ))
            # Ensure smaller areas are at the end of the list, ie above bigger areas on the map
            # to ensure we can select every area in case of overlapping
            qs = qs.annotate(area=Area('geom2d_transformed')).order_by('-area')

            if 'practices' in self.request.GET:
                qs = qs.filter(species__practices__name__in=self.request.GET['practices'].split(','))

            return qs
예제 #6
0
    def get_queryset(self):
        pk = self.kwargs['pk']
        try:
            trek = Trek.objects.existing().get(pk=pk)
        except Trek.DoesNotExist:
            raise Http404
        if not trek.is_public:
            raise Http404
        qs = trek.published_sensitive_areas
        qs = qs.prefetch_related('species')
        qs = qs.annotate(geom_type=GeometryType(F('geom')))
        qs = qs.annotate(geom2d_transformed=Case(
            When(geom_type='POINT',
                 then=Transform(Buffer(F('geom'), F('species__radius'), 4),
                                settings.API_SRID)),
            When(geom_type='POLYGON',
                 then=Transform(F('geom'), settings.API_SRID))))

        if 'practices' in self.request.GET:
            qs = qs.filter(species__practices__name__in=self.request.
                           GET['practices'].split(','))

        return qs