Package: buzzard
buzzardIn a nutshell, thebuzzardlibrary provides powerful abstractions to manipulate together images and geometries that come from different kind of sources (GeoTIFF,PNG,GeoJSON,Shapefile,numpy array,buzzard pipelines, ...).buzzardisApythonlibrary.Primarily designed to hide all cumbersome operations when doing data-science withGISfiles.A Multipurpose computer vision library, it can be used in all kind of situations where images or geometries are involved.A pythonic wrapper forosgeo'sgdal/ogr/osr.A solution to work with arbitrary large images by simplifying and automating the manipulation of image slices.buzzardcontainsADatasetclass that oversees all opened raster and vector files in order to share resources.An immutable toolbox class, theFootprint, designed to locate a rectangle in both image space and geometry space.How to open and read filesThis example demonstrates how to visualize a large raster polygon per polygon.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()Images from theISPRS'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))How to create files and manipulateFootprintsimportbuzzardasbuzzimportnumpyasnpimportmatplotlib.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)Advanced examplesAdditional examples can be found here:Files andFootprintsin depthasync rastersin depthbuzzardallowsOpening and creatingrasterandvectorfiles. Supports allGDAL drivers (GTiff, PNG, ...)and allOGR drivers (GeoJSON, DXF, Shapefile, ...).Readingraster files pixels from disk tonumpy.ndarray.Options: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).Properties:thread-safeWritingraster files pixels to disk fromnumpy.ndarray.Options:sub-rectangle writing,rotated and scaled sub-rectangle writing (thanks to on-the-fly remapping with OpenCV),masked writing.Readingvector files geometries from disk toshapely objects,geojson dictandraw coordinates.Options:masking.Properties:thread-safeWritingvector files geometries to disk fromshapely objects,geojson dictandraw coordinates.Powerful manipulations ofraster windowsInstantiationof image processing pipelines where each node is a raster, and each edge is a user defined python function working onnumpy.ndarray(beta, partially implemented).Options:automatic parallelization using user defined thread or process pools,disk caching.Properties:lazy evaluation,deterministic,automatic tasks chunking into tiles,fine grain task prioritization,backpressure prevention.Spatial reference homogenizationbetween opened files like a GIS software does (beta)Documentationhttps://buzzard.readthedocs.io/DependenciesThe following table lists dependencies along with the minimum version, their status for the project and the related license.LibraryVersionMandatoryLicenseCommentgdal>=2.3.3YesMIT/XHard to install. Will be included inbuzzardwheelsopencv-python>=3.1.0Yes3-clause BSDEasy to install withopencv-pythonwheels. Will be optionalshapely>=1.6.1Yes3-clause BSDaffine>=2.0.0Yes3-clause BSDnumpy>=1.15.0Yesnumpyscipy>=0.19.1Yesscipypint>=0.8.1Yes3-clause BSDsix>=1.11.0YesMITsortedcontainers>=1.5.9YesapacheRtree>=0.8.3YesMITscikit-image>=0.14.0Yesscikit-imagechainmap>=1.0.2YesPython 2.7 licenseOnly for python <3.2pytest>=3.2.2NoMITOnly for testsattrdict>=2.0.0NoMITOnly for testsHow to install from terminalAnaconda and pip# Step 1 - Install Anaconda# https://www.anaconda.com/download/# Step 2 - Create envcondacreate-nbuzzpythongdal>=2.3.3shapelyrtree-c'conda-forge'# Step 3 - Activate envcondaactivatebuzz# Step 4 - Install buzzardpipinstallbuzzardDockerdockerbuild-tbuzz--build-argPYTHON_VERSION=3.7https://raw.githubusercontent.com/earthcube-lab/buzzard/master/.circleci/images/base-python/Dockerfile
dockerrun-it--rmbuzzbash
pipinstallbuzzardPackage manager and pip# Step 1 - Install GDAL and rtree ******************************************* **# Windows# https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal# https://www.lfd.uci.edu/~gohlke/pythonlibs/#rtree# MacOSbrewinstallgdal
brewtaposgeo/osgeo4mac
brewtap--repair
brewinstallgdal2
brewinstallspatialindexexportPATH="/usr/local/opt/gdal2/bin:$PATH"python3-mpipinstall'gdal==2.3.3'# Ubuntu# Run the commands from the following Dockerfile:# https://github.com/earthcube-lab/buzzard/blob/master/doc/ubuntu_install/Dockerfile# Step 2 - Install buzzard ************************************************** **python3-mpipinstallbuzzardSupported Python versionsTo enjoy the latest buzzard features, update your python!Full python supportLatest supported version:3.8(June 2018)Oldest supported version:3.6(Sept 2015)Partial python support2.7: use buzzard version0.4.43.4: use buzzard version0.6.33.5: use buzzard version0.6.43.6: use buzzard version0.6.4SlackYou want some help? You have a question? You want to contribute? Join us on Slack!How to testgitclonehttps://github.com/earthcube-lab/buzzard
pipinstall-rbuzzard/requirements-dev.txt
pytestbuzzard/buzzard/testHow to build documentationcddocs
makehtml
open_build/html/index.htmlContributions and feedbackWelcome to thebuzzardproject! We appreciate any contribution and feedback, your proposals and pull requests will be considered and responded to. For more information, see theCONTRIBUTING.mdfile.AuthorsSeeAUTHORSLicense and NoticeSeeLICENSEandNOTICE.Other pagesTODOonnotion.so