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.

misc.py 1.1KB

12345678910111213141516171819202122232425262728293031
  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 POINTER, c_double, c_int
  6. from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOSFuncFactory
  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. __all__ = ['geos_area', 'geos_distance', 'geos_length', 'geos_isvalidreason']
  10. class DblFromGeom(GEOSFuncFactory):
  11. """
  12. Argument is a Geometry, return type is double that is passed
  13. in by reference as the last argument.
  14. """
  15. restype = c_int # Status code returned
  16. errcheck = staticmethod(check_dbl)
  17. # ### ctypes prototypes ###
  18. # Area, distance, and length prototypes.
  19. geos_area = DblFromGeom('GEOSArea', argtypes=[GEOM_PTR, POINTER(c_double)])
  20. geos_distance = DblFromGeom('GEOSDistance', argtypes=[GEOM_PTR, GEOM_PTR, POINTER(c_double)])
  21. geos_length = DblFromGeom('GEOSLength', argtypes=[GEOM_PTR, POINTER(c_double)])
  22. geos_isvalidreason = GEOSFuncFactory(
  23. 'GEOSisValidReason', restype=geos_char_p, errcheck=check_string, argtypes=[GEOM_PTR]
  24. )