gis文件操作

buzzard的Python项目详细描述


buzzard

简而言之,buzzard库提供了强大的抽象,可以将来自不同来源的图像和几何图形一起操作(GeoTIFFPNGGeoJSONShapefilenumpy arraybuzzard pipelines,…)。



licenseCircleCIcodecovreadthedoc

Join us on Slack!

buzzard

  • 一个python库。
  • 主要用于在使用GIS文件进行数据科学时隐藏所有繁琐的操作。
  • 它是一个多用途的计算机视觉库,可用于涉及图像或几何图形的各种情况。
  • 用于osgeo'sgdal/ogr/osr的pythonic包装器。
  • 通过简化和自动化图像切片的操作来处理任意大图像的解决方案。
  • Delair开发,用于几个深入学习和算法项目。

buzzard包含

  • 一个^{}类,它监视所有打开的光栅和矢量文件,以便共享资源。
  • 一个不可变的工具箱类^{},用于在图像空间和几何空间中定位矩形。

如何打开和读取文件

此示例演示如何可视化每个多边形的大型光栅多边形。

importbuzzardasbuzzimportnumpyasnpimportmatplotlib.pyplotasplt# Open the files. Only files' metadata are read so farr=buzz.open_raster('path/to/rgba-image.tif')v=buzz.open_vector('path/to/polygons.geojson',driver='GeoJSON')# Load the polygons from disk one by one as shapely objectsforpolyinv.iter_data():# Compute the Footprint bounding `poly`fp=r.fp.intersection(poly)print(fp)# Load the image from disk at `fp` to a numpy arrayrgb=r.get_data(fp=fp,channels=(0,1,2))alpha=r.get_data(fp=fp,channels=3)# Create a boolean mask as a numpy array from the shapely polygonmask=np.invert(fp.burn_polygons(poly))# Darken pixels outside of polygon, set transparent pixels to orangergb[mask]=(rgb[mask]*0.5).astype(np.uint8)rgb[alpha==0]=[236,120,57]# Show the result with matplotlibplt.imshow(rgb)plt.show()

来自ISPRS's Potsdam dataset的图像。

Footprint(tl=(3183.600000, -914.550000), br=(3689.700000, -1170.450000), size=(506.100000, 255.900000), rsize=(3374, 1706))



Footprint(tl=(3171.600000, -1321.500000), br=(4553.400000, -2400.000000), size=(1381.800000, 1078.500000), rsize=(9212, 7190))



如何创建文件和操作footprints

importbuzzardasbuzzimportnumpyasnpimportmatplotlib.pyplotaspltimportkerasr=buzz.open_raster('path/to/rgba-image.tif')km=keras.models.load_model('path/to/deep-learning-model.hdf5')# Chunk the raster's Footprint to Footprints of size# 1920 x 1080 pixel stored in a 2d numpy arraytiles=r.fp.tile(1920,1080)all_roads=[]fori,fpinenumerate(tiles.flat):rgb=r.get_data(fp=fp,channels=(0,1,2))# Perform pixelwise semantic segmentation with a keras modelpredictions_heatmap=km.predict(rgb[np.newaxis,...])[0]predictions_top1=np.argmax(predictions_heatmap,axis=-1)# Save the prediction to a `geotiff`withbuzz.create_raster(path='predictions_{}.tif'.format(i),fp=fp,dtype='uint8',channel_count=1).closeasout:out.set_data(predictions_top1)# Extract the road polygons by transforming a numpy boolean mask to shapely polygonsroad_polygons=fp.find_polygons(predictions_top1==3)all_roads+=road_polygons# Show the result with matplotlib for one tileifi==2:plt.imshow(rgb)plt.imshow(predictions_top1)plt.show()# Save all roads found to a single `shapefile`withbuzz.create_vector(path='roads.shp',type='polygon').closeasout:forpolyinall_roads:out.inser_data(poly)




高级示例

其他示例可在此处找到:

buzzard允许

  • 打开并创建rastervector文件。支持所有GDAL drivers (GTiff, PNG, ...)和所有OGR drivers (GeoJSON, DXF, Shapefile, ...)
  • Reading光栅文件像素从磁盘到numpy.ndarray
    • 选项:sub-rectangle readingrotated and scaled sub-rectangle reading (thanks to on-the-fly remapping with OpenCV)automatic parallelization of read and remapping (soon)async (soon)be the source of an image processing pipeline (soon)
    • 属性:thread-safe
  • Writing光栅文件从numpy.ndarray到磁盘的像素。
    • 选项:sub-rectangle writingrotated and scaled sub-rectangle writing (thanks to on-the-fly remapping with OpenCV)masked writing
  • Reading矢量文件从磁盘到shapely objectsgeojson dictraw coordinates的几何图形。
    • 选项:masking
    • 属性:thread-safe
  • Writing矢量文件从shapely objectsgeojson dictraw coordinates到磁盘的几何图形。
  • 强大的raster windows
  • Instantiation图像处理管道,其中每个节点是光栅,每个边是用户定义的python函数,用于numpy.ndarray(beta版,部分实现)。
    • 选项:automatic parallelization using user defined thread or process poolsdisk caching
    • 属性:lazy evaluationdeterministicautomatic tasks chunking into tilesfine grain task prioritizationbackpressure prevention
  • Spatial reference homogenization在像gis软件那样打开的文件之间(beta版)

文档

https://buzzard.readthedocs.io/

依赖关系

下表列出了依赖项以及最低版本、项目状态和相关许可证。

LibraryVersionMandatoryLicenseComment
gdal>=2.3.3YesMIT/XHard to install. Will be included in ^{} wheels
opencv-python>=3.1.0Yes3-clause BSDEasy to install with ^{} wheels. Will be optional
shapely>=1.6.1Yes3-clause BSD
affine>=2.0.0Yes3-clause BSD
numpy>=1.15.0Yesnumpy
scipy>=0.19.1Yesscipy
pint>=0.8.1Yes3-clause BSD
six>=1.11.0YesMIT
sortedcontainers>=1.5.9Yesapache
Rtree>=0.8.3YesMIT
scikit-image>=0.14.0Yesscikit-image
chainmap>=1.0.2YesPython 2.7 licenseOnly for python <3.2
pytest>=3.2.2NoMITOnly for tests
attrdict>=2.0.0NoMITOnly for tests

如何从终端安装

水蟒和琵琶

# Step 1 - Install Anaconda# https://www.anaconda.com/download/# Step 2 - Create env
conda create -n buzz python gdal>=2.3.3 shapely rtree -c 'conda-forge'# Step 3 - Activate env
conda activate buzz

# Step 4 - Install buzzard
pip install buzzard

Docker

docker build -t buzz --build-arg PYTHON_VERSION=3.7 https://raw.githubusercontent.com/airware/buzzard/master/.circleci/images/base-python/Dockerfile
docker run -it --rm buzz bash
pip install buzzard

包管理器和PIP

# Step 1 - Install GDAL and rtree ******************************************* **# Windows# https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal# https://www.lfd.uci.edu/~gohlke/pythonlibs/#rtree# MacOS
brew install gdal
brew tap osgeo/osgeo4mac
brew tap --repair
brew install gdal2
brew install spatialindex
exportPATH="/usr/local/opt/gdal2/bin:$PATH"
python3 -m pip install 'gdal==2.3.3'# Ubuntu# Run the commands from the following Dockerfile:# https://github.com/airware/buzzard/blob/master/doc/ubuntu_install/Dockerfile# Step 2 - Install buzzard ************************************************** **
python3 -m pip install buzzard

支持的Python版本

要享受最新的Buzzard功能,请更新您的Python!

完全支持python
  • 最新支持版本:3.7(2018年6月)
  • 支持的最旧版本:3.4(2014年3月)

部分python支持
  • 2.7:使用Buzzard版本0.4.4

松弛度

你需要帮忙吗?你有问题吗?你想捐款吗?加入我们!

Join us on Slack!

如何测试

git clone https://github.com/airware/buzzard
pip install -r buzzard/requirements-dev.txt
pytest buzzard/buzzard/test

如何建立文档代表

cd docs
make html
open _build/html/index.html

贡献和反馈

欢迎来到buzzard项目!我们感谢您的任何贡献和反馈,您的建议和请求将得到考虑和回应。有关详细信息,请参见^{}文件。

作者

AUTHORS

许可证和通知

LICENSENOTICE

其他页


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

推荐PyPI第三方库


热门话题
集合在Java中迭代哈希集的最佳方式   java cobertura maven插件在接口中不使用java8默认方法声明吗?   使用目录路径创建新类型“文件”对象时发生java无效URL/非法参数异常   java仅序列化超类   java在调用运行时后检测图形界面。行政长官()   java我的排序算法只运行一次   java构建JavaFX应用程序   java如何在Swing窗格中使用击键触发超链接   安卓 SD卡内容存在,但无法查看   java如何使用getClass()。getResource()方法   java为各种设备调整服务器上的图像大小   在java中检查数组   仅当执行Runnable JAR:java时引发eclipse异常。lang.NoClassDefFoundError:org/apache/logging/log4j/LogManager