Vote count:
0
I'm trying to import a KML file into an existing Django database. I'd like to do this as a Django management command so it's easy to re-do.
This is my Django model, nice and simple:
class PCT(models.Model):
code = models.CharField(max_length=3, primary_key=True)
boundary = models.MultiPolygonField(null=True, blank=True)
objects = models.GeoManager()
And this is my code:
filename = 'myfile.KML'
ds = DataSource(filename)
lyr = ds[0]
for feat in lyr:
code = feat.get('NAME')
geom = feat.geom
print(geom.wkt)[:15]
But when I run it I get this error:
TypeError: Cannot set PCT GeometryProxy (MULTIPOLYGON) with value of type:
<class 'django.contrib.gis.gdal.geometries.Polygon'>
Looking at the KML file, the problem seems to be that some of the features are MultiPolygon and some are Polygon.
How can I deal this with? At the moment I'm wondering if I should have two separate fields (not ideal), or if I can convert the Polygons into MultiPolygons somehow.
asked 30 secs ago
Import KML file into GeoDjango: field can be Polygon or MultiPolygon?
Aucun commentaire:
Enregistrer un commentaire