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