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

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第三方库


热门话题
java Android使用两个后台服务错误   解压缩HTTPInputStream时,java GZIPInputStream过早关闭   javax和javax的区别是什么。网ssl。密钥库和服务器。ssl。为SpringBoot应用程序指定密钥库时的密钥库属性   java生成两个JPanel,而我只需要一个   java深度链接从play store安装应用程序时获取数据   java 安卓应用程序在退出时未正确释放蓝牙   java正确使用setCellValueFactory   java开放JdbcTemplate连接处于只读模式?   使用Spring MVC创建服务时发生java错误   JavaFX获取安装在计算机中的特定应用程序的版本   SecureRandom的安全问题:PRNG在java 1.5中不一致   windows我可以创建一个独立的。带Inno设置的Java应用程序的exe安装程序?   如何使用JavaServlet下载csv文件?   java从生成的缓冲图像中添加图像作为jasper中的数据记录?   java日期和时间解析