TL:DR
我想将 GeoJSON 格式的 GeoServer WFS FeatureCollection 反序列化为GeometryField
/ GeometryCollection
。
让我们从模型开始:
class Layer(models.Model):
name = models.CharField(max_length=50)
layer = GeometryCollectionField(null=True)
和序列化器:
class LayerSerializer(GeoFeatureModelSerializer):
class Meta:
model = Layer
geo_field = 'layer'
fields = ('id', 'name', 'layer')
现在示例 WFS GeoJSON 如下所示:
{
"type": "FeatureCollection",
"totalFeatures": 1,
"features": [
{
"type": "Feature",
"id": "some_id",
"geometry": {
"type": "MultiLineString",
"coordinates": [
[
[4.538638998513776, 50.4674721021459],
[4.5436667765043754, 50.47258379613634],
[4.548444318495443, 50.47744374212726],
...
},
"geometry_name": "the_geom",
"properties": {
...
}
}
],
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
}
}
}
在尝试反序列化上述内容时,出现以下错误:
"layer": [
"Unable to convert to python object:
Invalid geometry pointer returned from \"OGR_G_CreateGeometryFromJson\"."
]
PS:我更喜欢不需要修改 GeoJSON 即可将其转换为 的解决方案(如果存在)GeometryCollection
,因为我已经成功地做到了。