Skip to main content

GEOS wrapped in numpy ufuncs

Project description

Documentation Status Travis CI status Appveyor CI status PyPI

PyGEOS is a C/Python library with vectorized geometry functions. The geometry operations are done in the open-source geometry library GEOS. PyGEOS wraps these operations in NumPy ufuncs providing a performance improvement when operating on arrays of geometries.

Note: PyGEOS is a very young package. While the available functionality should be stable and working correctly, it’s still possible that APIs change in upcoming releases. But we would love for you to try it out, give feedback or contribute!

What is a ufunc?

A universal function (or ufunc for short) is a function that operates on n-dimensional arrays in an element-by-element fashion, supporting array broadcasting. The for-loops that are involved are fully implemented in C diminishing the overhead of the Python interpreter.

Multithreading

PyGEOS functions support multithreading. More specifically, the Global Interpreter Lock (GIL) is released during function execution. Normally in Python, the GIL prevents multiple threads from computing at the same time. PyGEOS functions internally releases this constraint so that the heavy lifting done by GEOS can be done in parallel, from a single Python process.

The Geometry object

The pygeos.Geometry object is a container of the actual GEOSGeometry object. The Geometry object keeps track of the underlying GEOSGeometry and allows the python garbage collector to free memory when it is not used anymore.

Geometry objects are immutable. This means that after constructed, they cannot be changed inplace. Every PyGEOS operation will result in a new object being returned.

Construct a Geometry from a WKT (Well-Known Text):

>>> from pygeos import Geometry

>>> geometry = Geometry("POINT (5.2 52.1)")

Or using one of the provided (vectorized) functions:

>>> from pygeos import points

>>> point = points([(5.2, 52.1), (5.1, 52.2)]]

Examples

Compare an grid of points with a polygon:

>>> geoms = points(*np.indices((4, 4)))
>>> polygon = box(0, 0, 2, 2)

>>> contains(polygon, geoms)

  array([[False, False, False, False],
         [False,  True, False, False],
         [False, False, False, False],
         [False, False, False, False]])

Compute the area of all possible intersections of two lists of polygons:

>>> from pygeos import box, area, intersection

>>> polygons_x = box(range(5), 0, range(10, 15), 10)
>>> polygons_y = box(0, range(5), 10, range(10, 15))

>>> area(intersection(polygons_x[:, np.newaxis], polygons_y[np.newaxis, :]))

array([[100.,  90.,  80.,  70.,  60.],
     [ 90.,  81.,  72.,  63.,  54.],
     [ 80.,  72.,  64.,  56.,  48.],
     [ 70.,  63.,  56.,  49.,  42.],
     [ 60.,  54.,  48.,  42.,  36.]])

See the documentation for more: https://pygeos.readthedocs.io

Relationship to Shapely

Both Shapely and PyGEOS are exposing the functionality of the GEOS C++ library to Python. While Shapely only deals with single geometries, PyGEOS provides vectorized functions to work with arrays of geometries, giving better performance and convenience for such usecases.

There is active discussion and work toward integrating PyGEOS into Shapely:

For now PyGEOS is developed as a separate project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pygeos, version 0.8
Filename, size File type Python version Upload date Hashes
Filename, size pygeos-0.8-cp35-cp35m-manylinux1_x86_64.whl (1.6 MB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size pygeos-0.8-cp35-cp35m-win32.whl (569.2 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size pygeos-0.8-cp35-cp35m-win_amd64.whl (673.7 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size pygeos-0.8-cp36-cp36m-macosx_10_9_x86_64.whl (1.4 MB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size pygeos-0.8-cp36-cp36m-manylinux1_x86_64.whl (1.6 MB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size pygeos-0.8-cp36-cp36m-win32.whl (568.8 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size pygeos-0.8-cp36-cp36m-win_amd64.whl (673.0 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size pygeos-0.8-cp37-cp37m-macosx_10_9_x86_64.whl (1.4 MB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size pygeos-0.8-cp37-cp37m-manylinux1_x86_64.whl (1.6 MB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size pygeos-0.8-cp37-cp37m-win32.whl (568.8 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size pygeos-0.8-cp37-cp37m-win_amd64.whl (673.0 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size pygeos-0.8-cp38-cp38-macosx_10_9_x86_64.whl (1.4 MB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size pygeos-0.8-cp38-cp38-manylinux1_x86_64.whl (1.6 MB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size pygeos-0.8-cp38-cp38-win32.whl (569.0 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size pygeos-0.8-cp38-cp38-win_amd64.whl (673.1 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size pygeos-0.8.tar.gz (74.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page