Debian Codegraph @

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

raw
1 """
2 This module houses the GEOS ctypes prototype functions for the
3 topological operations on geometries.
4 """
5
6 from ctypes import c_double, c_int
7
8 from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOSFuncFactory
9 from django.contrib.gis.geos.prototypes.errcheck import (
10 check_geom,
11 check_minus_one,
12 check_string,
13 )
14 from django.contrib.gis.geos.prototypes.geom import geos_char_p
15
16
17 class Topology(GEOSFuncFactory):
18 "For GEOS unary topology functions."
19
20 argtypes = [GEOM_PTR]
21 restype = GEOM_PTR
22 errcheck = staticmethod(check_geom)
23
24
25 # Topology Routines
26 geos_boundary = Topology("GEOSBoundary")
27 geos_buffer = Topology("GEOSBuffer", argtypes=[GEOM_PTR, c_double, c_int])
28 geos_bufferwithstyle = Topology(
29 "GEOSBufferWithStyle", argtypes=[GEOM_PTR, c_double, c_int, c_int, c_int, c_double]
30 )
31 geos_centroid = Topology("GEOSGetCentroid")
32 geos_convexhull = Topology("GEOSConvexHull")
33 geos_difference = Topology("GEOSDifference", argtypes=[GEOM_PTR, GEOM_PTR])
34 geos_envelope = Topology("GEOSEnvelope")
35 geos_intersection = Topology("GEOSIntersection", argtypes=[GEOM_PTR, GEOM_PTR])
36 geos_linemerge = Topology("GEOSLineMerge")
37 geos_pointonsurface = Topology("GEOSPointOnSurface")
38 geos_preservesimplify = Topology(
39 "GEOSTopologyPreserveSimplify", argtypes=[GEOM_PTR, c_double]
40 )
41 geos_simplify = Topology("GEOSSimplify", argtypes=[GEOM_PTR, c_double])
42 geos_symdifference = Topology("GEOSSymDifference", argtypes=[GEOM_PTR, GEOM_PTR])
43 geos_union = Topology("GEOSUnion", argtypes=[GEOM_PTR, GEOM_PTR])
44
45 geos_unary_union = GEOSFuncFactory(
46 "GEOSUnaryUnion", argtypes=[GEOM_PTR], restype=GEOM_PTR
47 )
48
49 # GEOSRelate returns a string, not a geometry.
50 geos_relate = GEOSFuncFactory(
51 "GEOSRelate",
52 argtypes=[GEOM_PTR, GEOM_PTR],
53 restype=geos_char_p,
54 errcheck=check_string,
55 )
56
57 # Linear referencing routines
58 geos_project = GEOSFuncFactory(
59 "GEOSProject",
60 argtypes=[GEOM_PTR, GEOM_PTR],
61 restype=c_double,
62 errcheck=check_minus_one,
63 )
64 geos_interpolate = Topology("GEOSInterpolate", argtypes=[GEOM_PTR, c_double])
65
66 geos_project_normalized = GEOSFuncFactory(
67 "GEOSProjectNormalized",
68 argtypes=[GEOM_PTR, GEOM_PTR],
69 restype=c_double,
70 errcheck=check_minus_one,
71 )
72 geos_interpolate_normalized = Topology(
73 "GEOSInterpolateNormalized", argtypes=[GEOM_PTR, c_double]
74 )