Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What about Geospatial fields and queries? #305

Open
mosynaq opened this issue Oct 19, 2020 · 2 comments
Open

What about Geospatial fields and queries? #305

mosynaq opened this issue Oct 19, 2020 · 2 comments

Comments

@mosynaq
Copy link

mosynaq commented Oct 19, 2020

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
Copy link
Author

mosynaq commented Nov 26, 2020

Hello? Anyone here?

@lafrech
Copy link
Collaborator

lafrech commented Nov 27, 2020

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants