app/django/contrib/gis/geos/prototypes/predicates.py
changeset 323 ff1a9aa48cfd
equal deleted inserted replaced
322:6641e941ef1e 323:ff1a9aa48cfd
       
     1 """
       
     2  This module houses the GEOS ctypes prototype functions for the 
       
     3  unary and binary predicate operations on geometries.
       
     4 """
       
     5 from ctypes import c_char, c_char_p, c_double
       
     6 from django.contrib.gis.geos.libgeos import lgeos, GEOM_PTR
       
     7 from django.contrib.gis.geos.prototypes.errcheck import check_predicate
       
     8 
       
     9 ## Binary & unary predicate functions ##
       
    10 def binary_predicate(func, *args):
       
    11     "For GEOS binary predicate functions."
       
    12     argtypes = [GEOM_PTR, GEOM_PTR]
       
    13     if args: argtypes += args
       
    14     func.argtypes = argtypes
       
    15     func.restype = c_char
       
    16     func.errcheck = check_predicate
       
    17     return func
       
    18 
       
    19 def unary_predicate(func):
       
    20     "For GEOS unary predicate functions."
       
    21     func.argtypes = [GEOM_PTR]
       
    22     func.restype = c_char
       
    23     func.errcheck = check_predicate
       
    24     return func
       
    25 
       
    26 ## Unary Predicates ##
       
    27 geos_hasz = unary_predicate(lgeos.GEOSHasZ)
       
    28 geos_isempty = unary_predicate(lgeos.GEOSisEmpty)
       
    29 geos_isring = unary_predicate(lgeos.GEOSisRing)
       
    30 geos_issimple = unary_predicate(lgeos.GEOSisSimple)
       
    31 geos_isvalid = unary_predicate(lgeos.GEOSisValid)
       
    32 
       
    33 ## Binary Predicates ##
       
    34 geos_contains = binary_predicate(lgeos.GEOSContains)
       
    35 geos_crosses = binary_predicate(lgeos.GEOSCrosses)
       
    36 geos_disjoint = binary_predicate(lgeos.GEOSDisjoint)
       
    37 geos_equals = binary_predicate(lgeos.GEOSEquals)
       
    38 geos_equalsexact = binary_predicate(lgeos.GEOSEqualsExact, c_double)
       
    39 geos_intersects = binary_predicate(lgeos.GEOSIntersects)
       
    40 geos_overlaps = binary_predicate(lgeos.GEOSOverlaps)
       
    41 geos_relatepattern = binary_predicate(lgeos.GEOSRelatePattern, c_char_p)
       
    42 geos_touches = binary_predicate(lgeos.GEOSTouches)
       
    43 geos_within = binary_predicate(lgeos.GEOSWithin)