方便的地理空间数据处理。

meridian的Python项目详细描述


子午线

PyPI version

python的高级地理空间数据抽象。

meridian允许您像对待普通python数据结构一样对待地理空间数据集,并由用于高性能地理空间查询的空间索引支持。

用法

所实现的核心数据结构是SpatialDataset,它接受GeoJSON-结构化dicts的iterable(listgenerator)并建立数据集和索引。数据集中的记录存储在SpatialDatasetas SpatialData对象中,geojson的properties中的所有键/值对都是属性。加载完成后,您将拥有一个熟悉的感觉数据结构,可以用来查询数据集。

meridianfiona库生成的类似geojson的对象完全兼容,这使得启动变得非常容易:

importfionafrommeridianimportSpatialDatasetfromshapelyimportgeometrywithfiona.open('/path/to/my/shapefile.shp')assrc:dataset=SpatialDataset(src)# Find out how many records you haveprint(len(dataset))poi=geometry.shape({'type':'Point','coordinates':[-72.319261,43.648956]})# Check if your poi intersects with the datasetprint(dataset.intersects(poi))# True# See how many records intersectprint(dataset.count(poi))# 1# Find the n nearest records to the query geometryprint(dataset.nearest(poi,3))# The dataset itself is iterable.forrecordindataset:print(record)# iterate through all records in the dataset which bbox-intersect with poi# dataset.intersection returns a list of spatialdata objectsforrecordindataset.intersection(poi):print(record)

一个SpatialDataset上的所有空间查询方法只需要查询对象有一个bounds属性,该属性返回一个类似(xmin, ymin, xmax, ymax)的4元组。只要存在,^ {< CD1> }是查询几何实现的不可知的,但是它在引擎盖下使用^ {CD15> }几何图形来记录存储在其中的记录。

aSpatialDataset中的记录是SpatialDatas:

poi=geometry.shape({'type':'Point','coordinates':[-72.319261,43.648956]})forrecordindataset:print(record.id)# The id in the `id` field of the input geojsonprint(record.geom)# The `shapely` geometry representation of the recordprint(record.bounds)# The bounds of the geometryprint(record.properties)# a dict of all the `properties` in the initial geojson featureprint(record.my_fancy_property)# All individual properties in the geojson feature will be exposed as attributes on the namedtuple# SpatialData objects are fully compatible with all of the objects & operations defined in the shapely package.print(record.intersects(poi))print(poi.intersects(record))# Even advanced operations like cascaded union work as expected.fromshapely.opsimportcascaded_unionunioned=cascaded_union(dataset)print(unioned.wkt)

由于id字段不是geojson规范的一部分,因此可以选择包含它;没有它,库将正常工作。但是,它确实为用户提供了唯一标识每个数据集中记录的方法。

安装

来自pypi

pip install meridian

或者,克隆回购协议并运行

python path/to/repo/setup.py install

您还可以使用pip直接从github repo安装:

pip install git+git://github.com/tomplex/meridian.git

meridian需要geos(用于shapely库)和^{}来创建用于查询的空间索引。在大多数系统上,libspatialindex必须从源代码编译。这些说明应适用于Linux&MacOS:

wget -qO- http://download.osgeo.org/libspatialindex/spatialindex-src-1.8.5.tar.gz | tar xz -C /tmp
cd /tmp/spatialindex-src-1.8.5 && ./configure; make; make install

在linux上,您可能需要在之后运行ldconfig,以确保rtreepython库能够正确地找到库。

如果使用Docker,则会在docker hub上预安装有具有所有依赖项和最新版本meridian的图像。

找到了

数据占用内存。根据尝试使用的几何图形的数量和大小,可能会耗尽内存。在我的机器2016 MacBook Pro上,我发现一个有350k条记录的数据集,每个多边形平均有6个节点,占用了大约500MB的内存。YMMV公司。

meridian固执己见,认为数据应该是不可变的。如果需要更改数据,则应创建表示输入+处理的新数据,而不是更改旧数据。因此,SpatialDataset在行为上更像是frozenset,而不是list

计划功能

  • 深入的文档和使用示例
  • 格式化compat。内置工具,帮助从其他格式(Postgres、WKT等)加载数据。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
雅加达。木卫一。WriteAbortedException:写入中止;JAVA木卫一。NotSerializableException   如果没有互联网连接,java“重启”应用程序   ant将我的Mac更新为最新的Java JDK时遇到的困难   java从边的文本文件创建网络   java多个枚举与一个枚举   使用XML进行JavaBean验证:字段上的多个相同约束   java Eclipse报告HTML警告以获得正确的(正如我假设的)代码   java使用Jackson从POJO数组生成JSON模式   在JTextPane java swing中填充行的rectange后无法与视图同步   如何编写Java字符串。格式化为ruby代码?   java如何使Hibernate标准只包含所需字段   在java中拆分字符串,更改字母和分组   mysql Java 1.8.0_60,MariaDB v10。0和mariadbjavaclient 1.2.2,“未找到合适的驱动程序”   java试图做一个简单的计算,结果不正确   javatomcat远程访问   java我安装了安卓 studio,创建了我的第一个项目,面对这个错误。。。我点击了所有链接,但什么都没发生   JavaSpring3。0注释   SwingJavaJLabel。setText()方法重载时不使用字符串