summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2017-09-06 17:06:36 +0500
committerTim Graham <timograham@gmail.com>2017-09-06 08:06:36 -0400
commita8ad1e32162a85de6fdf9cc5e5efce60420f3489 (patch)
tree2bc0d53cb31c01a8fc6e7508c05d5000d60f2595
parentad4a8acdb55a80a6a6dec60724b22abed0025399 (diff)
Replaced get_pointer_arr() with usage of GEOM_PTR for simplicity.
-rw-r--r--django/contrib/gis/geos/collections.py9
-rw-r--r--django/contrib/gis/geos/libgeos.py8
-rw-r--r--django/contrib/gis/geos/polygon.py8
3 files changed, 7 insertions, 18 deletions
diff --git a/django/contrib/gis/geos/collections.py b/django/contrib/gis/geos/collections.py
index cea286d439..9c3a2407d1 100644
--- a/django/contrib/gis/geos/collections.py
+++ b/django/contrib/gis/geos/collections.py
@@ -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.error import GEOSException
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.point import Point
from django.contrib.gis.geos.polygon import Polygon
@@ -49,12 +49,11 @@ class GeometryCollection(GEOSGeometry):
# ### Methods for compatibility with ListMixin ###
def _create_collection(self, length, items):
# Creating the geometry pointer array.
- geoms = get_pointer_arr(length)
- for i, g in enumerate(items):
+ geoms = (GEOM_PTR * length)(*[
# this is a little sloppy, but makes life easier
# 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))
def _get_single_internal(self, index):
diff --git a/django/contrib/gis/geos/libgeos.py b/django/contrib/gis/geos/libgeos.py
index 29a15a249b..e63d42659b 100644
--- a/django/contrib/gis/geos/libgeos.py
+++ b/django/contrib/gis/geos/libgeos.py
@@ -127,14 +127,6 @@ CS_PTR = POINTER(GEOSCoordSeq_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)
diff --git a/django/contrib/gis/geos/polygon.py b/django/contrib/gis/geos/polygon.py
index 845c440e53..26fcfbf42a 100644
--- a/django/contrib/gis/geos/polygon.py
+++ b/django/contrib/gis/geos/polygon.py
@@ -2,7 +2,7 @@ from ctypes import byref, c_uint
from django.contrib.gis.geos import prototypes as capi
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
@@ -86,10 +86,8 @@ class Polygon(GEOSGeometry):
n_holes = length - 1
if n_holes:
- holes = get_pointer_arr(n_holes)
- for i, r in enumerate(rings):
- holes[i] = self._clone(r)
- holes_param = byref(holes)
+ holes = (GEOM_PTR * n_holes)(*[self._clone(r) for r in rings])
+ holes_param = byref(holes)
else:
holes_param = None