Esempio n. 1
0
 def test_make_valid_output_field(self):
     # output_field is GeometryField instance because different geometry
     # types can be returned.
     output_field = functions.MakeValid(
         Value(Polygon(), PolygonField(srid=42)), ).output_field
     self.assertIs(output_field.__class__, GeometryField)
     self.assertEqual(output_field.srid, 42)
Esempio n. 2
0
 def test_make_valid(self):
     invalid_geom = fromstr('POLYGON((0 0, 0 1, 1 1, 1 0, 1 1, 1 0, 0 0))')
     State.objects.create(name='invalid', poly=invalid_geom)
     invalid = State.objects.filter(name='invalid').annotate(
         repaired=functions.MakeValid('poly')).first()
     self.assertIs(invalid.repaired.valid, True)
     self.assertEqual(invalid.repaired,
                      fromstr('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))'))
Esempio n. 3
0
 def test_make_valid(self):
     invalid_geom = fromstr("POLYGON((0 0, 0 1, 1 1, 1 0, 1 1, 1 0, 0 0))")
     State.objects.create(name="invalid", poly=invalid_geom)
     invalid = (State.objects.filter(name="invalid").annotate(
         repaired=functions.MakeValid("poly")).first())
     self.assertIs(invalid.repaired.valid, True)
     self.assertTrue(
         invalid.repaired.equals(
             fromstr("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))",
                     srid=invalid.poly.srid)))
Esempio n. 4
0
 def test_make_valid_multipolygon(self):
     invalid_geom = fromstr('POLYGON((0 0, 0 1 , 1 1 , 1 0, 0 0), '
                            '(10 0, 10 1, 11 1, 11 0, 10 0))')
     State.objects.create(name='invalid', poly=invalid_geom)
     invalid = State.objects.filter(name='invalid').annotate(
         repaired=functions.MakeValid('poly'), ).get()
     self.assertIs(invalid.repaired.valid, True)
     self.assertEqual(
         invalid.repaired,
         fromstr(
             'MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0, 0 0)), '
             '((10 0, 10 1, 11 1, 11 0, 10 0)))',
             srid=invalid.poly.srid,
         ))
     self.assertEqual(len(invalid.repaired), 2)
Esempio n. 5
0
 def test_make_valid_multipolygon(self):
     invalid_geom = fromstr(
         "POLYGON((0 0, 0 1 , 1 1 , 1 0, 0 0), (10 0, 10 1, 11 1, 11 0, 10 0))"
     )
     State.objects.create(name="invalid", poly=invalid_geom)
     invalid = (State.objects.filter(name="invalid").annotate(
         repaired=functions.MakeValid("poly"), ).get())
     self.assertIs(invalid.repaired.valid, True)
     self.assertTrue(
         invalid.repaired.equals(
             fromstr(
                 "MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0, 0 0)), "
                 "((10 0, 10 1, 11 1, 11 0, 10 0)))",
                 srid=invalid.poly.srid,
             )))
     self.assertEqual(len(invalid.repaired), 2)