Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release the GIL for geometry-creating operations #156

Merged
merged 21 commits into from Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 14 additions & 12 deletions pygeos/constructive.py
Expand Up @@ -2,7 +2,7 @@
import numpy as np
from . import Geometry # NOQA
from . import lib
from .decorators import requires_geos
from .decorators import requires_geos, multithreading_enabled


__all__ = [
Expand Down Expand Up @@ -36,7 +36,7 @@ class BufferJoinStyles(IntEnum):
MITRE = 2
BEVEL = 3


@multithreading_enabled
def boundary(geometry, **kwargs):
"""Returns the topological boundary of a geometry.

Expand All @@ -60,7 +60,7 @@ def boundary(geometry, **kwargs):
"""
return lib.boundary(geometry, **kwargs)


@multithreading_enabled
def buffer(
geometry,
radius,
Expand Down Expand Up @@ -162,7 +162,7 @@ def buffer(
**kwargs
)


@multithreading_enabled
def centroid(geometry, **kwargs):
"""Computes the geometric center (center-of-mass) of a geometry.

Expand All @@ -188,7 +188,7 @@ def centroid(geometry, **kwargs):
"""
return lib.centroid(geometry, **kwargs)


@multithreading_enabled
def convex_hull(geometry, **kwargs):
"""Computes the minimum convex geometry that encloses an input geometry.

Expand All @@ -205,7 +205,7 @@ def convex_hull(geometry, **kwargs):
"""
return lib.convex_hull(geometry, **kwargs)


@multithreading_enabled
def delaunay_triangles(geometry, tolerance=0.0, only_edges=False, **kwargs):
"""Computes a Delaunay triangulation around the vertices of an input
geometry.
Expand Down Expand Up @@ -241,7 +241,7 @@ def delaunay_triangles(geometry, tolerance=0.0, only_edges=False, **kwargs):
"""
return lib.delaunay_triangles(geometry, tolerance, only_edges, **kwargs)


@multithreading_enabled
def envelope(geometry, **kwargs):
"""Computes the minimum bounding box that encloses an input geometry.

Expand All @@ -262,7 +262,7 @@ def envelope(geometry, **kwargs):
"""
return lib.envelope(geometry, **kwargs)


@multithreading_enabled
def extract_unique_points(geometry, **kwargs):
"""Returns all distinct vertices of an input geometry as a multipoint.

Expand Down Expand Up @@ -290,6 +290,7 @@ def extract_unique_points(geometry, **kwargs):


@requires_geos("3.8.0")
@multithreading_enabled
def build_area(geometry, **kwargs):
"""Creates an areal geometry formed by the constituent linework of given geometry.

Expand All @@ -310,6 +311,7 @@ def build_area(geometry, **kwargs):


@requires_geos("3.8.0")
@multithreading_enabled
def make_valid(geometry, **kwargs):
"""Repairs invalid geometries.

Expand All @@ -326,7 +328,7 @@ def make_valid(geometry, **kwargs):
"""
return lib.make_valid(geometry, **kwargs)


@multithreading_enabled
def normalize(geometry, **kwargs):
"""Converts Geometry to normal form (or canonical form).

Expand All @@ -346,7 +348,7 @@ def normalize(geometry, **kwargs):
"""
return lib.normalize(geometry, **kwargs)


@multithreading_enabled
def point_on_surface(geometry, **kwargs):
"""Returns a point that intersects an input geometry.

Expand All @@ -367,7 +369,7 @@ def point_on_surface(geometry, **kwargs):
"""
return lib.point_on_surface(geometry, **kwargs)


@multithreading_enabled
def simplify(geometry, tolerance, preserve_topology=False, **kwargs):
"""Returns a simplified version of an input geometry using the
Douglas-Peucker algorithm.
Expand Down Expand Up @@ -428,7 +430,7 @@ def snap(geometry, reference, tolerance, **kwargs):
"""
return lib.snap(geometry, reference, tolerance, **kwargs)


@multithreading_enabled
def voronoi_polygons(
geometry, tolerance=0.0, extend_to=None, only_edges=False, **kwargs
):
Expand Down
3 changes: 2 additions & 1 deletion pygeos/creation.py
@@ -1,6 +1,7 @@
import numpy as np
from . import lib
from . import Geometry, GeometryType
from .decorators import multithreading_enabled

__all__ = [
"points",
Expand Down Expand Up @@ -70,7 +71,7 @@ def linearrings(coords, y=None, z=None):
"""
return _wrap_construct_ufunc(lib.linearrings, coords, y, z)


@multithreading_enabled
def polygons(shells, holes=None):
"""Create an array of polygons.

Expand Down
8 changes: 4 additions & 4 deletions pygeos/geometry.py
Expand Up @@ -249,7 +249,7 @@ def get_y(point):

# linestrings


@multithreading_enabled
def get_point(geometry, index):
"""Returns the nth point of a linestring or linearring.

Expand Down Expand Up @@ -310,7 +310,7 @@ def get_num_points(geometry):

# polygons


@multithreading_enabled
def get_exterior_ring(geometry):
"""Returns the exterior ring of a polygon.

Expand All @@ -331,7 +331,7 @@ def get_exterior_ring(geometry):
"""
return lib.get_exterior_ring(geometry)


@multithreading_enabled
def get_interior_ring(geometry, index):
"""Returns the nth interior ring of a polygon.

Expand Down Expand Up @@ -387,7 +387,7 @@ def get_num_interior_rings(geometry):

# collections


@multithreading_enabled
def get_geometry(geometry, index):
"""Returns the nth geometry from a collection of geometries.

Expand Down
4 changes: 2 additions & 2 deletions pygeos/linear.py
Expand Up @@ -4,7 +4,7 @@

__all__ = ["line_interpolate_point", "line_locate_point", "line_merge", "shared_paths"]


@multithreading_enabled
def line_interpolate_point(line, distance, normalize=False):
"""Returns a point interpolated at given distance on a line.

Expand Down Expand Up @@ -70,7 +70,7 @@ def line_locate_point(line, other, normalize=False):
else:
return lib.line_locate_point(line, other)


@multithreading_enabled
def line_merge(line):
"""Returns (multi)linestrings formed by combining the lines in a
multilinestrings.
Expand Down
15 changes: 8 additions & 7 deletions pygeos/set_operations.py
@@ -1,5 +1,6 @@
import numpy as np
from . import lib, Geometry, GeometryType
from .decorators import multithreading_enabled

__all__ = [
"difference",
Expand All @@ -11,7 +12,7 @@
"union_all",
]


@multithreading_enabled
def difference(a, b, **kwargs):
"""Returns the part of geometry A that does not intersect with geometry B.

Expand All @@ -32,7 +33,7 @@ def difference(a, b, **kwargs):
"""
return lib.difference(a, b, **kwargs)


@multithreading_enabled
def intersection(a, b, **kwargs):
"""Returns the geometry that is shared between input geometries.

Expand All @@ -53,7 +54,7 @@ def intersection(a, b, **kwargs):
"""
return lib.intersection(a, b, **kwargs)


@multithreading_enabled
def intersection_all(geometries, axis=0, **kwargs):
"""Returns the intersection of multiple geometries.

Expand Down Expand Up @@ -81,7 +82,7 @@ def intersection_all(geometries, axis=0, **kwargs):
"""
return lib.intersection.reduce(geometries, axis=axis, **kwargs)


@multithreading_enabled
def symmetric_difference(a, b, **kwargs):
"""Returns the geometry that represents the portions of input geometries
that do not intersect.
Expand All @@ -103,7 +104,7 @@ def symmetric_difference(a, b, **kwargs):
"""
return lib.symmetric_difference(a, b, **kwargs)


@multithreading_enabled
def symmetric_difference_all(geometries, axis=0, **kwargs):
"""Returns the symmetric difference of multiple geometries.

Expand Down Expand Up @@ -131,7 +132,7 @@ def symmetric_difference_all(geometries, axis=0, **kwargs):
"""
return lib.symmetric_difference.reduce(geometries, axis=axis, **kwargs)


@multithreading_enabled
def union(a, b, **kwargs):
"""Merges geometries into one.

Expand All @@ -154,7 +155,7 @@ def union(a, b, **kwargs):
"""
return lib.union(a, b, **kwargs)


@multithreading_enabled
def union_all(geometries, axis=0, **kwargs):
"""Returns the union of multiple geometries.

Expand Down
3 changes: 2 additions & 1 deletion pygeos/test/test_set_operations.py
Expand Up @@ -21,6 +21,7 @@
pygeos.box(0, 0, 5, 5),
pygeos.box(2, 2, 7, 7),
pygeos.box(4, 4, 9, 9),
pygeos.box(5, 5, 10, 10),
]


Expand All @@ -32,7 +33,7 @@ def test_set_operation_array(a, func):
assert isinstance(actual[0], Geometry)


@pytest.mark.parametrize("n", range(1, 4))
@pytest.mark.parametrize("n", range(1, 5))
@pytest.mark.parametrize("func, related_func", REDUCE_SET_OPERATIONS)
def test_set_operation_reduce_1dim(n, func, related_func):
actual = func(reduce_test_data[:n])
Expand Down