跳转到主要内容

一个用于在GeoJSON中强制执行多边形环绕行顺序的Python库

项目描述

geojson-rewind

Run tests codecov PyPI Version License Python Compatibility Code style: black

一个用于在GeoJSON中强制执行多边形环绕行顺序的Python库

GeoJSON规范强制执行右手定则

线性环必须遵循相对于其包围区域的右手定则,即外部环为逆时针,孔为顺时针。

这有助于您生成符合规定的多边形和MultiPolygon几何形状。

注意:输入数据中的坐标假定是WGS84,(lon, lat)顺序,如RFC 7946中所述。使用任何其他CRS的坐标可能导致意外结果。

安装

pip install geojson-rewind

用法

作为库

强制执行RFC 7946环绕行顺序(输入/输出为GeoJSON字符串)

>>> from geojson_rewind import rewind

>>> input = """{
...      "geometry": {   "coordinates": [   [   [100, 0],
...                                             [100, 1],
...                                             [101, 1],
...                                             [101, 0],
...                                             [100, 0]]],
...                      "type": "Polygon"},
...      "properties": {"foo": "bar"},
...      "type": "Feature"}"""

>>> output = rewind(input)

>>> output
'{"geometry": {"coordinates": [[[100, 0], [101, 0], [101, 1], [100, 1], [100, 0]]], "type": "Polygon"}, "properties": {"foo": "bar"}, "type": "Feature"}'

>>> type(output)
<class 'str'>

强制执行RFC 7946环绕行顺序(输入/输出为python字典)

>>> from geojson_rewind import rewind

>>> input = {
...     'geometry': {   'coordinates': [   [   [100, 0],
...                                            [100, 1],
...                                            [101, 1],
...                                            [101, 0],
...                                            [100, 0]]],
...                     'type': 'Polygon'},
...     'properties': {'foo': 'bar'},
...     'type': 'Feature'}

>>> output = rewind(input)

>>> output
{'geometry': {'coordinates': [[[100, 0], [101, 0], [101, 1], [100, 1], [100, 0]]], 'type': 'Polygon'}, 'properties': {'foo': 'bar'}, 'type': 'Feature'}

>>> type(output)
<class 'dict'>

在控制台中

# Enforce ring winding order on a GeoJSON file
$ rewind in.geojson > out.geojson

# fetch GeoJSON from the web and enforce ring winding order
$ curl "https://myserver.com/in.geojson" | rewind

版本

geojson-rewind遵循语义版本控制。对于此项目,“API”还包括

  • CLI标志和选项
  • CLI退出代码

遵循Python社区中的常见做法,geojson-rewind将不会在不增加主版本的情况下与不支持Python版本兼容。

致谢

geojson-rewind是Mapbox的javascript geojson-rewind软件包的Python端口。感谢Tom MacWright贡献者

项目详情


下载文件

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

源分发

geojson_rewind-1.1.0.tar.gz (4.1 kB 查看哈希)

上传时间

构建分发

geojson_rewind-1.1.0-py3-none-any.whl (5.2 kB 查看哈希)

上传时间 Python 3

支持