Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Vagrantfile
venv
.eggs
.cache
.python-version
*.lprof

# no uv lockfile until this is fixed:
# https://github.com/astral-sh/uv/issues/10845
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
0.21.0
- Replace fiona with pyogrio as the default vector io engine #314
- Binary wheel support for python 3.14
- Promises better performance. See improvements in PR.
- Pass `engine=fiona` to use the old code path.
- Vector file detection now also uses pyogrio, so driver discovery etc may have changed for edge cases.
- fix bug in progress bar #304
- build, tooling, and test improvements #306 #308 #309 #310

0.20.0
- Progress bar for interactive use (#300)
- Fixes to support Fiona 1.10 (#301)
Expand Down
4 changes: 4 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Quickstart

Install::

uv add rasterstats

Or with pip::

pip install rasterstats


Expand Down
34 changes: 26 additions & 8 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
Installation
============

Depends on libgdal, rasterio, fiona, shapely and numpy
Depends on libgdal, rasterio, fiona, shapely and numpy.

Using Ubuntu 14.04::
Using ``uv`` (recommended)::

sudo apt-get install python-numpy libgdal1h gdal-bin libgdal-dev
pip install rasterstats
uv add rasterstats

Or homebrew on OS X::
Or with pip::

brew install gdal
pip install rasterstats

For Windows, follow the `rasterio installation <https://github.com/mapbox/rasterio#windows-1>`_ and then run::
Platform-specific GDAL setup
-----------------------------

pip install rasterstats
**Ubuntu**::

sudo apt-get install libgdal-dev gdal-bin

then install rasterstats as above.

**macOS** (Homebrew)::

brew install gdal

then install rasterstats as above.

**Windows**: follow the `rasterio installation <https://github.com/mapbox/rasterio#windows-1>`_,
then install rasterstats as above.

Tests
-----

To run the python unit tests

uv run pytest
9 changes: 6 additions & 3 deletions docs/manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ while ``point_query`` gives us a list of raster values corresponding to each inp
Vector Data Sources
-------------------
The most common use case is having vector data sources in a file such as an ESRI Shapefile or any
other format supported by ``fiona``. The path to the file can be passed in directly as the first argument::
other format supported by ``pyogrio``. The path to the file can be passed in directly as the first argument::

>>> zs = zonal_stats('tests/data/polygons.shp', 'tests/data/slope.tif')

If you have multi-layer sources, you can specify the ``layer`` by either name or index::

>>> zs = zonal_stats('tests/data', 'tests/data/slope.tif', layer="polygons")

If you have ``fiona`` installed and want to use it as the vector iteration engine
instead of the default ``pyogrio``, you can optionally add ``engine='fiona'``

>>> zs = zonal_stats("tests/data/polygons.shp", "tests/data/slope.tif", engine="fiona")

In addition to the basic usage above, rasterstats supports other
mechanisms of specifying vector geometries.

Expand Down Expand Up @@ -294,5 +299,3 @@ command line tool, as well as GRASS's `r.statistics <https://grass.osgeo.org/gra
They were suitable for offline analyses but were rather clunky to deploy in a large python application.
In 2013, I implemented a proof-of-concept zonal stats function which eventually became ``rasterstats``. It has
been in production in several large python web applications ever since, replacing the starspan wrapper `madrona.raster_stats <https://github.com/Ecotrust/madrona/blob/master/docs/raster_stats.rst>`_.


110 changes: 53 additions & 57 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,65 +1,64 @@
# Note: code auto-formatted with `taplo fmt`
Comment thread
perrygeo marked this conversation as resolved.
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "rasterstats"
description = "Summarize geospatial raster datasets based on vector geometries"
authors = [
{name = "Matthew Perry", email = "perrygeo@gmail.com"},
]
authors = [{ name = "Matthew Perry", email = "perrygeo@gmail.com" }]
readme = "README.rst"
keywords = ["gis", "geospatial", "geographic", "raster", "vector", "zonal statistics"]
keywords = [
"gis",
"geospatial",
"geographic",
"raster",
"vector",
"zonal statistics",
]
dynamic = ["version"]
license = {text = "BSD-3-Clause"}
license = { text = "BSD-3-Clause" }
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Utilities",
"Topic :: Scientific/Engineering :: GIS",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Topic :: Utilities",
"Topic :: Scientific/Engineering :: GIS",
]
requires-python = ">=3.9"
dependencies = [
"affine",
"click >7.1, !=8.2.1",
"cligj >=0.4",
"fiona",
"numpy >=1.9",
"rasterio >=1.0",
"simplejson",
"shapely",
"affine",
"click >7.1, !=8.2.1",
"cligj >=0.4",
"numpy >=1.9",
"pyogrio",
"rasterio >=1.0",
"simplejson",
"shapely",
]

[project.optional-dependencies]
progress = [
"tqdm"
]
docs = [
"numpydoc",
"sphinx",
"sphinx-rtd-theme",
]
progress = ["tqdm"]
fiona = ["fiona"]
docs = ["numpydoc", "sphinx", "sphinx-rtd-theme"]
test = [
"coverage",
"geopandas",
"pyshp >=1.1.4",
"pytest >=4.6",
"pytest-cov >=2.2.0",
"simplejson",
]
dev = [
"rasterstats[test]",
"ruff",
"twine",
"coverage",
"geopandas",
"pyshp >=1.1.4",
"pytest >=4.6",
"pytest-cov >=2.2.0",
"simplejson",
]
dev = ["rasterstats[test,fiona]", "ruff", "twine"]

[project.entry-points."rasterio.rio_plugins"]
zonalstats = "rasterstats.cli:zonalstats"
Expand All @@ -73,31 +72,28 @@ Documentation = "https://pythonhosted.org/rasterstats/"
only-include = ["src", "tests"]

[tool.pytest.ini_options]
filterwarnings = [
"error",
"ignore::UserWarning",
]
filterwarnings = ["error", "ignore::UserWarning"]
testpaths = ["tests"]
# addopts = "--verbose -rf --ipdb --maxfail=1"
addopts = "--verbose -rf --cov rasterstats --cov-report html"

[tool.setuptools.dynamic]
version = {attr = "rasterstats._version.__version__"}
version = { attr = "rasterstats._version.__version__" }

[tool.hatch.version]
path = "src/rasterstats/_version.py"

[tool.ruff.lint]
select = [
"E", # pycodestyle
"F", # Pyflakes
"I", # isort
"RUF", # Ruff-specific rules
"UP", # pyupgrade
"E", # pycodestyle
"F", # Pyflakes
"I", # isort
"RUF", # Ruff-specific rules
"UP", # pyupgrade
]
ignore = [
"RUF005", # Consider iterable unpacking instead of concatenation
"E501", # Disable: line too long
"RUF005", # Disable: Consider iterable unpacking instead of concatenation
]

[tool.ruff]
# TODO: files in docs/notebooks/ use old versions and are incompatible with modern tools
extend-exclude = ["*.ipynb"]
Loading
Loading