You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

prepared.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from .base import GEOSBase
  2. from .prototypes import prepared as capi
  3. class PreparedGeometry(GEOSBase):
  4. """
  5. A geometry that is prepared for performing certain operations.
  6. At the moment this includes the contains covers, and intersects
  7. operations.
  8. """
  9. ptr_type = capi.PREPGEOM_PTR
  10. destructor = capi.prepared_destroy
  11. def __init__(self, geom):
  12. # Keeping a reference to the original geometry object to prevent it
  13. # from being garbage collected which could then crash the prepared one
  14. # See #21662
  15. self._base_geom = geom
  16. from .geometry import GEOSGeometry
  17. if not isinstance(geom, GEOSGeometry):
  18. raise TypeError
  19. self.ptr = capi.geos_prepare(geom.ptr)
  20. def contains(self, other):
  21. return capi.prepared_contains(self.ptr, other.ptr)
  22. def contains_properly(self, other):
  23. return capi.prepared_contains_properly(self.ptr, other.ptr)
  24. def covers(self, other):
  25. return capi.prepared_covers(self.ptr, other.ptr)
  26. def intersects(self, other):
  27. return capi.prepared_intersects(self.ptr, other.ptr)
  28. def crosses(self, other):
  29. return capi.prepared_crosses(self.ptr, other.ptr)
  30. def disjoint(self, other):
  31. return capi.prepared_disjoint(self.ptr, other.ptr)
  32. def overlaps(self, other):
  33. return capi.prepared_overlaps(self.ptr, other.ptr)
  34. def touches(self, other):
  35. return capi.prepared_touches(self.ptr, other.ptr)
  36. def within(self, other):
  37. return capi.prepared_within(self.ptr, other.ptr)