errors.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. """Shapely errors."""
  2. import threading
  3. from shapely.lib import GEOSException, ShapelyError, _setup_signal_checks # noqa: F401
  4. def setup_signal_checks(interval=10000):
  5. """Enable Python signal checks in the ufunc inner loops.
  6. Doing so allows termination (using CTRL+C) of operations on large arrays of
  7. vectors.
  8. Parameters
  9. ----------
  10. interval : int, default 10000
  11. Check for interrupts every x iterations. The higher the number, the
  12. slower shapely will respond to a signal. However, at low values there
  13. will be a negative effect on performance. The default of 10000 does not
  14. have any measureable effects on performance.
  15. Notes
  16. -----
  17. For more information on signals consult the Python docs:
  18. https://docs.python.org/3/library/signal.html
  19. """
  20. if interval <= 0:
  21. raise ValueError("Signal checks interval must be greater than zero.")
  22. _setup_signal_checks(interval, threading.main_thread().ident)
  23. class UnsupportedGEOSVersionError(ShapelyError):
  24. """Raised when the GEOS library version does not support a certain operation."""
  25. class DimensionError(ShapelyError):
  26. """An error in the number of coordinate dimensions."""
  27. class TopologicalError(ShapelyError):
  28. """A geometry is invalid or topologically incorrect."""
  29. class ShapelyDeprecationWarning(FutureWarning):
  30. """Warning for features that will be removed or changed in a future release."""
  31. class EmptyPartError(ShapelyError):
  32. """An error signifying an empty part was encountered when creating a multi-part."""
  33. class GeometryTypeError(ShapelyError):
  34. """An error raised when the geometry has an unrecognized or inappropriate type."""
  35. def __getattr__(name):
  36. import warnings
  37. # Alias Shapely 1.8 error classes to ShapelyError with deprecation warning
  38. if name in [
  39. "ReadingError",
  40. "WKBReadingError",
  41. "WKTReadingError",
  42. "PredicateError",
  43. "InvalidGeometryError",
  44. ]:
  45. warnings.warn(
  46. f"{name} is deprecated and will be removed in a future version. "
  47. "Use ShapelyError instead (functions previously raising {name} "
  48. "will now raise a ShapelyError instead).",
  49. FutureWarning,
  50. stacklevel=2,
  51. )
  52. return ShapelyError
  53. raise AttributeError(f"module 'shapely.errors' has no attribute '{name}'")