Skip to content

Commit

Permalink
Merge branch 'int-strtree' of github.com:Toblerity/Shapely into int-s…
Browse files Browse the repository at this point in the history
…trtree
  • Loading branch information
Sean Gillies committed Jul 7, 2021
2 parents f7caf0c + 8d16c7e commit 5c31b1f
Show file tree
Hide file tree
Showing 42 changed files with 383 additions and 160 deletions.
21 changes: 4 additions & 17 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,11 @@ on: [push, pull_request]
jobs:
test:
name: Python ${{ matrix.python }} (GEOS ${{ matrix.geos }}, speedups ${{ matrix.speedups }}, numpy ${{ matrix.numpy || 'not installed' }})
# runs-on: ubuntu-latest
runs-on: ubuntu-16.04
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
# 2015
- python: 3.5
geos: 3.5.2
numpy: 1.10.4
speedups: 1
- python: 3.5
geos: 3.5.2
numpy: 1.10.4
speedups: 0
- python: 3.5
geos: 3.5.2
speedups: 0
# 2017
- python: 3.6
geos: 3.6.4
Expand Down Expand Up @@ -73,7 +60,7 @@ jobs:
speedups: 0
# dev
- python: 3.9
geos: master
geos: main
speedups: 1

env:
Expand Down Expand Up @@ -108,7 +95,7 @@ jobs:
run: |
pip install --disable-pip-version-check --upgrade pip
pip install --upgrade wheel
if [ "$GEOS_VERSION" = "master" ]; then
if [ "$GEOS_VERSION" = "main" ]; then
pip install --upgrade --pre Cython numpy;
elif [ "$SPEEDUPS" == "1" ]; then
pip install --install-option="--no-cython-compile" cython;
Expand Down Expand Up @@ -139,7 +126,7 @@ jobs:
- name: Run tests
shell: bash
continue-on-error: ${{ matrix.geos == 'master' }}
continue-on-error: ${{ matrix.geos == 'main' }}
run: |
if [ "$SPEEDUPS" == "1" ]; then SPEEDUPS_FLAG=--with-speedups; else SPEEDUPS_FLAG=--without-speedups; fi
python -c "from shapely import geos; print(geos.geos_version_string)"
Expand Down
11 changes: 11 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changes
1.8a2 (TBD)
-----------

Python version support:

Shapely 1.8 will support only Python versions >= 3.6.

New features:

- The STRtree class constructor now takes an optional second argument, a
Expand All @@ -15,6 +19,9 @@ New features:

Bug fixes:

