dayjournal memo

Total 975 articles!!

GeoDjango #004 – バウンディングボックスを配信

Yasunori Kirimoto's avatar

画像



バウンディングボックスを配信するメモ。



画像



/app/api/serializers.py

# GeoFeatureModelSerializer読み込み
from rest_framework_gis.serializers import GeoFeatureModelSerializer
# モデル読み込み
from .models import Points, Lines, Polygons

# ポイントシリアライザ
class PointsSerializer(GeoFeatureModelSerializer):
    class Meta:
        model = Points
        # idとnameのみ表示
        fields = ('full_id', 'name')
        # 位置情報カラム指定
        geo_field = 'geom'
        # バウンディングボックスを表示
        auto_bbox = True

# ラインシリアライザ
class LinesSerializer(GeoFeatureModelSerializer):
    class Meta:
        model = Lines
        # idとnameのみ表示
        fields = ('full_id', 'name')
        # 位置情報カラム指定
        geo_field = 'geom'
        # バウンディングボックスを表示
        auto_bbox = True

# ポリゴンシリアライザ
class PolygonsSerializer(GeoFeatureModelSerializer):
    class Meta:
        model = Polygons
        # idとnameのみ表示
        fields = ('full_id', 'name')
        # 位置情報カラム指定
        geo_field = 'geom'
        # バウンディングボックスを表示
        auto_bbox = True


バウンディングボックスを表示

# バウンディングボックスを表示
auto_bbox = True


下記URLで確認

http://127.0.0.1:8000/api/points/100/



GeoDjangoを手軽に始める環境を公開しています。
geodjango-starter



book

Q&A