|
@@ -10,16 +10,20 @@ from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc
|
|
|
from django.utils import six
|
|
|
from django.utils.encoding import force_bytes
|
|
|
|
|
|
+
|
|
|
### The WKB/WKT Reader/Writer structures and pointers ###
|
|
|
class WKTReader_st(Structure):
|
|
|
pass
|
|
|
|
|
|
+
|
|
|
class WKTWriter_st(Structure):
|
|
|
pass
|
|
|
|
|
|
+
|
|
|
class WKBReader_st(Structure):
|
|
|
pass
|
|
|
|
|
|
+
|
|
|
class WKBWriter_st(Structure):
|
|
|
pass
|
|
|
|
|
@@ -71,6 +75,7 @@ wkb_reader_create.restype = WKB_READ_PTR
|
|
|
wkb_reader_destroy = GEOSFunc('GEOSWKBReader_destroy')
|
|
|
wkb_reader_destroy.argtypes = [WKB_READ_PTR]
|
|
|
|
|
|
+
|
|
|
def wkb_read_func(func):
|
|
|
# Although the function definitions take `const unsigned char *`
|
|
|
# as their parameter, we use c_char_p here so the function may
|
|
@@ -92,6 +97,7 @@ wkb_writer_create.restype = WKB_WRITE_PTR
|
|
|
wkb_writer_destroy = GEOSFunc('GEOSWKBWriter_destroy')
|
|
|
wkb_writer_destroy.argtypes = [WKB_WRITE_PTR]
|
|
|
|
|
|
+
|
|
|
# WKB Writing prototypes.
|
|
|
def wkb_write_func(func):
|
|
|
func.argtypes = [WKB_WRITE_PTR, GEOM_PTR, POINTER(c_size_t)]
|
|
@@ -102,12 +108,14 @@ def wkb_write_func(func):
|
|
|
wkb_writer_write = wkb_write_func(GEOSFunc('GEOSWKBWriter_write'))
|
|
|
wkb_writer_write_hex = wkb_write_func(GEOSFunc('GEOSWKBWriter_writeHEX'))
|
|
|
|
|
|
+
|
|
|
# WKBWriter property getter/setter prototypes.
|
|
|
def wkb_writer_get(func, restype=c_int):
|
|
|
func.argtypes = [WKB_WRITE_PTR]
|
|
|
func.restype = restype
|
|
|
return func
|
|
|
|
|
|
+
|
|
|
def wkb_writer_set(func, argtype=c_int):
|
|
|
func.argtypes = [WKB_WRITE_PTR, argtype]
|
|
|
return func
|
|
@@ -119,6 +127,7 @@ wkb_writer_set_outdim = wkb_writer_set(GEOSFunc('GEOSWKBWriter_setOutputDimensio
|
|
|
wkb_writer_get_include_srid = wkb_writer_get(GEOSFunc('GEOSWKBWriter_getIncludeSRID'), restype=c_char)
|
|
|
wkb_writer_set_include_srid = wkb_writer_set(GEOSFunc('GEOSWKBWriter_setIncludeSRID'), argtype=c_char)
|
|
|
|
|
|
+
|
|
|
### Base I/O Class ###
|
|
|
class IOBase(GEOSBase):
|
|
|
"Base class for GEOS I/O objects."
|
|
@@ -133,6 +142,7 @@ class IOBase(GEOSBase):
|
|
|
|
|
|
### Base WKB/WKT Reading and Writing objects ###
|
|
|
|
|
|
+
|
|
|
# Non-public WKB/WKT reader classes for internal use because
|
|
|
# their `read` methods return _pointers_ instead of GEOSGeometry
|
|
|
# objects.
|
|
@@ -146,6 +156,7 @@ class _WKTReader(IOBase):
|
|
|
raise TypeError
|
|
|
return wkt_reader_read(self.ptr, force_bytes(wkt))
|
|
|
|
|
|
+
|
|
|
class _WKBReader(IOBase):
|
|
|
_constructor = wkb_reader_create
|
|
|
_destructor = wkb_reader_destroy
|
|
@@ -161,6 +172,7 @@ class _WKBReader(IOBase):
|
|
|
else:
|
|
|
raise TypeError
|
|
|
|
|
|
+
|
|
|
### WKB/WKT Writer Classes ###
|
|
|
class WKTWriter(IOBase):
|
|
|
_constructor = wkt_writer_create
|
|
@@ -232,6 +244,7 @@ class WKBWriter(IOBase):
|
|
|
|
|
|
srid = property(_get_include_srid, _set_include_srid)
|
|
|
|
|
|
+
|
|
|
# `ThreadLocalIO` object holds instances of the WKT and WKB reader/writer
|
|
|
# objects that are local to the thread. The `GEOSGeometry` internals
|
|
|
# access these instances by calling the module-level functions, defined
|
|
@@ -245,6 +258,7 @@ class ThreadLocalIO(threading.local):
|
|
|
|
|
|
thread_context = ThreadLocalIO()
|
|
|
|
|
|
+
|
|
|
# These module-level routines return the I/O object that is local to the
|
|
|
# thread. If the I/O object does not exist yet it will be initialized.
|
|
|
def wkt_r():
|
|
@@ -252,23 +266,27 @@ def wkt_r():
|
|
|
thread_context.wkt_r = _WKTReader()
|
|
|
return thread_context.wkt_r
|
|
|
|
|
|
+
|
|
|
def wkt_w(dim=2):
|
|
|
if not thread_context.wkt_w:
|
|
|
thread_context.wkt_w = WKTWriter()
|
|
|
thread_context.wkt_w.outdim = dim
|
|
|
return thread_context.wkt_w
|
|
|
|
|
|
+
|
|
|
def wkb_r():
|
|
|
if not thread_context.wkb_r:
|
|
|
thread_context.wkb_r = _WKBReader()
|
|
|
return thread_context.wkb_r
|
|
|
|
|
|
+
|
|
|
def wkb_w(dim=2):
|
|
|
if not thread_context.wkb_w:
|
|
|
thread_context.wkb_w = WKBWriter()
|
|
|
thread_context.wkb_w.outdim = dim
|
|
|
return thread_context.wkb_w
|
|
|
|
|
|
+
|
|
|
def ewkb_w(dim=2):
|
|
|
if not thread_context.ewkb_w:
|
|
|
thread_context.ewkb_w = WKBWriter()
|