I need import in my app geo files .kml, .kmz o .shp. How do that in django. Thanks
from django.contrib.gis.geos import GeometryCollection, GEOSGeometry
import json
def load_shape(shape_file_path):
with open(shape_file_path, "r") as shape_file:
jsn = json.load(shape_file)
geometries = [
GEOSGeometry(json.dumps(feature.get('geometry')))
for feature in jsn.get('features')
]
return GeometryCollection(tuple(geometries), srid=4326)
This is what I’ve used with geojson files. YMMV, or if you’re lucky you might even be able to simplify it.