You can either pass a dictionary with the full geoJSON information or a list of point pairs. eg:
Line(owner=user, line=[[0,2],[2,0],[2.5,1.2]]).save()
Question
I would like to know how to create an object with a LineStringField in MongoEngine. With a model like that:
class Line(Document):
line = LineStringField()
owner = ReferenceField(User)
meta = {
'indexes': [[("line", "2dsphere"), ("owner", 1)]]
}
I would do something like that:
shape = Line(owner=user, line={type:"LineString",coordinates:[[0,2],[2,0],[2.5,1.2]]})
shape.save()
But I feel like I am overwriting the preset "type" attribute of the predefined LineStringField.
Solution
You can either pass a dictionary with the full geoJSON information or a list of point pairs. eg:
Line(owner=user, line=[[0,2],[2,0],[2.5,1.2]]).save()