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

FeatureCollection validation #139

Open YuriyRomanyshynUA opened 4 years ago

YuriyRomanyshynUA commented 4 years ago

Hi)

class FeatureCollection(GeoJSON):
   # ...
   def errors(self):
       return self.check_list_errors(lambda x: x.errors(), self.features)
   # ...
   # possible solution
   def errors(self):
      def check(item):
         if isinstance(item, geojson.Feature):
            return item.errors()
         else:
            raise GeoJSONError ...

      return self.check_list_errors(check, self.features)

I think it would be better if first check object type and if it is instance of GeoJSON only then call 'errors' method, if it is not, raise exception with appropriate message, because if you put in collection something different from GeoJSON object you will get a confusing error. For example if you append native dict in collection you will get bewildering:

"AttributeError: 'dict' object has no attribute 'errors'"