跳转到主要内容

几何对象的操作和分析

项目描述

Documentation Status Travis CI status PyPI Anaconda

笛卡尔平面上几何对象的操作和分析。

https://c2.staticflickr.com/6/5560/31301790086_b3472ea4e9_c.jpg

Shapely是一个BSD许可的Python包,用于平面几何对象的操作和分析。它使用了广泛部署的开源几何库GEOSPostGIS的引擎和JTS的移植)。Shapely包装了GEOS几何和操作,为单个(标量)几何提供了功能丰富的Geometry接口,并为使用几何数组操作提供了高性能的NumPy ufunc。Shapely主要不关注数据序列化格式或坐标系,但可以轻松与这些包集成。

什么是ufunc?

通用函数(或简称为ufunc)是一种对n维数组进行逐元素操作并支持数组广播的函数。底层循环是用C实现的,以减少Python解释器的开销。

多线程

Shapely函数通常通过在执行过程中释放全局解释器锁(GIL)来支持多线程。在Python中,GIL通常阻止多个线程同时计算。Shapely函数内部释放了这个限制,以便GEOS可以并行执行,而无需启动多个Python进程。

使用方法

以下是一个使用标量Geometry接口通过缓冲点构建近似圆形区域的典型示例

>>> from shapely import Point
>>> patch = Point(0.0, 0.0).buffer(10.0)
>>> patch
<POLYGON ((10 0, 9.952 -0.98, 9.808 -1.951, 9.569 -2.903, 9.239 -3.827, 8.81...>
>>> patch.area
313.6548490545941

使用向量化ufunc接口(而不是使用手动循环),比较点数组和多边形

>>> import shapely
>>> import numpy as np
>>> geoms = np.array([Point(0, 0), Point(1, 1), Point(2, 2)])
>>> polygon = shapely.box(0, 0, 2, 2)

>>> shapely.contains(polygon, geoms)
array([False,  True, False])

请参阅文档以获取更多示例和指导:https://shapely.readthedocs.io

需求

Shapely 2.0需要

  • Python >=3.7

  • GEOS >=3.5

  • NumPy >=1.14

安装Shapely

我们建议使用可用的构建分发版之一安装Shapely,例如使用

pip

conda

$ pip install shapely
# or using conda
$ conda install shapely --channel conda-forge

请参阅安装文档以获取更多详细信息和高级安装说明。

集成

Shapely不读取或写入数据文件,但它可以使用几种知名格式和协议进行序列化和反序列化。shapely.wkb和shapely.wkt模块提供了受Python的pickle模块启发的dumper和loader。

>>> from shapely.wkt import dumps, loads
>>> dumps(loads('POINT (0 0)'))
'POINT (0.0000000000000000 0.0000000000000000)'

Shapely还可以通过GeoJSON-like字典与其它Python GIS包集成。

>>> import json
>>> from shapely.geometry import mapping, shape
>>> s = shape(json.loads('{"type": "Point", "coordinates": [0.0, 0.0]}'))
>>> s
<POINT (0 0)>
>>> print(json.dumps(mapping(s)))
{"type": "Point", "coordinates": [0.0, 0.0]}

支持

有关使用Shapely的问题,可以在使用“shapely”标签的GIS StackExchange上提问。

可以在https://github.com/shapely/shapely/issues上报告错误。

项目详情


发行历史 发布通知 | RSS源

下载文件

下载适用于您平台的应用程序文件。如果您不确定选择哪个,请了解有关安装包的更多信息

源代码分布

shapely-2.0.6.tar.gz (282.4 kB 查看哈希值)

上传时间 源代码

构建分布

shapely-2.0.6-cp313-cp313-win_amd64.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.13 Windows x86-64

shapely-2.0.6-cp313-cp313-win32.whl (1.3 MB 查看哈希值)

上传时间 CPython 3.13 Windows x86

shapely-2.0.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB 查看哈希值)

上传时间 CPython 3.13 manylinux: glibc 2.17+ x86-64

shapely-2.0.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB 查看哈希值)

上传时间 CPython 3.13 manylinux: glibc 2.17+ ARM64

shapely-2.0.6-cp313-cp313-macosx_11_0_arm64.whl (1.3 MB 查看哈希值)

上传时间 CPython 3.13 macOS 11.0+ ARM64

shapely-2.0.6-cp313-cp313-macosx_10_13_x86_64.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.13 macOS 10.13+ x86-64

shapely-2.0.6-cp312-cp312-win_amd64.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.12 Windows x86-64

shapely-2.0.6-cp312-cp312-win32.whl (1.3 MB 查看哈希值)

