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.
     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 
    10 from ctypes import c_char_p, c_double, c_int
    11 from django.contrib.gis.geos.libgeos import lgeos, GEOM_PTR, GEOS_PREPARE
    12 from django.contrib.gis.geos.prototypes.errcheck import check_geom, check_string
    13 
    14 def topology(func, *args):
    15     "For GEOS unary topology functions."
    16     argtypes = [GEOM_PTR]
    17     if args: argtypes += args
    18     func.argtypes = argtypes
    19     func.restype = GEOM_PTR
    20     func.errcheck = check_geom
    21     return func
    22 
    23 ### Topology Routines ###
    24 geos_boundary = topology(lgeos.GEOSBoundary)
    25 geos_buffer = topology(lgeos.GEOSBuffer, c_double, c_int)
    26 geos_centroid = topology(lgeos.GEOSGetCentroid)
    27 geos_convexhull = topology(lgeos.GEOSConvexHull)
    28 geos_difference = topology(lgeos.GEOSDifference, GEOM_PTR)
    29 geos_envelope = topology(lgeos.GEOSEnvelope)
    30 geos_intersection = topology(lgeos.GEOSIntersection, GEOM_PTR)
    31 geos_linemerge = topology(lgeos.GEOSLineMerge)
    32 geos_pointonsurface = topology(lgeos.GEOSPointOnSurface)
    33 geos_preservesimplify = topology(lgeos.GEOSTopologyPreserveSimplify, c_double)
    34 geos_simplify = topology(lgeos.GEOSSimplify, c_double)
    35 geos_symdifference = topology(lgeos.GEOSSymDifference, GEOM_PTR)
    36 geos_union = topology(lgeos.GEOSUnion, GEOM_PTR)
    37 
    38 # GEOSRelate returns a string, not a geometry.
    39 geos_relate = lgeos.GEOSRelate
    40 geos_relate.argtypes = [GEOM_PTR, GEOM_PTR]
    41 geos_relate.errcheck = check_string
    42 
    43 # Routines only in GEOS 3.1+
    44 if GEOS_PREPARE:
    45     geos_cascaded_union = lgeos.GEOSUnionCascaded
    46     geos_cascaded_union.argtypes = [GEOM_PTR]
    47     geos_cascaded_union.restype = GEOM_PTR
    48     __all__.append('geos_cascaded_union')