Skip to content

Bbox behavior different from spec #125

Closed
@bordax

Description

@bordax

Current Behavior

When we initialize any GeoJson type without passing a bbox, it's setted to null.

from geojson_pydantic import FeatureCollection
from pprint import pprint

fc = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": "",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [-37.33175659179676, -9.424103736877383],
                        [-37.31844711303711, -9.420578002929688],
                        [-37.26972198486328, -9.45348930358881],
                        [-37.3108024597168, -9.467284202575684],
                        [-37.33392715454096, -9.487695693969727],
                        [-37.37298583984375, -9.524782180786133],
                        [-37.4452285766601, -9.476631164550724],
                        [-37.44975662231445, -9.453315734863281],
                        [-37.33175659179676, -9.424103736877383],
                    ]
                ],
            },
        }
    ],
}
fc = FeatureCollection(**fc)
pprint(fc.dict())

Will print

{'bbox': None,
 'features': [{'bbox': None,
               'geometry': {'bbox': None,
                            'coordinates': [[(-37.33175659179676,
                                              -9.424103736877383),
                                             (-37.31844711303711,
                                              -9.420578002929688),
                                             (-37.26972198486328,
                                              -9.45348930358881),
                                             (-37.3108024597168,
                                              -9.467284202575684),
                                             (-37.33392715454096,
                                              -9.487695693969727),
                                             (-37.37298583984375,
                                              -9.524782180786133),
                                             (-37.4452285766601,
                                              -9.476631164550724),
                                             (-37.44975662231445,
                                              -9.453315734863281),
                                             (-37.33175659179676,
                                              -9.424103736877383)]],
                            'type': 'Polygon'},
               'id': None,
               'properties': {},
               'type': 'Feature'}],
 'type': 'FeatureCollection'}

Expected Behavior

From the standard, at the definition of a GeoJSON Object:

GeoJSON Object

A GeoJSON object represents a Geometry, Feature, or collection of Features.
A GeoJSON object is a JSON object.
A GeoJSON object has a member with the name "type". The value of the member MUST be one of the GeoJSON types.
A GeoJSON object MAY have a "bbox" member, the value of which MUST be a bounding box array (see Section 5).

Then, from the section on bounding boxes:

  1. Bounding Box

    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.

In other words, when passing no bbox, the parsed geometry should contain no bbox fields.

{
 'features': [{
               'geometry': {
                            'coordinates': [[(-37.33175659179676,
                                              -9.424103736877383),
                                             (-37.31844711303711,
                                              -9.420578002929688),
                                             (-37.26972198486328,
                                              -9.45348930358881),
                                             (-37.3108024597168,
                                              -9.467284202575684),
                                             (-37.33392715454096,
                                              -9.487695693969727),
                                             (-37.37298583984375,
                                              -9.524782180786133),
                                             (-37.4452285766601,
                                              -9.476631164550724),
                                             (-37.44975662231445,
                                              -9.453315734863281),
                                             (-37.33175659179676,
                                              -9.424103736877383)]],
                            'type': 'Polygon'},
               'id': None,
               'properties': {},
               'type': 'Feature'}],
 'type': 'FeatureCollection'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions