django/contrib/gis/geos/prototypes/topology.py
author Justin Bronn <jbronn@geodjango.org>
Thu Mar 19 13:08:50 2009 -0500 (3 years ago)
branchtrunk
changeset 362 87b34dce202d
parent 354 3fcbf6e3e599
child 435 d75ff359e306
permissions -rw-r--r--
Added `merged` property to LineString & MultiLineString, which returns the output of the GEOS line merging operation.
kmtracey@0
     1
"""
jbronn@354
     2
 This module houses the GEOS ctypes prototype functions for the
kmtracey@0
     3
 topological operations on geometries.
kmtracey@0
     4
"""
jbronn@126
     5
__all__ = ['geos_boundary', 'geos_buffer', 'geos_centroid', 'geos_convexhull',
jbronn@362
     6
           'geos_difference', 'geos_envelope', 'geos_intersection', 
jbronn@362
     7
           'geos_linemerge', 'geos_pointonsurface', 'geos_preservesimplify',
jbronn@362
     8
           'geos_simplify', 'geos_symdifference', 'geos_union', 'geos_relate']
jbronn@126
     9
kmtracey@0
    10
from ctypes import c_char_p, c_double, c_int
jbronn@126
    11
from django.contrib.gis.geos.libgeos import lgeos, GEOM_PTR, GEOS_PREPARE
kmtracey@0
    12
from django.contrib.gis.geos.prototypes.errcheck import check_geom, check_string
kmtracey@0
    13
kmtracey@0
    14
def topology(func, *args):
kmtracey@0
    15
    "For GEOS unary topology functions."
kmtracey@0
    16
    argtypes = [GEOM_PTR]
kmtracey@0
    17
    if args: argtypes += args
kmtracey@0
    18
    func.argtypes = argtypes
kmtracey@0
    19
    func.restype = GEOM_PTR
kmtracey@0
    20
    func.errcheck = check_geom
kmtracey@0
    21
    return func
kmtracey@0
    22
kmtracey@0
    23
### Topology Routines ###
kmtracey@0
    24
geos_boundary = topology(lgeos.GEOSBoundary)
kmtracey@0
    25
geos_buffer = topology(lgeos.GEOSBuffer, c_double, c_int)
kmtracey@0
    26
geos_centroid = topology(lgeos.GEOSGetCentroid)
kmtracey@0
    27
geos_convexhull = topology(lgeos.GEOSConvexHull)
kmtracey@0
    28
geos_difference = topology(lgeos.GEOSDifference, GEOM_PTR)
kmtracey@0
    29
geos_envelope = topology(lgeos.GEOSEnvelope)
kmtracey@0
    30
geos_intersection = topology(lgeos.GEOSIntersection, GEOM_PTR)
jbronn@362
    31
geos_linemerge = topology(lgeos.GEOSLineMerge)
kmtracey@0
    32
geos_pointonsurface = topology(lgeos.GEOSPointOnSurface)
kmtracey@0
    33
geos_preservesimplify = topology(lgeos.GEOSTopologyPreserveSimplify, c_double)
kmtracey@0
    34
geos_simplify = topology(lgeos.GEOSSimplify, c_double)
kmtracey@0
    35
geos_symdifference = topology(lgeos.GEOSSymDifference, GEOM_PTR)
kmtracey@0
    36
geos_union = topology(lgeos.GEOSUnion, GEOM_PTR)
kmtracey@0
    37
kmtracey@0
    38
# GEOSRelate returns a string, not a geometry.
kmtracey@0
    39
geos_relate = lgeos.GEOSRelate
kmtracey@0
    40
geos_relate.argtypes = [GEOM_PTR, GEOM_PTR]
kmtracey@0
    41
geos_relate.errcheck = check_string
jbronn@126
    42
jbronn@126
    43
# Routines only in GEOS 3.1+
jbronn@126
    44
if GEOS_PREPARE:
jbronn@126
    45
    geos_cascaded_union = lgeos.GEOSUnionCascaded
jbronn@126
    46
    geos_cascaded_union.argtypes = [GEOM_PTR]
jbronn@126
    47
    geos_cascaded_union.restype = GEOM_PTR
jbronn@126
    48
    __all__.append('geos_cascaded_union')