Validate the GeoJson object based on its type.
(self, value)
| 606 | super().__init__(*args, **kwargs) |
| 607 | |
| 608 | def validate(self, value): |
| 609 | """Validate the GeoJson object based on its type.""" |
| 610 | if isinstance(value, dict): |
| 611 | if set(value.keys()) == {"type", "coordinates"}: |
| 612 | if value["type"] != self._type: |
| 613 | self.error(f'{self._name} type must be "{self._type}"') |
| 614 | return self.validate(value["coordinates"]) |
| 615 | else: |
| 616 | self.error( |
| 617 | "%s can only accept a valid GeoJson dictionary" |
| 618 | " or lists of (x, y)" % self._name |
| 619 | ) |
| 620 | return |
| 621 | elif not isinstance(value, (list, tuple)): |
| 622 | self.error("%s can only accept lists of [x, y]" % self._name) |
| 623 | return |
| 624 | |
| 625 | validate = getattr(self, "_validate_%s" % self._type.lower()) |
| 626 | error = validate(value) |
| 627 | if error: |
| 628 | self.error(error) |
| 629 | |
| 630 | def _validate_polygon(self, value, top_level=True): |
| 631 | if not isinstance(value, (list, tuple)): |