Opened 3 hours ago

Last modified 2 hours ago

#37250 assigned Bug

GeometryCollection should be an allowed type for GeometryCollection — at Version 1

Reported by: Jacob Walls Owned by: Jacob Walls
Component: GIS Version: 6.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Jacob Walls)

The multivalued geometry fields, e.g. MultiPolygon, define which classes they can contain, e.g. Polygon but not Point, via the private attribute _allowed.

GeometryCollection is generic, so it contains all the others:

# Setting the allowed types here since GeometryCollection is defined before
# its subclasses.
GeometryCollection._allowed = (
    Point,
    LineString,
    LinearRing,
    Polygon,
    MultiPoint,
    MultiLineString,
    MultiPolygon,
)

However, this list should also contain itself, since GeometryCollections can be nested.

In other words, this should work:

  • django/contrib/gis/geos/collections.py

    diff --git a/django/contrib/gis/geos/collections.py b/django/contrib/gis/geos/collections.py
    index 8659b660b6..16b5c74951 100644
    a b GeometryCollection._allowed = (  
    123123    MultiPoint,
    124124    MultiLineString,
    125125    MultiPolygon,
     126    GeometryCollection,
    126127)
  • tests/gis_tests/geos_tests/test_geos.py

    diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py
    index 025e4fb4f3..e1a531b979 100644
    a b class GEOSTest(SimpleTestCase, TestDataMixin):  
    13471347        # And, they should be equal.
    13481348        self.assertEqual(gc1, gc2)
    13491349
     1350        # Should also construct ok from GeometryCollection.
     1351        gc3 = GeometryCollection(gc2)
     1352        self.assertEqual(gc1, gc3[0])
     1353
    13501354    def test_gdal(self):
    13511355        "Testing `ogr` and `srs` properties."
    13521356        g1 = fromstr("POINT(5 23)")

Change History (1)

comment:1 by Jacob Walls, 2 hours ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top