Exemplo n.º 1
0
    def test_diff_intersection_union(self):
        "Testing the `difference`, `intersection`, `sym_difference`, and `union` GeoQuerySet methods."
        geom = Point(5, 23, srid=4326)
        qs = Country.objects.all().annotate(
            difference=functions.Difference('mpoly', geom),
            sym_difference=functions.SymDifference('mpoly', geom),
            union=functions.Union('mpoly', geom),
        )

        # For some reason SpatiaLite does something screwy with the Texas geometry here.
        # Also, it doesn't like the null intersection.
        if spatialite:
            qs = qs.exclude(name='Texas')
        else:
            qs = qs.annotate(
                intersection=functions.Intersection('mpoly', geom))

        if oracle:
            # Should be able to execute the queries; however, they won't be the same
            # as GEOS (because Oracle doesn't use GEOS internally like PostGIS or
            # SpatiaLite).
            return
        for c in qs:
            self.assertTrue(c.mpoly.difference(geom).equals(c.difference))
            if not (spatialite or mysql):
                self.assertEqual(c.mpoly.intersection(geom), c.intersection)
            self.assertTrue(
                c.mpoly.sym_difference(geom).equals(c.sym_difference))
            self.assertTrue(c.mpoly.union(geom).equals(c.union))
Exemplo n.º 2
0
 def test_sym_difference(self):
     geom = Point(5, 23, srid=4326)
     qs = Country.objects.annotate(sym_difference=functions.SymDifference('mpoly', geom))
     # Oracle does something screwy with the Texas geometry.
     if oracle:
         qs = qs.exclude(name='Texas')
     for country in qs:
         self.assertTrue(country.mpoly.sym_difference(geom).equals(country.sym_difference))
Exemplo n.º 3
0
 def test_sym_difference(self):
     geom = Point(5, 23, srid=4326)
     qs = Country.objects.annotate(
         sym_difference=functions.SymDifference('mpoly', geom))
     for country in qs:
         self.assertTrue(
             country.mpoly.sym_difference(geom).equals(
                 country.sym_difference))
Exemplo n.º 4
0
 def test_sym_difference(self):
     geom = Point(5, 23, srid=4326)
     qs = Country.objects.annotate(
         sym_difference=functions.SymDifference('mpoly', geom))
     for country in qs:
         # Ordering might differ in collections
         self.assertSetEqual(
             set(g.wkt for g in country.mpoly.sym_difference(geom)),
             set(g.wkt for g in country.sym_difference))
Exemplo n.º 5
0
 def test_sym_difference(self):
     if geos_version_info()['version'] < '3.3.0':
         self.skipTest("GEOS >= 3.3 required")
     geom = Point(5, 23, srid=4326)
     qs = Country.objects.annotate(
         sym_difference=functions.SymDifference('mpoly', geom))
     for country in qs:
         # Ordering might differ in collections
         self.assertSetEqual(
             set(g.wkt for g in country.mpoly.sym_difference(geom)),
             set(g.wkt for g in country.sym_difference))
Exemplo n.º 6
0
 def test_sym_difference(self):
     if geos_version_info()['version'] < '3.3.0':
         self.skipTest("GEOS >= 3.3 required")
     geom = Point(5, 23, srid=4326)
     qs = Country.objects.annotate(
         sym_difference=functions.SymDifference('mpoly', geom))
     # Oracle does something screwy with the Texas geometry.
     if oracle:
         qs = qs.exclude(name='Texas')
     for country in qs:
         # Ordering might differ in collections
         self.assertSetEqual(
             set(g.wkt for g in country.mpoly.sym_difference(geom)),
             set(g.wkt for g in country.sym_difference))
Exemplo n.º 7
0
    def test_diff_intersection_union(self):
        geom = Point(5, 23, srid=4326)
        qs = Country.objects.all().annotate(
            difference=functions.Difference('mpoly', geom),
            sym_difference=functions.SymDifference('mpoly', geom),
            union=functions.Union('mpoly', geom),
            intersection=functions.Intersection('mpoly', geom),
        )

        if oracle:
            # Should be able to execute the queries; however, they won't be the same
            # as GEOS (because Oracle doesn't use GEOS internally like PostGIS or
            # SpatiaLite).
            return
        for c in qs:
            self.assertTrue(c.mpoly.difference(geom).equals(c.difference))
            if not (spatialite or mysql):
                self.assertEqual(c.mpoly.intersection(geom), c.intersection)
            self.assertTrue(c.mpoly.sym_difference(geom).equals(c.sym_difference))
            self.assertTrue(c.mpoly.union(geom).equals(c.union))
Exemplo n.º 8
0
    def test_diff_intersection_union(self):
        geom = Point(5, 23, srid=4326)
        qs = Country.objects.annotate(
            difference=functions.Difference("mpoly", geom),
            sym_difference=functions.SymDifference("mpoly", geom),
            union=functions.Union("mpoly", geom),
            intersection=functions.Intersection("mpoly", geom),
        )

        if connection.ops.oracle:
            # Should be able to execute the queries; however, they won't be the same
            # as GEOS (because Oracle doesn't use GEOS internally like PostGIS or
            # SpatiaLite).
            return
        for c in qs:
            self.assertTrue(c.mpoly.difference(geom).equals(c.difference))
            if connection.features.empty_intersection_returns_none:
                self.assertIsNone(c.intersection)
            else:
                self.assertIs(c.intersection.empty, True)
            self.assertTrue(c.mpoly.sym_difference(geom).equals(c.sym_difference))
            self.assertTrue(c.mpoly.union(geom).equals(c.union))