Skip to content

Commit ec1c627

Browse files
committed
create spatial indexes
1 parent 3e3ea6c commit ec1c627

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

django_mongodb_backend_gis/adapter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ def __init__(self, obj, geography=False):
1717
def get_data(self, obj):
1818
return {
1919
"type": obj.__class__.__name__,
20-
"coordinates": obj.coords[0] if obj.__class__.__name__ == "Polygon" else obj.coords,
20+
"coordinates": obj.coords,
21+
# obj.coords[0] if obj.__class__.__name__ == "Polygon" else obj.coords,
2122
}

django_mongodb_backend_gis/features.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ def django_test_expected_failures(self):
2929
"gis_tests.geoapp.tests.GeoModelTest.test_gis_query_as_string",
3030
# No lookups are supported (yet?)
3131
"gis_tests.geoapp.tests.GeoLookupTest.test_gis_lookups_with_complex_expressions",
32+
# LinearRing requires at least 4 points, got 1.
33+
"gis_tests.geoapp.tests.GeoLookupTest.test_null_geometries",
34+
"gis_tests.geoapp.tests.GeoModelTest.test_geometryfield",
35+
# Trying to remove spatial index fails:
36+
# "index not found with name [gis_neighborhood_geom_id]"
37+
"gis_tests.gis_migrations.test_operations.OperationTests.test_alter_field_remove_spatial_index",
3238
}
3339
)
3440
return expected_failures
@@ -44,6 +50,21 @@ def django_test_skips(self):
4450
"Raw SQL not supported": {
4551
"gis_tests.geoapp.tests.GeoModelTest.test_raw_sql_query",
4652
},
53+
"MongoDB doesn't support the SRID(s) used in this test.": {
54+
# Error messages:
55+
# - Can't extract geo keys
56+
# - Longitude/latitude is out of bounds
57+
"gis_tests.geoapp.test_expressions.GeoExpressionsTests.test_update_from_other_field",
58+
"gis_tests.layermap.tests.LayerMapTest.test_encoded_name",
59+
# SouthTexasCity fixture objects use SRID 2278 which is ignored
60+
# by the patched version of loaddata in the Django fork.
61+
"gis_tests.distapp.tests.DistanceTest.test_init",
62+
},
63+
"ImproperlyConfigured isn't raised when using RasterField": {
64+
# Normally RasterField.db_type() raises an error, but MongoDB
65+
# migrations don't need to call it, so the check doesn't happen.
66+
"gis_tests.gis_migrations.test_operations.NoRasterSupportTests",
67+
},
4768
},
4869
)
4970
return skips

django_mongodb_backend_gis/schema.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66

77

88
class DatabaseSchemaEditor(BaseSchemaEditor):
9-
# def _field_should_be_indexed(self, model, field):
10-
# if getattr(field, "spatial_index", False):
11-
# return True
12-
# return super()._field_should_be_indexed(model, field)
9+
def _field_should_be_indexed(self, model, field):
10+
if getattr(field, "spatial_index", False):
11+
return True
12+
return super()._field_should_be_indexed(model, field)
1313

14-
# def _add_field_index(self, model, field, *, column_prefix=""):
15-
# if hasattr(field, "geodetic"):
16-
# self._add_spatial_index(model, field)
17-
# else:
18-
# super()._add_field_index(model, field, column_prefix=column_prefix)
14+
def _add_field_index(self, model, field, *, column_prefix=""):
15+
if hasattr(field, "geodetic"):
16+
self._add_spatial_index(model, field)
17+
else:
18+
super()._add_field_index(model, field, column_prefix=column_prefix)
1919

2020
def _alter_field(
2121
self,

0 commit comments

Comments
 (0)