Replaced get_pointer_arr() with usage of GEOM_PTR for simplicity.

This commit is contained in:
Sergey Fedoseev 2017-09-06 17:06:36 +05:00 committed by Tim Graham
parent ad4a8acdb5
commit a8ad1e3216
3 changed files with 7 additions and 18 deletions

View File

@ -7,7 +7,7 @@ from ctypes import byref, c_int, c_uint
from django.contrib.gis.geos import prototypes as capi from django.contrib.gis.geos import prototypes as capi
from django.contrib.gis.geos.error import GEOSException from django.contrib.gis.geos.error import GEOSException
from django.contrib.gis.geos.geometry import GEOSGeometry, LinearGeometryMixin from django.contrib.gis.geos.geometry import GEOSGeometry, LinearGeometryMixin
from django.contrib.gis.geos.libgeos import geos_version_tuple, get_pointer_arr from django.contrib.gis.geos.libgeos import GEOM_PTR, geos_version_tuple
from django.contrib.gis.geos.linestring import LinearRing, LineString from django.contrib.gis.geos.linestring import LinearRing, LineString
from django.contrib.gis.geos.point import Point from django.contrib.gis.geos.point import Point
from django.contrib.gis.geos.polygon import Polygon from django.contrib.gis.geos.polygon import Polygon
@ -49,12 +49,11 @@ class GeometryCollection(GEOSGeometry):
# ### Methods for compatibility with ListMixin ### # ### Methods for compatibility with ListMixin ###
def _create_collection(self, length, items): def _create_collection(self, length, items):
# Creating the geometry pointer array. # Creating the geometry pointer array.
geoms = get_pointer_arr(length) geoms = (GEOM_PTR * length)(*[
for i, g in enumerate(items):
# this is a little sloppy, but makes life easier # this is a little sloppy, but makes life easier
# allow GEOSGeometry types (python wrappers) or pointer types # allow GEOSGeometry types (python wrappers) or pointer types
geoms[i] = capi.geom_clone(getattr(g, 'ptr', g)) capi.geom_clone(getattr(g, 'ptr', g)) for g in items
])
return capi.create_collection(c_int(self._typeid), byref(geoms), c_uint(length)) return capi.create_collection(c_int(self._typeid), byref(geoms), c_uint(length))
def _get_single_internal(self, index): def _get_single_internal(self, index):

View File

@ -127,14 +127,6 @@ CS_PTR = POINTER(GEOSCoordSeq_t)
CONTEXT_PTR = POINTER(GEOSContextHandle_t) CONTEXT_PTR = POINTER(GEOSContextHandle_t)
# Used specifically by the GEOSGeom_createPolygon and GEOSGeom_createCollection
# GEOS routines
def get_pointer_arr(n):
"Get a ctypes pointer array (of length `n`) for GEOSGeom_t opaque pointer."
GeomArr = GEOM_PTR * n
return GeomArr()
lgeos = SimpleLazyObject(load_geos) lgeos = SimpleLazyObject(load_geos)

View File

@ -2,7 +2,7 @@ from ctypes import byref, c_uint
from django.contrib.gis.geos import prototypes as capi from django.contrib.gis.geos import prototypes as capi
from django.contrib.gis.geos.geometry import GEOSGeometry from django.contrib.gis.geos.geometry import GEOSGeometry
from django.contrib.gis.geos.libgeos import GEOM_PTR, get_pointer_arr from django.contrib.gis.geos.libgeos import GEOM_PTR
from django.contrib.gis.geos.linestring import LinearRing from django.contrib.gis.geos.linestring import LinearRing
@ -86,10 +86,8 @@ class Polygon(GEOSGeometry):
n_holes = length - 1 n_holes = length - 1
if n_holes: if n_holes:
holes = get_pointer_arr(n_holes) holes = (GEOM_PTR * n_holes)(*[self._clone(r) for r in rings])
for i, r in enumerate(rings): holes_param = byref(holes)
holes[i] = self._clone(r)
holes_param = byref(holes)
else: else:
holes_param = None holes_param = None