I'm trying to use MakeValid
to fix (validate) my geometry fields.
I can make it work by getting and updating in single line:
from django.contrib.gis.db.models.functions import MakeValid
MyModel.objects.filter(id=<id>).update(polygon=MakeValid('polygon'))
but for some cases, I have to update polygon
of a single model object already instantiated in a function (meaning I have already done .filter
/.get
) which gives me the following error:
// np is an object of MyModel which has a field 'polygon' which is `MultiPolygon` django model field
np.polygon = MakeValid(np.polygon)
// np.save()
TypeError: Cannot set MyModel SpatialProxy (MULTIPOLYGON) with value of type: <class 'django.contrib.gis.db.models.functions.MakeValid'>
Here, MakeValid(np.polygon)
doesn't return a MultiPolygon
object. Instead, it returns a django.contrib.gis.db.models.functions.MakeValid
wrapper.
Can I get a Geometry object from MakeValid
?