jazzband / geojson

Python bindings and utilities for GeoJSON
https://pypi.python.org/pypi/geojson/
BSD 3-Clause "New" or "Revised" License
913 stars 121 forks source link

[bug] FeatureCollection is valid when it contains any geojson object that is valid #220

Open KS-HTK opened 1 year ago

KS-HTK commented 1 year ago
import geojson

gj = geojson.FeatureCollection([geojson.Point((0, 0))])
print(gj.is_valid)
print(gj.errors())

gj2 = geojson.FeatureCollection([geojson.Point((0, 0), True)])
print(gj2.is_valid)
print(gj2.errors())

gj3 = geojson.FeatureCollection([geojson.FeatureCollection([geojson.Point((0, 0))])])
print(gj3.is_valid)
print(gj3.errors())

All three FeatureCollections above return is_valid as True even though all of them are invalid. The geojson specification section 3.3 states that a FeatureCollections feature list should ONLY contain Features. Point is a geometry and storing those should be done in a GeometryCollection and third is a FeatureCollection that is in its self invalid inside a FeatureCollection. Even if the inside FeatureCollection was valid the outside one should be invalid.

FeatureCollection validation should be revised to cause an error if anything but valid Features are in the feature list.