PageRenderTime 28ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://code.google.com/p/mango-py/
Python | 51 lines | 39 code | 5 blank | 7 comment | 2 complexity | 7027fe3ad6f9574f02e01d7f7b6987df MD5 | raw file
Possible License(s): BSD-3-Clause
  1. """
  2. This module houses the GEOS ctypes prototype functions for the
  3. topological operations on geometries.
  4. """
  5. __all__ = ['geos_boundary', 'geos_buffer', 'geos_centroid', 'geos_convexhull',
  6. 'geos_difference', 'geos_envelope', 'geos_intersection',
  7. 'geos_linemerge', 'geos_pointonsurface', 'geos_preservesimplify',
  8. 'geos_simplify', 'geos_symdifference', 'geos_union', 'geos_relate']
  9. from ctypes import c_char_p, c_double, c_int
  10. from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOS_PREPARE
  11. from django.contrib.gis.geos.prototypes.errcheck import check_geom, check_string
  12. from django.contrib.gis.geos.prototypes.geom import geos_char_p
  13. from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc
  14. def topology(func, *args):
  15. "For GEOS unary topology functions."
  16. argtypes = [GEOM_PTR]
  17. if args: argtypes += args
  18. func.argtypes = argtypes
  19. func.restype = GEOM_PTR
  20. func.errcheck = check_geom
  21. return func
  22. ### Topology Routines ###
  23. geos_boundary = topology(GEOSFunc('GEOSBoundary'))
  24. geos_buffer = topology(GEOSFunc('GEOSBuffer'), c_double, c_int)
  25. geos_centroid = topology(GEOSFunc('GEOSGetCentroid'))
  26. geos_convexhull = topology(GEOSFunc('GEOSConvexHull'))
  27. geos_difference = topology(GEOSFunc('GEOSDifference'), GEOM_PTR)
  28. geos_envelope = topology(GEOSFunc('GEOSEnvelope'))
  29. geos_intersection = topology(GEOSFunc('GEOSIntersection'), GEOM_PTR)
  30. geos_linemerge = topology(GEOSFunc('GEOSLineMerge'))
  31. geos_pointonsurface = topology(GEOSFunc('GEOSPointOnSurface'))
  32. geos_preservesimplify = topology(GEOSFunc('GEOSTopologyPreserveSimplify'), c_double)
  33. geos_simplify = topology(GEOSFunc('GEOSSimplify'), c_double)
  34. geos_symdifference = topology(GEOSFunc('GEOSSymDifference'), GEOM_PTR)
  35. geos_union = topology(GEOSFunc('GEOSUnion'), GEOM_PTR)
  36. # GEOSRelate returns a string, not a geometry.
  37. geos_relate = GEOSFunc('GEOSRelate')
  38. geos_relate.argtypes = [GEOM_PTR, GEOM_PTR]
  39. geos_relate.restype = geos_char_p
  40. geos_relate.errcheck = check_string
  41. # Routines only in GEOS 3.1+
  42. if GEOS_PREPARE:
  43. geos_cascaded_union = GEOSFunc('GEOSUnionCascaded')
  44. geos_cascaded_union.argtypes = [GEOM_PTR]
  45. geos_cascaded_union.restype = GEOM_PTR
  46. __all__.append('geos_cascaded_union')