What about Geospatial fields and queries?
mosynaq opened this issue · 2 comments
mosynaq commented
Hi.
I like this project but I need Geospatial Fields like Point and Polygon and Geospatial queries which can be found in Mongoengine.
Is there any way or plan for these?
mosynaq commented
Hello? Anyone here?
lafrech commented
I'm currently focusing on shipping umongo 3.
There's been prior discussion about this a while (4 years) ago in #248.
It might be worth checking the state of geojeon and pymongo to see if those considerations still apply. Is geojson still the way to go? Does pymongo provide some sort of geojson support? What about the other drivers? What are the exact supported features in latest MongoDB versions?
I've been using a custom Point in my app:
from marshmallow import ValidationError, fields as ma_fields
import geojson
from umongo.i18n import gettext as _
class Point(ma_fields.Field):
def _serialize(self, value, attr, obj):
if value is None:
return None
# Item access works for both Mongo world and OO world
return value['coordinates']
def _deserialize(self, value, attr, data, **kwargs):
if isinstance(value, geojson.Point):
return value
try:
# TODO: Add unit tests. Seriously.
# Should work for both Mongo world and OO world
return geojson.Point(value)
except ValueError:
raise ValidationError(_('Invalid Point.'))
import geojson
from umongo import fields as u_fields
from . import marshmallow_bonus as ma_bonus_fields
class PointField(u_fields.BaseField, ma_bonus_fields.Point):
def _deserialize_from_mongo(self, value):
return geojson.GeoJSON.to_instance(value)