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.

topology.py 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. """
  2. This module houses the GEOS ctypes prototype functions for the
  3. topological operations on geometries.
  4. """
  5. from ctypes import c_double, c_int
  6. from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOSFuncFactory
  7. from django.contrib.gis.geos.prototypes.errcheck import (
  8. check_geom, check_minus_one, check_string,
  9. )
  10. from django.contrib.gis.geos.prototypes.geom import geos_char_p
  11. class Topology(GEOSFuncFactory):
  12. "For GEOS unary topology functions."
  13. argtypes = [GEOM_PTR]
  14. restype = GEOM_PTR
  15. errcheck = staticmethod(check_geom)
  16. # Topology Routines
  17. geos_boundary = Topology('GEOSBoundary')
  18. geos_buffer = Topology('GEOSBuffer', argtypes=[GEOM_PTR, c_double, c_int])
  19. geos_bufferwithstyle = Topology('GEOSBufferWithStyle', argtypes=[GEOM_PTR, c_double, c_int, c_int, c_int, c_double])
  20. geos_centroid = Topology('GEOSGetCentroid')
  21. geos_convexhull = Topology('GEOSConvexHull')
  22. geos_difference = Topology('GEOSDifference', argtypes=[GEOM_PTR, GEOM_PTR])
  23. geos_envelope = Topology('GEOSEnvelope')
  24. geos_intersection = Topology('GEOSIntersection', argtypes=[GEOM_PTR, GEOM_PTR])
  25. geos_linemerge = Topology('GEOSLineMerge')
  26. geos_pointonsurface = Topology('GEOSPointOnSurface')
  27. geos_preservesimplify = Topology('GEOSTopologyPreserveSimplify', argtypes=[GEOM_PTR, c_double])
  28. geos_simplify = Topology('GEOSSimplify', argtypes=[GEOM_PTR, c_double])
  29. geos_symdifference = Topology('GEOSSymDifference', argtypes=[GEOM_PTR, GEOM_PTR])
  30. geos_union = Topology('GEOSUnion', argtypes=[GEOM_PTR, GEOM_PTR])
  31. geos_unary_union = GEOSFuncFactory('GEOSUnaryUnion', argtypes=[GEOM_PTR], restype=GEOM_PTR)
  32. # GEOSRelate returns a string, not a geometry.
  33. geos_relate = GEOSFuncFactory(
  34. 'GEOSRelate', argtypes=[GEOM_PTR, GEOM_PTR], restype=geos_char_p, errcheck=check_string
  35. )
  36. # Linear referencing routines
  37. geos_project = GEOSFuncFactory(
  38. 'GEOSProject', argtypes=[GEOM_PTR, GEOM_PTR], restype=c_double, errcheck=check_minus_one
  39. )
  40. geos_interpolate = Topology('GEOSInterpolate', argtypes=[GEOM_PTR, c_double])
  41. geos_project_normalized = GEOSFuncFactory(
  42. 'GEOSProjectNormalized', argtypes=[GEOM_PTR, GEOM_PTR], restype=c_double, errcheck=check_minus_one
  43. )
  44. geos_interpolate_normalized = Topology('GEOSInterpolateNormalized', argtypes=[GEOM_PTR, c_double])