上传于 CPython 3.12 Windows x86

shapely-2.0.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB 查看哈希值)

上传于 CPython 3.12 manylinux: glibc 2.17+ x86-64

shapely-2.0.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB 查看哈希值)

上传于 CPython 3.12 manylinux: glibc 2.17+ ARM64

shapely-2.0.6-cp312-cp312-macosx_11_0_arm64.whl (1.3 MB 查看哈希值)

上传于 CPython 3.12 macOS 11.0+ ARM64

shapely-2.0.6-cp312-cp312-macosx_10_9_x86_64.whl (1.5 MB 查看哈希值)

上传于 CPython 3.12 macOS 10.9+ x86-64

shapely-2.0.6-cp311-cp311-win_amd64.whl (1.4 MB 查看哈希值)

上传于 CPython 3.11 Windows x86-64

shapely-2.0.6-cp311-cp311-win32.whl (1.3 MB 查看哈希值)

上传于 CPython 3.11 Windows x86

shapely-2.0.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ x86-64

shapely-2.0.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ ARM64

shapely-2.0.6-cp311-cp311-macosx_11_0_arm64.whl (1.3 MB 查看哈希值)

上传于 CPython 3.11 macOS 11.0+ ARM64

shapely-2.0.6-cp311-cp311-macosx_10_9_x86_64.whl (1.4 MB 查看哈希值)

上传于 CPython 3.11 macOS 10.9+ x86-64

shapely-2.0.6-cp310-cp310-win_amd64.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.10 Windows x86-64

shapely-2.0.6-cp310-cp310-win32.whl (1.3 MB 查看哈希值)

上传时间 CPython 3.10 Windows x86

shapely-2.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB 查看哈希值)

上传时间 CPython 3.10 manylinux: glibc 2.17+ x86-64

shapely-2.0.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB 查看哈希值)

上传时间 CPython 3.10 manylinux: glibc 2.17+ ARM64

shapely-2.0.6-cp310-cp310-macosx_11_0_arm64.whl (1.3 MB 查看哈希值)

上传时间 CPython 3.10 macOS 11.0+ ARM64

shapely-2.0.6-cp310-cp310-macosx_10_9_x86_64.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.10 macOS 10.9+ x86-64

shapely-2.0.6-cp39-cp39-win_amd64.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.9 Windows x86-64

shapely-2.0.6-cp39-cp39-win32.whl (1.3 MB 查看哈希值)

上传时间 CPython 3.9 Windows x86

shapely-2.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB 查看哈希值)

上传时间 CPython 3.9 manylinux: glibc 2.17+ x86-64

shapely-2.0.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB 查看哈希值)

上传时间 CPython 3.9 manylinux: glibc 2.17+ ARM64

shapely-2.0.6-cp39-cp39-macosx_11_0_arm64.whl (1.3 MB 查看哈希值)

上传于 CPython 3.9 macOS 11.0+ ARM64

shapely-2.0.6-cp39-cp39-macosx_10_9_x86_64.whl (1.5 MB 查看哈希值)

上传于 CPython 3.9 macOS 10.9+ x86-64

shapely-2.0.6-cp38-cp38-win_amd64.whl (1.5 MB 查看哈希值)

上传于 CPython 3.8 Windows x86-64

shapely-2.0.6-cp38-cp38-win32.whl (1.3 MB 查看哈希值)

上传于 CPython 3.8 Windows x86

shapely-2.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.17+ x86-64

shapely-2.0.6-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.17+ ARM64

shapely-2.0.6-cp38-cp38-macosx_11_0_arm64.whl (1.3 MB 查看哈希值)

上传于 CPython 3.8 macOS 11.0+ ARM64

shapely-2.0.6-cp38-cp38-macosx_10_9_x86_64.whl (1.5 MB 查看哈希值)

上传于 CPython 3.8 macOS 10.9+ x86-64

shapely-2.0.6-cp37-cp37m-win_amd64.whl (1.5 MB 查看哈希值)

上传于 CPython 3.7m Windows x86-64

shapely-2.0.6-cp37-cp37m-win32.whl (1.3 MB 查看哈希值)

上传于 CPython 3.7m Windows x86

shapely-2.0.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB 查看哈希值)

上传于 CPython 3.7m manylinux: glibc 2.17+ x86-64

shapely-2.0.6-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB 查看哈希值)

上传时间: CPython 3.7m manylinux: glibc 2.17+ ARM64

shapely-2.0.6-cp37-cp37m-macosx_10_9_x86_64.whl (1.4 MB 查看哈希值)

上传时间: CPython 3.7m macOS 10.9+ x86-64

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面