/django/contrib/gis/geos/prototypes/predicates.py

https://code.google.com/p/mango-py/ · Python · 44 lines · 33 code · 4 blank · 7 comment · 1 complexity · 93a5033bb8356c65d2ffc56b95ab1c83 MD5 · raw file

  1. """
  2. This module houses the GEOS ctypes prototype functions for the
  3. unary and binary predicate operations on geometries.
  4. """
  5. from ctypes import c_char, c_char_p, c_double
  6. from django.contrib.gis.geos.libgeos import GEOM_PTR
  7. from django.contrib.gis.geos.prototypes.errcheck import check_predicate
  8. from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc
  9. ## Binary & unary predicate functions ##
  10. def binary_predicate(func, *args):
  11. "For GEOS binary predicate functions."
  12. argtypes = [GEOM_PTR, GEOM_PTR]
  13. if args: argtypes += args
  14. func.argtypes = argtypes
  15. func.restype = c_char
  16. func.errcheck = check_predicate
  17. return func
  18. def unary_predicate(func):
  19. "For GEOS unary predicate functions."
  20. func.argtypes = [GEOM_PTR]
  21. func.restype = c_char
  22. func.errcheck = check_predicate
  23. return func
  24. ## Unary Predicates ##
  25. geos_hasz = unary_predicate(GEOSFunc('GEOSHasZ'))
  26. geos_isempty = unary_predicate(GEOSFunc('GEOSisEmpty'))
  27. geos_isring = unary_predicate(GEOSFunc('GEOSisRing'))
  28. geos_issimple = unary_predicate(GEOSFunc('GEOSisSimple'))
  29. geos_isvalid = unary_predicate(GEOSFunc('GEOSisValid'))
  30. ## Binary Predicates ##
  31. geos_contains = binary_predicate(GEOSFunc('GEOSContains'))
  32. geos_crosses = binary_predicate(GEOSFunc('GEOSCrosses'))
  33. geos_disjoint = binary_predicate(GEOSFunc('GEOSDisjoint'))
  34. geos_equals = binary_predicate(GEOSFunc('GEOSEquals'))
  35. geos_equalsexact = binary_predicate(GEOSFunc('GEOSEqualsExact'), c_double)
  36. geos_intersects = binary_predicate(GEOSFunc('GEOSIntersects'))
  37. geos_overlaps = binary_predicate(GEOSFunc('GEOSOverlaps'))
  38. geos_relatepattern = binary_predicate(GEOSFunc('GEOSRelatePattern'), c_char_p)
  39. geos_touches = binary_predicate(GEOSFunc('GEOSTouches'))
  40. geos_within = binary_predicate(GEOSFunc('GEOSWithin'))