Skip to content

A python module for converting a raster to a Pandas DataFrame

License

Notifications You must be signed in to change notification settings

mblackgeo/rastertodataframe

Repository files navigation

Raster To DataFrame

PyPI Status Build Status Documentation Status Coverage Status

A simple python module that converts a raster to a Pandas DataFrame.

from rastertodataframe import raster_to_dataframe

raster_path = '/some/gdal/compatible/file.tif'
vector_path = '/some/ogr/compatible/file.geojson'

# Extract all image pixels (no vector).
df = raster_to_dataframe(raster_path)

# Extract only pixels the vector touches and include the vector metadata.
df = raster_to_dataframe(raster_path, vector_path=vector_path)

Features

  • Convert any GDAL compatible raster to a Pandas DataFrame.
  • Optionally, if any OGR compatible vector file is given, only pixels touched by the vector are extracted from the raster. The output DataFrame includes these pixels as well as any attributes from the vector file.

Installation

pip install rastertodataframe
  • A working GDAL/OGR installation is required. This is best accomplished with conda.
conda install -c conda-forge numpy gdal geopandas pandas pyproj

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.