Skip to content

Commit

Permalink
fixed #43
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Jul 21, 2021
1 parent 5912335 commit 6ea8b7b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
22 changes: 21 additions & 1 deletion archiv/api_serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# API serializers for archiv created by appcreator
from rest_framework import serializers
from rest_framework_gis.serializers import GeoFeatureModelSerializer
from rest_framework_gis.serializers import GeoFeatureModelSerializer, GeometrySerializerMethodField
from archiv.models import (
Autor,
KeyWord,
Expand Down Expand Up @@ -36,6 +36,26 @@ class Meta:
depth = 3


class ConeSerializer(
GeoFeatureModelSerializer, serializers.HyperlinkedModelSerializer
):
cone = GeometrySerializerMethodField()

def get_cone(self, res):
return res.convex_hull

class Meta:
model = SpatialCoverage
geo_field = 'cone'
auto_bbox = False
fields = (
'stelle',
'key_word',
'fuzzyness'
)
depth = 3


class AutorSerializer(serializers.HyperlinkedModelSerializer):

class Meta:
Expand Down
11 changes: 10 additions & 1 deletion archiv/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
StelleSerializer,
TextSerializer,
SpatialCoverageSerializer,
UseCaseSerializer
UseCaseSerializer,
ConeSerializer
)
from archiv.models import (
Autor,
Expand Down Expand Up @@ -48,6 +49,14 @@ class SpatialCoverageViewSet(viewsets.ModelViewSet):
pagination_class = GeoJsonPagination


class ConeViewSet(viewsets.ModelViewSet):
queryset = SpatialCoverage.objects.exclude(fuzzy_geom=None)
serializer_class = ConeSerializer
filter_backends = [django_filters.rest_framework.DjangoFilterBackend]
filter_class = SpatialCoverageListFilter
pagination_class = GeoJsonPagination


class AutorViewSet(viewsets.ModelViewSet):
queryset = Autor.objects.all()
serializer_class = AutorSerializer
Expand Down
1 change: 0 additions & 1 deletion archiv/endpoint_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from archiv.models import KeyWord
from archiv.filters import KeyWordListFilter

from archiv.network_utils import create_graph, graph_table


Expand Down
10 changes: 5 additions & 5 deletions archiv/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# generated by appcreator
from archiv.utils import parse_date
import logging

from django.db import models
Expand All @@ -8,9 +7,9 @@
from django.contrib.gis.db.models import PolygonField
from django.utils.functional import cached_property

from vocabs.models import SkosConcept

from archiv.utils import parse_date
from browsing.browsing_utils import model_to_dict
from vocabs.models import SkosConcept

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -322,9 +321,10 @@ def new_coords(self):
new_coords = poly_cords[:1] + self.get_author_coords() + poly_cords[1:]
return new_coords

@cached_property
def convex_hull(self):
poly = Polygon(self.new_coords())
return poly.convex_hull.geojson
poly = Polygon(self.new_coords()).convex_hull
return poly


class Autor(models.Model):
Expand Down
6 changes: 5 additions & 1 deletion archiv/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# generated by appcreator
from django.conf.urls import url
from . import views
from archiv.endpoint_views import KeyWordEndpoint
Expand Down Expand Up @@ -92,6 +91,11 @@
KeyWordEndpoint.as_view(),
name='keyword_data'
),
url(
r'^cone-data/$',
KeyWordEndpoint.as_view(),
name='keyword_data'
),
url(
r'^keyword/detail/(?P<pk>[0-9]+)$',
views.KeyWordDetailView.as_view(),
Expand Down
1 change: 1 addition & 0 deletions djangobaseproject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
router.register(r'stelle', archiv_api_views.StelleViewSet)
router.register(r'text', archiv_api_views.TextViewSet)
router.register(r'spatialcoverage', archiv_api_views.SpatialCoverageViewSet)
router.register(r'cones', archiv_api_views.ConeViewSet)
router.register(r'usecase', archiv_api_views.UseCaseViewSet)

urlpatterns = [
Expand Down

0 comments on commit 6ea8b7b

Please sign in to comment.