app/django/contrib/gis/geos/prototypes/misc.py
changeset 323 ff1a9aa48cfd
equal deleted inserted replaced
322:6641e941ef1e 323:ff1a9aa48cfd
       
     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 lgeos, GEOM_PTR
       
     7 from django.contrib.gis.geos.prototypes.errcheck import check_dbl
       
     8 
       
     9 ### ctypes generator function ###
       
    10 def dbl_from_geom(func, num_geom=1):
       
    11     """
       
    12     Argument is a Geometry, return type is double that is passed
       
    13     in by reference as the last argument.
       
    14     """
       
    15     argtypes = [GEOM_PTR for i in xrange(num_geom)]
       
    16     argtypes += [POINTER(c_double)]
       
    17     func.argtypes = argtypes
       
    18     func.restype = c_int # Status code returned
       
    19     func.errcheck = check_dbl
       
    20     return func
       
    21 
       
    22 ### ctypes prototypes ###
       
    23 
       
    24 # Area, distance, and length prototypes.
       
    25 geos_area = dbl_from_geom(lgeos.GEOSArea)
       
    26 geos_distance = dbl_from_geom(lgeos.GEOSDistance, num_geom=2)
       
    27 geos_length = dbl_from_geom(lgeos.GEOSLength)