~canonical-django/canonical-django/project-template

« back to all changes in this revision

Viewing changes to trunk/python-packages/django/contrib/gis/geos/prototypes/predicates.py

  • Committer: Matthew Nuzum
  • Date: 2008-11-13 05:46:03 UTC
  • Revision ID: matthew.nuzum@canonical.com-20081113054603-v0kvr6z6xyexvqt3
adding to version control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)