У меня есть модель многоугольника GeoDjango, как показано ниже
class PolygonFeature(models.Model):
shapefile = models.ForeignKey(Shapefile,
on_delete=models.CASCADE, related_name='polygon_shp')
geom = models.PolygonField(srid=4326, blank=True, null=True)
def __str__(self):
return str(self.shapefile.filename) + "-" + str(self.pk)
Я добавляю полигон к модели через LayerMapping, в котором out - это шейп-файл
mapping = {
'shapefile':{'id':'survey_pk'},
'geom': geom,
}
lm = LayerMapping(model, out, mapping, transform=transform, encoding='iso-8859-1')
lm.save(verbose=False)
Мне нужно изменить точность координат, покасериализация геометрии объекта полигона в GeoJSOn
feat = PolygonFeature.objects.filter(shapefile=obj)
json_obj = serialize('geojson', feat)
текущий
{
"type": "FeatureCollection",
"crs": {
"type": "name",
"name": "EPSG:4326"
},
"features": [
{
"type": "Feature",
"properties": {
"shapefile": 53,
"pk": "45269"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
75.6083423241,
31.315054275
],
[
75.5543398801,
31.30543373742
],
[
75.5970812345,
31.2980635331
],
[
75.6543504465,
31.30345354185
],
[
75.6035348241,
31.315035375
]
]
]
}
}
]
}