我想找到一个解决方案DataField
我应该给一个properties
列的geojson。目前,下面的geojson格式不会有任何问题,因为它只需要StringField()
和PointField()
。
geojson格式如下所示:
{
name : "Timmy's Taco Truck",
loc : {
type : "Point",
coordinates : [ 37.7577 , -122.4376 ]
}
}
但是对于这种格式的geojson:
{
"type" : "Feature",
"id" : "ID80001",
"geometry":{"type": "LineString", "coordinates":[[122.332,14.241],[125.332,13.532]]},
"properties":{ "name":"Dummy Name", "color":"#000000" }
}
使用 模型 ,如下所示:
from mongoengine import *
from colorful.fields import RGBColorField
class Geometry(Document):
type = StringField()
id = StringField()
geometry = LineStringField()
name = StringField() color= RGBColorField() ***OR*** properties = ???
如果我使用EmbeddedDocumentField
并创建单独的属性字段,则会产生"properties": [{"name": "Dummy Name","color": "#000000"}]
不
"properties": {"name": "Dummy Name","color": "#000000"}
如何在模型中保留geojson格式?
答案 0 :(得分:1)
mySelectedItem.id
或者,只需使用from mongoengine import *
class Geometry(Document):
type = StringField()
id = StringField()
geometry = LineStringField()
properties = DictField()
g = Geometry()
# Assuming id is unique
g.properties['id'] = {"name": "Dummy Name","color": "#000000"}
g.save()
db.Geometry.findOne()
{
"_id": <some_id>
"properties": {
"<some_id>": {
{"name": "Dummy Name","color": "#000000"}
}
}
的{{1}}访问它?
index 0