django-rest-framework-gis icon indicating copy to clipboard operation
django-rest-framework-gis copied to clipboard

No bounding box in FeatureCollection

Open azlekov opened this issue 9 years ago • 3 comments

I have following configuration:

class GuideItemSerializer(GeoFeatureModelSerializer):

    class Meta:
        depth = 1
        model = GuideItem
        geo_field = 'point'
        auto_bbox = True
        id_field = False
        fields = ('id', 'name', 'description', 'address', 'city', 'state', 'hours')

I try to fetch and parse this using Android Maps Utils and seems that the parser expects bbox in FeatureCollections but there are bbox in all feature elements but not in the root, take a look here: Snippet

azlekov avatar Mar 30 '16 20:03 azlekov

drf-gis currently does not support adding bbox properties to a FeatureCollection. You may achieve this by extending one of its serializer and adding the custom logic needed to suit your needs. If you publish your solution here more people will be able to see it, use it, improve it and it might be eventually merged.

nemesifier avatar Apr 01 '16 15:04 nemesifier

@nemesisdesign, thanks. I examined drf-gis serializers and I will open pull request soon.

azlekov avatar Apr 02 '16 09:04 azlekov

The bounding box on the feature collection is not implemented correctly in drf-gis. We should fix that.

From the spec: https://tools.ietf.org/html/rfc7946#section-5

A GeoJSON object MAY have a member named "bbox" to include information on the coordinate range for its Geometries, Features, or FeatureCollections. The value of the bbox member MUST be an array of length 2*n where n is the number of dimensions represented in the contained geometries, with all axes of the most southwesterly point followed by all axes of the more northeasterly point. The axes order of a bbox follows the axes order of geometries.

The "bbox" values define shapes with edges that follow lines of constant longitude, latitude, and elevation.

Example of a 2D bbox member on a Feature:

{ "type": "Feature", "bbox": [-10.0, -10.0, 10.0, 10.0], "geometry": { "type": "Polygon", "coordinates": [ [ [-10.0, -10.0], [10.0, -10.0], [10.0, 10.0], [-10.0, -10.0] ] ] } //... }

Example of a 2D bbox member on a FeatureCollection:

{ "type": "FeatureCollection", "bbox": [100.0, 0.0, 105.0, 1.0], "features": [ //... ] }

Example of a 3D bbox member with a depth of 100 meters:

{ "type": "FeatureCollection", "bbox": [100.0, 0.0, -100.0, 105.0, 1.0, 0.0], "features": [ //... ] }

So when the object is a FeatureCollection we should output the bbox only at the FeatureCollection level and not in each feature contained in it.

nemesifier avatar Dec 10 '19 12:12 nemesifier