gis文件操作
buzzard的Python项目详细描述
buzzard
简而言之,buzzard
库提供了强大的抽象,可以将来自不同来源的图像和几何图形一起操作(GeoTIFF
,PNG
,GeoJSON
,Shapefile
,numpy array
,buzzard pipelines
,…)。
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
允许
- 打开并创建raster和vector文件。支持所有GDAL drivers (GTiff, PNG, ...)和所有OGR drivers (GeoJSON, DXF, Shapefile, ...)。
- Reading光栅文件像素从磁盘到numpy.ndarray。
- 选项:
sub-rectangle reading
,rotated 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 writing
,rotated and scaled sub-rectangle writing (thanks to on-the-fly remapping with OpenCV)
,masked writing
。
- 选项:
- Reading矢量文件从磁盘到shapely objects,geojson dict和raw coordinates的几何图形。
- 选项:
masking
。 - 属性:
thread-safe
- 选项:
- Writing矢量文件从shapely objects、geojson dict和raw coordinates到磁盘的几何图形。
- 强大的raster windows
- Instantiation图像处理管道,其中每个节点是光栅,每个边是用户定义的python函数,用于numpy.ndarray(beta版,部分实现)。
- 选项:
automatic parallelization using user defined thread or process pools
,disk caching
。 - 属性:
lazy evaluation
,deterministic
,automatic tasks chunking into tiles
,fine grain task prioritization
,backpressure prevention
。
- 选项:
- Spatial reference homogenization在像gis软件那样打开的文件之间(beta版)
文档
https://buzzard.readthedocs.io/
依赖关系
下表列出了依赖项以及最低版本、项目状态和相关许可证。
Library | Version | Mandatory | License | Comment |
---|---|---|---|---|
gdal | >=2.3.3 | Yes | MIT/X | Hard to install. Will be included in ^{ |
opencv-python | >=3.1.0 | Yes | 3-clause BSD | Easy to install with ^{ |
shapely | >=1.6.1 | Yes | 3-clause BSD | |
affine | >=2.0.0 | Yes | 3-clause BSD | |
numpy | >=1.15.0 | Yes | numpy | |
scipy | >=0.19.1 | Yes | scipy | |
pint | >=0.8.1 | Yes | 3-clause BSD | |
six | >=1.11.0 | Yes | MIT | |
sortedcontainers | >=1.5.9 | Yes | apache | |
Rtree | >=0.8.3 | Yes | MIT | |
scikit-image | >=0.14.0 | Yes | scikit-image | |
chainmap | >=1.0.2 | Yes | Python 2.7 license | Only for python <3.2 |
pytest | >=3.2.2 | No | MIT | Only for tests |
attrdict | >=2.0.0 | No | MIT | Only 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
松弛度
3.7
(2018年6月)3.4
(2014年3月)2.7
:使用Buzzard版本0.4.4
松弛度
你需要帮忙吗?你有问题吗?你想捐款吗?加入我们!
如何测试
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
项目!我们感谢您的任何贡献和反馈,您的建议和请求将得到考虑和回应。有关详细信息,请参见^{
作者
许可证和通知
其他页
- TODO在
notion.so