Skip to content
Snippets Groups Projects
geojson_format.py 478 B
Newer Older
  • Learn to ignore specific revisions
  • Jesper Zedlitz's avatar
    Jesper Zedlitz committed
    
    
    def is_valid(resource, file):
        """Check if the content is a readable GeoJSON file."""
    
        with open(file.name, "rb") as f:
            try:
    
                geojson_data = geojson.load(f)
                if isinstance(geojson_data, dict) and "type" in geojson_data:
                    return True
                else:
                    resource["error"] = "JSON is not GeoJSON."
                    return False
            except Exception as e:
                resource["error"] = str(e)