PageRenderTime 160ms CodeModel.GetById 101ms app.highlight 6ms RepoModel.GetById 50ms app.codeStats 0ms

/django/contrib/gis/geos/prototypes/topology.py

https://code.google.com/p/mango-py/
Python | 51 lines | 39 code | 5 blank | 7 comment | 2 complexity | 7027fe3ad6f9574f02e01d7f7b6987df MD5 | raw file
 1"""
 2 This module houses the GEOS ctypes prototype functions for the
 3 topological operations on geometries.
 4"""
 5__all__ = ['geos_boundary', 'geos_buffer', 'geos_centroid', 'geos_convexhull',
 6           'geos_difference', 'geos_envelope', 'geos_intersection', 
 7           'geos_linemerge', 'geos_pointonsurface', 'geos_preservesimplify',
 8           'geos_simplify', 'geos_symdifference', 'geos_union', 'geos_relate']
 9
10from ctypes import c_char_p, c_double, c_int
11from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOS_PREPARE
12from django.contrib.gis.geos.prototypes.errcheck import check_geom, check_string
13from django.contrib.gis.geos.prototypes.geom import geos_char_p
14from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc
15
16def topology(func, *args):
17    "For GEOS unary topology functions."
18    argtypes = [GEOM_PTR]
19    if args: argtypes += args
20    func.argtypes = argtypes
21    func.restype = GEOM_PTR
22    func.errcheck = check_geom
23    return func
24
25### Topology Routines ###
26geos_boundary = topology(GEOSFunc('GEOSBoundary'))
27geos_buffer = topology(GEOSFunc('GEOSBuffer'), c_double, c_int)
28geos_centroid = topology(GEOSFunc('GEOSGetCentroid'))
29geos_convexhull = topology(GEOSFunc('GEOSConvexHull'))
30geos_difference = topology(GEOSFunc('GEOSDifference'), GEOM_PTR)
31geos_envelope = topology(GEOSFunc('GEOSEnvelope'))
32geos_intersection = topology(GEOSFunc('GEOSIntersection'), GEOM_PTR)
33geos_linemerge = topology(GEOSFunc('GEOSLineMerge'))
34geos_pointonsurface = topology(GEOSFunc('GEOSPointOnSurface'))
35geos_preservesimplify = topology(GEOSFunc('GEOSTopologyPreserveSimplify'), c_double)
36geos_simplify = topology(GEOSFunc('GEOSSimplify'), c_double)
37geos_symdifference = topology(GEOSFunc('GEOSSymDifference'), GEOM_PTR)
38geos_union = topology(GEOSFunc('GEOSUnion'), GEOM_PTR)
39
40# GEOSRelate returns a string, not a geometry.
41geos_relate = GEOSFunc('GEOSRelate')
42geos_relate.argtypes = [GEOM_PTR, GEOM_PTR]
43geos_relate.restype = geos_char_p
44geos_relate.errcheck = check_string
45
46# Routines only in GEOS 3.1+
47if GEOS_PREPARE:
48    geos_cascaded_union = GEOSFunc('GEOSUnionCascaded')
49    geos_cascaded_union.argtypes = [GEOM_PTR]
50    geos_cascaded_union.restype = GEOM_PTR
51    __all__.append('geos_cascaded_union')