| 1 |
""" |
| 2 |
This module is for the miscellaneous GEOS routines, particularly the |
| 3 |
ones that return the area, distance, and length. |
| 4 |
""" |
| 5 |
|
| 6 |
from ctypes import POINTER, 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 check_dbl, check_string |
| 10 |
from django.contrib.gis.geos.prototypes.geom import geos_char_p |
| 11 |
|
| 12 |
__all__ = ["geos_area", "geos_distance", "geos_length", "geos_isvalidreason"] |
| 13 |
|
| 14 |
|
| 15 |
class DblFromGeom(GEOSFuncFactory): |
| 16 |
""" |
| 17 |
Argument is a Geometry, return type is double that is passed |
| 18 |
in by reference as the last argument. |
| 19 |
""" |
| 20 |
|
| 21 |
restype = c_int # Status code returned |
| 22 |
errcheck = staticmethod(check_dbl) |
| 23 |
|
| 24 |
|
| 25 |
# ### ctypes prototypes ### |
| 26 |
|
| 27 |
# Area, distance, and length prototypes. |
| 28 |
geos_area = DblFromGeom("GEOSArea", argtypes=[GEOM_PTR, POINTER(c_double)]) |
| 29 |
geos_distance = DblFromGeom( |
| 30 |
"GEOSDistance", argtypes=[GEOM_PTR, GEOM_PTR, POINTER(c_double)] |
| 31 |
) |
| 32 |
geos_length = DblFromGeom("GEOSLength", argtypes=[GEOM_PTR, POINTER(c_double)]) |
| 33 |
geos_isvalidreason = GEOSFuncFactory( |
| 34 |
"GEOSisValidReason", restype=geos_char_p, errcheck=check_string, argtypes=[GEOM_PTR] |
| 35 |
) |