PageRenderTime 27ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://code.google.com/p/mango-py/
Python | 39 lines | 22 code | 5 blank | 12 comment | 2 complexity | d752abc59872276db4c48958a560cfbc MD5 | raw file
Possible License(s): BSD-3-Clause
  1. """
  2. This module is for the miscellaneous GEOS routines, particularly the
  3. ones that return the area, distance, and length.
  4. """
  5. from ctypes import c_int, c_double, POINTER
  6. from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOS_PREPARE
  7. from django.contrib.gis.geos.prototypes.errcheck import check_dbl, check_string
  8. from django.contrib.gis.geos.prototypes.geom import geos_char_p
  9. from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc
  10. __all__ = ['geos_area', 'geos_distance', 'geos_length']
  11. ### ctypes generator function ###
  12. def dbl_from_geom(func, num_geom=1):
  13. """
  14. Argument is a Geometry, return type is double that is passed
  15. in by reference as the last argument.
  16. """
  17. argtypes = [GEOM_PTR for i in xrange(num_geom)]
  18. argtypes += [POINTER(c_double)]
  19. func.argtypes = argtypes
  20. func.restype = c_int # Status code returned
  21. func.errcheck = check_dbl
  22. return func
  23. ### ctypes prototypes ###
  24. # Area, distance, and length prototypes.
  25. geos_area = dbl_from_geom(GEOSFunc('GEOSArea'))
  26. geos_distance = dbl_from_geom(GEOSFunc('GEOSDistance'), num_geom=2)
  27. geos_length = dbl_from_geom(GEOSFunc('GEOSLength'))
  28. # Validity reason; only in GEOS 3.1+
  29. if GEOS_PREPARE:
  30. geos_isvalidreason = GEOSFunc('GEOSisValidReason')
  31. geos_isvalidreason.argtypes = [GEOM_PTR]
  32. geos_isvalidreason.restype = geos_char_p
  33. geos_isvalidreason.errcheck = check_string
  34. __all__.append('geos_isvalidreason')