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 Array dtype

Shapely geometries are stored in structured numpy arrays with the following structure:

np.dtype([("obj", "O"), ("_ptr", "intp")])

In this way, we enable fast C-access to the geometries, while keeping a python object close to keep track of the memory allocation/deallocation.

The ufuncs automatically converts a (iterable of) shapely geometry to this Geometry Array dtype. Functions that return geometries will return this custom dtype.

Examples

Compare an grid of points with a polygon:

>>> from pygeos import contains
>>> from shapely.geometry import box, Point

>>> points = [[Point(i, j) for i in range(4)] for j in range(4)]
>>> polygon = box(0, 0, 2, 2)

>>> contains(polygon, points)

  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 area, intersection
>>> from shapely.geometry import box

>>> polygons_x = [[box(0 + i, 0, 10 + i, 10) for i in range(5)]]
>>> polygons_y = [[box(0, 0 + j, 10, 10 + j)] for j in range(5)]

>>> area(intersection(polygons_x, polygons_y))

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.1.tar.gz (7.9 kB view hashes)

Uploaded Source

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