- GEOS error messages printed when GEOS_getCoordSeq() is passed an empty
geometry are avoided by never passing an empty geometry (#1134).
- Python's builtin super() is now used only as described in PEP 3135 (#1109).
- Only load conda GEOS dll if it exists (on Windows) (#1108).

1.8a1 (2021-03-03)
Expand All @@ -24,6 +31,10 @@ Shapely 1.8.0 will be a transitional version. There are a few bug fixes and new
features, but it is mainly about warning of the upcoming changes in 2.0.0.
Several more pre-releases before 1.8.0 are expected.

Python version support:

Shapely 1.8 will support only Python versions >= 3.5 (#884).

Deprecations:

The following functions and geometry attributes and methods will be removed in
Expand Down
1 change: 1 addition & 0 deletions CREDITS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Shapely is written by:
* David Swinkels <davidswinkelss@gmail.com>
* Denis Rykov <rykovd@gmail.com>
* Erwin Sterrenburg <e.w.sterrenburg@gmail.com>
* Felix Divo <4403130+felixdivo@users.noreply.github.com>
* Felix Yan <felixonmars@archlinux.org>
* Filipe Fernandes <ocefpaf@gmail.com>
* Frédéric Junod <frederic.junod@camptocamp.com>
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ See the manual for more examples and guidance.
Requirements
============

Shapely 1.7 requires
Shapely 1.8 requires

* Python 2.7, >=3.5
* Python >=3.6
* GEOS >=3.3

Installing Shapely
Expand Down
4 changes: 2 additions & 2 deletions _vendor/packaging/_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import absolute_import, division, print_function


class Infinity(object):
class Infinity:

def __repr__(self):
return "Infinity"
Expand Down Expand Up @@ -36,7 +36,7 @@ def __neg__(self):
Infinity = Infinity()


class NegativeInfinity(object):
class NegativeInfinity:

def __repr__(self):
return "-Infinity"
Expand Down
4 changes: 2 additions & 2 deletions _vendor/packaging/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class UndefinedEnvironmentName(ValueError):
"""


class Node(object):
class Node:

def __init__(self, value):
self.value = value
Expand Down Expand Up @@ -254,7 +254,7 @@ def default_environment():
}


class Marker(object):
class Marker:

def __init__(self, marker):
try:
Expand Down
2 changes: 1 addition & 1 deletion _vendor/packaging/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class InvalidRequirement(ValueError):
REQUIREMENT = stringStart + NAMED_REQUIREMENT + stringEnd


class Requirement(object):
class Requirement:
"""Parse a requirement.
Parse a given requirement string into its parts, such as name, specifier,
Expand Down
2 changes: 1 addition & 1 deletion _vendor/packaging/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class InvalidVersion(ValueError):
"""


class _BaseVersion(object):
class _BaseVersion:

def __hash__(self):
return hash(self._key)
Expand Down
3 changes: 0 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ environment:

matrix:
# Interleave PYTHON, ARCH and GEOS_VERSION
- PYTHON: "C:\\Python35-x64"
ARCH: x64
GEOS_VERSION: "3.5.2"
- PYTHON: "C:\\Python36"
ARCH: x86
GEOS_VERSION: "3.6.4"
Expand Down
5 changes: 3 additions & 2 deletions ci/install_geos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# This script requires environment variables to be set
# - export GEOS_INSTALL=/path/to/cached/prefix -- to build or use as cache
# - export GEOS_VERSION=3.7.3 or master -- to download and compile
# - export GEOS_VERSION=3.7.3 or main -- to download and compile

set -e

Expand Down Expand Up @@ -38,11 +38,12 @@ build_geos(){
make install
}

if [ "$GEOS_VERSION" = "master" ]; then
if [ "$GEOS_VERSION" = "main" ]; then
prepare_geos_build_dir
# use GitHub mirror
git clone --depth 1 https://github.com/libgeos/geos.git geos-$GEOS_VERSION
cd geos-$GEOS_VERSION
git log -1
git rev-parse HEAD > newrev.txt
BUILD=no
# Only build if nothing cached or if the GEOS revision changed
Expand Down
37 changes: 37 additions & 0 deletions docs/code/buffer_single_side.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from matplotlib import pyplot
from shapely.geometry import LineString
from descartes import PolygonPatch

from figures import SIZE, BLUE, GRAY, set_limits, plot_line

line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])

fig = pyplot.figure(1, figsize=SIZE, dpi=90)

# 1
ax = fig.add_subplot(121)

plot_line(ax, line)

left_hand_side = line.buffer(0.5, single_sided=True)
patch1 = PolygonPatch(left_hand_side, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2)
ax.add_patch(patch1)

ax.set_title('a) left hand buffer')

set_limits(ax, -1, 4, -1, 3)

#2
ax = fig.add_subplot(122)

plot_line(ax, line)

right_hand_side = line.buffer(-0.3, single_sided=True)
patch2 = PolygonPatch(right_hand_side, fc=GRAY, ec=GRAY, alpha=0.5, zorder=1)
ax.add_patch(patch2)

ax.set_title('b) right hand buffer')

set_limits(ax, -1, 4, -1, 3)

pyplot.show()
71 changes: 60 additions & 11 deletions docs/manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ Shapely's binary :meth:`within` predicate.

.. code-block:: python
class Within(object):
class Within:
def __init__(self, o):
self.o = o
def __lt__(self, other):
Expand Down Expand Up @@ -1570,7 +1570,7 @@ Constructive Methods
Shapely geometric object have several methods that yield new objects not
derived from set-theoretic analysis.

.. method:: object.buffer(distance, resolution=16, cap_style=1, join_style=1, mitre_limit=5.0)
.. method:: object.buffer(distance, resolution=16, cap_style=1, join_style=1, mitre_limit=5.0, single_sided=False)

Returns an approximate representation of all points within a given `distance`
of the this geometric object.
Expand Down Expand Up @@ -1647,6 +1647,28 @@ With a `resolution` of 1, the buffer is a square patch.
>>> q.area
200.0
You may want a buffer only on one side. You can achieve this effect with
`single_sided` option.

The side used is determined by the sign of the buffer distance:

- a positive distance indicates the left-hand side
- a negative distance indicates the right-hand side

.. code-block:: pycon
>>> line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])
>>> left_hand_side = line.buffer(0.5, single_sided=True)
>>> right_hand_side = line.buffer(-0.3, single_sided=True)
.. plot:: code/buffer_single_side.py

Figure 10. Single sided buffer of 0.5 left hand (left) and of 0.3 right hand (right).

The single-sided buffer of point geometries is the same as the regular buffer.
The End Cap Style for single-sided buffers is always ignored, and forced to
the equivalent of `CAP_STYLE.flat`.

Passed a `distance` of 0, :meth:`buffer` can sometimes be used to "clean" self-touching
or self-crossing polygons such as the classic "bowtie". Users have reported
that very small distance values sometimes produce cleaner results than 0. Your
Expand Down Expand Up @@ -1690,7 +1712,7 @@ Buffering splits the polygon in two at the point where they touch.
.. plot:: code/convex_hull.py

Figure 10. Convex hull (blue) of 2 points (left) and of 6 points (right).
Figure 11. Convex hull (blue) of 2 points (left) and of 6 points (right).

.. attribute:: object.envelope

Expand Down Expand Up @@ -1722,7 +1744,7 @@ Figure 10. Convex hull (blue) of 2 points (left) and of 6 points (right).
.. plot:: code/minimum_rotated_rectangle.py

Figure 11. Minimum rotated rectangle for a multipoint feature (left) and a
Figure 12. Minimum rotated rectangle for a multipoint feature (left) and a
linestring feature (right).

.. method:: object.parallel_offset(distance, side, resolution=16, join_style=1, mitre_limit=5.0)
Expand Down Expand Up @@ -1762,15 +1784,15 @@ linestring feature (right).

.. plot:: code/parallel_offset.py

Figure 12. Three styles of parallel offset lines on the left side of a simple
Figure 13. Three styles of parallel offset lines on the left side of a simple
line string (its starting point shown as a circle) and one offset on the right
side, a multipart.

The effect of the `mitre_limit` parameter is shown below.

.. plot:: code/parallel_offset_mitre.py

Figure 13. Large and small mitre_limit values for left and right offsets.
Figure 14. Large and small mitre_limit values for left and right offsets.

.. method:: object.simplify(tolerance, preserve_topology=True)

Expand All @@ -1797,7 +1819,7 @@ Douglas-Peucker algorithm [6]_ is used.
.. plot:: code/simplify.py

Figure 14. Simplification of a nearly circular polygon using a tolerance of 0.2
Figure 15. Simplification of a nearly circular polygon using a tolerance of 0.2
(left) and 0.5 (right).

.. note::
Expand Down Expand Up @@ -1925,7 +1947,7 @@ preserved or supported by 3D affine transformations.
.. plot:: code/rotate.py

Figure 15. Rotation of a `LineString` (gray) by an angle of 90°
Figure 16. Rotation of a `LineString` (gray) by an angle of 90°
counter-clockwise (blue) using different origins.

.. function:: shapely.affinity.scale(geom, xfact=1.0, yfact=1.0, zfact=1.0, origin='center')
Expand Down Expand Up @@ -1967,7 +1989,7 @@ preserved or supported by 3D affine transformations.
.. plot:: code/scale.py

Figure 16. Scaling of a gray triangle to blue result: a) by a factor of 1.5
Figure 17. Scaling of a gray triangle to blue result: a) by a factor of 1.5
along x-direction, with reflection across y-axis; b) by a factor of 2 along
x-direction with custom origin at (1, 1).

Expand Down Expand Up @@ -1999,7 +2021,7 @@ preserved or supported by 3D affine transformations.
.. plot:: code/skew.py

Figure 17. Skewing of a gray "R" to blue result: a) by a shear angle of 20°
Figure 18. Skewing of a gray "R" to blue result: a) by a shear angle of 20°
along the x-direction and an origin at (1, 1); b) by a shear angle of 30°
along the y-direction, using default origin.

Expand Down Expand Up @@ -2186,6 +2208,33 @@ using functions in the :mod:`shapely.ops` module.
<shapely.geometry.linestring.LineString object at 0x...>,
<shapely.geometry.linestring.LineString object at 0x...>]
Efficient Rectangle Clipping
----------------------------
The :func:`~shapely.ops.clip_by_rect` function in `shapely.ops` returns the
portion of a geometry within a rectangle.

.. function:: shapely.ops.clip_by_rect(geom, xmin, ymin, xmax, ymax)

The geometry is clipped in a fast but possibly dirty way. The output is
not guaranteed to be valid. No exceptions will be raised for topological
errors.

`New in version 1.7.`

Requires GEOS 3.5.0 or higher

.. code-block:: python
>>> from shapely.geometry import Polygon
>>> from shapely.ops import clip_by_rect
>>> polygon = Polygon(
shell=[(0, 0), (0, 30), (30, 30), (30, 0), (0, 0)],
holes=[[(10, 10), (20, 10), (20, 20), (10, 20), (10, 10)]],
)
>>> clipped_polygon = clip_by_rect(polygon, 5, 5, 15, 15)
>>> print(clipped_polygon.wkt)
POLYGON ((5 5, 5 15, 10 15, 10 10, 15 10, 15 5, 5 5))
Efficient Unions
----------------

Expand Down Expand Up @@ -2835,7 +2884,7 @@ Or a simple placemark-type object:

.. code-block:: pycon
>>> class GeoThing(object):
>>> class GeoThing:
... def __init__(self, d):
... self.__geo_interface__ = d
>>> thing = GeoThing({"type": "Point", "coordinates": (0.0, 0.0)})
Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[tool:pytest]
testpaths = tests
addopts = --ignore _vendor --ignore shapely/examples

[bdist_wheel]
universal=1

0 comments on commit 5c31b1f

Please sign in to comment.