3👍
You can use DataSource
to read a KML file, and extract geoms from it:
from django.contrib.gis.gdal.datasource import DataSource
ds = DataSource("data.kml")
geoms = ds[0].get_geoms(geos=True)
However, this does not work with your KML above since the polygons are not closed properly (This might be OK with KML, but not with GEOS. Removing geos=True
will load it as GDAL geometries correctly). Try some other KML examples here.
Style info is lost with DataSource. You might be able to extract it using libkml or lxml.
If your data contains a mixture of points, lines and polygons, consider using a GeometryCollection
field instead of a MultiPolygon
field.
👤Udi
Source:stackexchange.com