Skip to main content

GEOS wrapped in numpy ufuncs

Project description

This is a C/Python library that wraps geometry functions in GEOS in numpy ufuncs. This project is still in a mock-up phase: the API will most likely change.

The Geometry object

GEOS geometry objects are stored in a Python extension type pygeos.GEOSGeometry, that keeps the python interpreter out of the numpy ufunc inner loop. This object calls the GEOS destroy function to deallocate memory just before the wrapping GEOSGeometry object is deallocated.

Ufuncs only act on these pygeos.GEOSGeometry objects. Construct these as follows. This operation copies the underlying C object so that we can safely deallocate it once point is garbage collected:

>>> from pygeos import GEOSGeometry
>>> from shapely.geometry import Point

>>> pointer_to_geometry = Point(i, j)._geom
>>> geometry = GEOSGeometry(pointer_to_geometry)

Or simply:

>>> from pygeos import points

>>> point = points(5.2, 52.1)

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.]])

Installation

Pygeos uses shapely’s installing scripts. If you have libgeos at a standard location, the following should work:

$ pip install pygeos

Installation for developers

Clone the package:

$ git clone https://github.com/caspervdw/pygeos.git

Install it using pip:

$ pip install -e .

Run the unittests:

$ python -m pytest pygeos/test.py

References

Project details


Download files

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

Source Distribution

pygeos-0.2.tar.gz (14.6 kB view details)

Uploaded Source

File details

Details for the file pygeos-0.2.tar.gz.

File metadata

  • Download URL: pygeos-0.2.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5

File hashes

Hashes for pygeos-0.2.tar.gz
Algorithm Hash digest
SHA256 cfecdc449027dff9371e753232d1d29070e209fb18d97df1ad1057658ad2e480
MD5 ab8555ae75e7c870ad331da813d14a31
BLAKE2b-256 1a7fb6788a51230356ddf663fe743d6aa92dda012de72dd5b60066ff076d859c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page