Skip to main content

GIS files manipulations

Project description

buzzard

In a nutshell, buzzard reads and writes geospatial raster and vector data.



license CircleCI codecov

Table of Contents

buzzard is

  • a python library
  • a gdal/ogr/osr wrapper
  • designed to hide all cumbersome operations while working with GIS files
  • designed for data science workflows
  • under active development (see TODO)
  • tested with pytest in python 2.7 and python 3.6

buzzard contains

  • a class to open/read/write/create GIS files: DataSource
  • classes to interact with opened files: RasterPhysical Vector
  • a toolbox class designed to locate a rectangle in both image space and geometry space: Footprint

Simple example

This example illustrates visualization of a raster based on polygons.

import buzzard as buzz
import numpy as np
import matplotlib.pyplot as plt

rgb_path = 'path/to/raster.file'
polygons_path = 'path/to/vector.file'

ds = buzz.DataSource()
ds.open_raster('rgb', rgb_path)
ds.open_vector('polygons', polygons_path)

# Iterate over the polygons as shapely objects
for poly in ds.polygons.iter_data(None):

    # Compute the Footprint bounding poly
    fp = ds.rgb.fp.intersection(poly)

    # Read rgb at `fp` to a numpy array
    rgb = ds.rgb.get_data(band=(1, 2, 3), fp=fp).astype('uint8')
    alpha = ds.rgb.get_data(band=4, fp=fp).astype('uint8')

    # Create a boolean mask as a numpy array from a shapely polygon
    mask = np.invert(fp.burn_polygons(poly))

    # Darken pixels outside of polygon, set nodata pixels to red
    rgb[mask] = (rgb[mask] * 0.5).astype(np.uint8)
    rgb[alpha == 0] = [255, 0, 0]

    plt.imshow(rgb)
    plt.show()

Advanced (and fun 😊) examples

Additional examples can be found here: jupyter notebook.

Features

  • Raster and vector files opening
  • Raster and vector files reading to numpy.ndarray, shapely objects, geojson and raw coordinates
  • Raster and vector files writing from numpy.ndarray, shapely objects, geojson and raw coordinates
  • Raster and vector files creation
  • Powerful manipulations of raster windows
  • Spatial reference homogenization between opened files like a GIS software

Future features summary

  • Wheels with osgeo binaries included
  • Advanced spatial reference homogenization using gdal warping functions
  • More tools, syntaxes and algorithms to work with raster datasets that don't fit in memory
  • Strong support of non north-up / west-left footprints
  • Data visualization tools
  • Strong performance improvements
  • Floating point precision loss handling improvements

Dependencies

The following table lists dependencies along with the minimum version, their status for the project and the related license.

Library Version Last Mandatory License Comment
gdal >=2.1.3 2.2.2 Yes MIT/X Hard to install. Will be included in buzzard wheels
opencv-python >=3.1.0 3.3.0.10 Yes 3-clause BSD Easy to install with opencv-python wheels. Will be optional
shapely >=1.6.1 1.6.1 Yes 3-clause BSD
affine >=2.0.0 2.1.0 Yes 3-clause BSD
numpy >=1.13.0 1.13.1 Yes numpy
scipy >=0.19.1 0.19.1 Yes scipy
pint >=0.8.1 0.8.1 Yes 3-clause BSD
six >=1.11.0 1.11.0 Yes MIT
chainmap >=1.0.2 1.0.2 Yes Python 2.7 license Only for python <3.2
pytest >=3.2.2 3.2.2 No MIT Only for tests
attrdict >=2.0.0 2.0.0 Yes MIT
geopandas 0.3.0 No 3-clause BSD Future dependency. Will be optional

How to install

Package manager and pip

# Install GDAL
# Windows: http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal
# MacOS: brew install gdal && brew tap osgeo/osgeo4mac && brew tap --repair && brew install gdal2 && export PATH="/usr/local/opt/gdal2/bin:$PATH" && pip install 'gdal==2.1.3'
# Ubuntu: apt-get install python-gdal=2.1.3+dfsg-1~xenial2 libproj-dev libgdal-dev gdal-bin

# Install buzzard
pip install buzzard

Anaconda and pip

# Install Anaconda
# https://www.anaconda.com/download/

# Create env
conda create -n buzz python=3.6 gdal opencv scipy shapely -c 'conda-forge'

# Activate env
# Windows: activate buzz
# Linux, MacOS: source activate buzz

# Install buzzard
pip install buzzard

How to test

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

Documentation

Hosted soon, in the meantime

Contributions and feedback

Welcome to the buzzard project! We appreciate any contribution and feedback, your proposals and pull requests will be considered and responded to. For more information, see the CONTRIBUTING.md file.

Authors

See AUTHORS

License and Notice

See LICENSE and NOTICE.

Other pages


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

buzzard-0.4.4.tar.gz (95.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page