-
Notifications
You must be signed in to change notification settings - Fork 24
Add GeoDjango support #308
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
Draft
timgraham
wants to merge
8
commits into
mongodb:main
Choose a base branch
from
timgraham:gis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
53b16bc
use fork for temporary testing
timgraham e26ee4f
Add GeoDjango support
timgraham 595c908
some issues triaged
timgraham 600544f
Add support for GeoSpatial indexes
timgraham 28699bc
disable spatial indexes
timgraham c936425
fix polygon initialization, use serialized type for geom_class
timgraham 3020173
add back GeometryCollection, initialize with srid=4326
timgraham a6b6796
fix GeometryCollection initialization
timgraham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .functions import register_functions | ||
from .lookups import register_lookups | ||
|
||
register_functions() | ||
register_lookups() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import collections | ||
|
||
|
||
class Adapter(collections.UserDict): | ||
def __init__(self, obj, geography=False): | ||
""" | ||
Initialize on the spatial object. | ||
""" | ||
if obj.__class__.__name__ == "GeometryCollection": | ||
self.data = { | ||
"type": obj.__class__.__name__, | ||
"geometries": [self.get_data(x) for x in obj], | ||
} | ||
else: | ||
self.data = self.get_data(obj) | ||
|
||
def get_data(self, obj): | ||
return { | ||
"type": obj.__class__.__name__, | ||
"coordinates": obj.coords[0] if obj.__class__.__name__ == "Polygon" else obj.coords, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django_mongodb_backend.base import DatabaseWrapper as BaseDatabaseWrapper | ||
|
||
from .features import DatabaseFeatures | ||
from .operations import DatabaseOperations | ||
from .schema import DatabaseSchemaEditor | ||
|
||
|
||
class DatabaseWrapper(BaseDatabaseWrapper): | ||
SchemaEditorClass = DatabaseSchemaEditor | ||
features_class = DatabaseFeatures | ||
ops_class = DatabaseOperations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures | ||
from django.utils.functional import cached_property | ||
|
||
from django_mongodb_backend.features import DatabaseFeatures as MongoFeatures | ||
|
||
|
||
class DatabaseFeatures(BaseSpatialFeatures, MongoFeatures): | ||
has_spatialrefsys_table = False | ||
supports_transform = False | ||
|
||
@cached_property | ||
def django_test_expected_failures(self): | ||
expected_failures = super().django_test_expected_failures | ||
expected_failures.update( | ||
{ | ||
# SRIDs aren't populated: AssertionError: 4326 != None | ||
# self.assertEqual(4326, nullcity.point.srid) | ||
"gis_tests.geoapp.tests.GeoModelTest.test_proxy", | ||
# MongoDB does not support the within lookup | ||
"gis_tests.relatedapp.tests.RelatedGeoModelTest.test06_f_expressions", | ||
# 'Adapter' object has no attribute 'srid' | ||
"gis_tests.geoapp.test_expressions.GeoExpressionsTests.test_geometry_value_annotation", | ||
# Object of type ObjectId is not JSON serializable | ||
"gis_tests.geoapp.test_serializers.GeoJSONSerializerTests.test_fields_option", | ||
"gis_tests.geoapp.test_serializers.GeoJSONSerializerTests.test_geometry_field_option", | ||
"gis_tests.geoapp.test_serializers.GeoJSONSerializerTests.test_serialization_base", | ||
"gis_tests.geoapp.test_serializers.GeoJSONSerializerTests.test_srid_option", | ||
# KeyError: 'within' connection.ops.gis_operators[self.lookup_name] | ||
"gis_tests.geoapp.tests.GeoModelTest.test_gis_query_as_string", | ||
# No lookups are supported (yet?) | ||
"gis_tests.geoapp.tests.GeoLookupTest.test_gis_lookups_with_complex_expressions", | ||
} | ||
) | ||
return expected_failures | ||
|
||
@cached_property | ||
def django_test_skips(self): | ||
skips = super().django_test_skips | ||
skips.update( | ||
{ | ||
"inspectdb not supported.": { | ||
"gis_tests.inspectapp.tests.InspectDbTests", | ||
}, | ||
"Raw SQL not supported": { | ||
"gis_tests.geoapp.tests.GeoModelTest.test_raw_sql_query", | ||
}, | ||
}, | ||
) | ||
return skips |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Placeholder if we can support any functions. | ||
# from django.contrib.gis.db.models.functions import Distance, Length, Perimeter | ||
|
||
|
||
def register_functions(): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.contrib.gis.db.models.lookups import GISLookup | ||
from django.db import NotSupportedError | ||
|
||
|
||
def gis_lookup(self, compiler, connection): # noqa: ARG001 | ||
raise NotSupportedError(f"MongoDB does not support the {self.lookup_name} lookup.") | ||
|
||
|
||
def register_lookups(): | ||
GISLookup.as_mql = gis_lookup |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be
django_mongodb_backend.gis
? I cannot with the_gis
on the already too longdjango_mongodb_backend
. Also similar todjango.contrib.gis
.