MongoEngine / MongoEngine/mongoengine

DynamicGeoJsonBaseField for shapely.geometry

Open
#2,078 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.3k
Forks
1.2k
Avg merge
4h 41m
Merged PRs (30d)
11

Description

I was trying to directly store shapely.geometry.multipolygon.MultiPolygon and shapely.geometry.polygon.Polygon. I ended up creating a DynamicGeoJsonBaseField.
This is my first time here not sure how I can contribute to this amazing community.

class DynamicGeoJsonBaseField(GeoJsonBaseField):

def validate(self, value):
    if not isinstance(value, BaseGeometry):
        self.error(f'{self.name} is not a BaseGeometry')
    if 

def to_mongo(self, value):

    dict_mongo_geo_json = {}
    dict_mongo_geo_json['type'] = value.geometryType()
    coordinates = []
    if isinstance(value, Polygon):
        coordinates = list(value.exterior.coords)
    elif isinstance(value, MultiPolygon):
        coordinates = [list(i.exterior.coords) for i in list(value)]
    dict_mongo_geo_json['coordinates'] = coordinates
    return super().to_mongo(dict_mongo_geo_json)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with GeoJsonBaseField and the provided DynamicGeoJsonBaseField example. The issue names no repository file or test; done would be agreed support for directly storing Polygon and MultiPolygon values, with corresponding tests identified during investigation.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.