-
Notifications
You must be signed in to change notification settings - Fork 117
Migrating to 1.0
As we move towards a stable 1.0 release it's important to get a few things cleaned up. Unfortunately that sometimes means breaking backwards compatibility between 0.x releases. This guide should help you make the transitions smoothly. Let me know if I've missed anything...
This is a big one.
We removed all dependencies on the osgeo
bindings and now depend on fiona
for vector IO. This means that if you relied on osgeo.ogr
bindings to access non-file data sources such as postgis or wfs, you will need to write a wrapper function to convert those to GeoJSON-like Feature dictionaries yourself.
Following the lead of rasterio, rasterstats deprecating the 6-element GDAL-style geotransform tuples. Please update your code to use affine
# before
gt = (244300.6, 25.5, 0.0, 1000868.8, 0.0, -25.5)
zonal_stats(..., transform=gt)
# after
zonal_stats(..., affine=Affine.from_gdal(*gt))
Old style will work until 1.0 with a deprecation warning.
Previously, non-intersecting features would return a numpy NaN
for some, not all aggregate stats. This behavior is now better defined with None
returned for all stats (except count
which is 0
).
In an effort to clean up the code and make it more maintaible in the long run. Several utility functions have been removed entirely:
utils.bbox_to_pixel_offsets
utils.pixel_offsets_to_window
utils.raster_extent_as_bounds
-
utils.combine_feature_results
: Use thegeojson_out
argument instead
All of the functions concerning vector data access have been moved to rasterstats.io
. I do not recommend using them external to this module (IOW don't import rasterstats.io
in your own code) as they may eventually get pulled out into a separate module.
Removed the deprecated rasterstats
script in favor of rio zonal
The keys for mini raster output have changed to
mini_raster_array: The clipped and masked numpy array
mini_raster_affine: Affine transform (NOT a GDAL-style geotransform)
mini_raster_nodata: NoData Value
Additionally, we removed the GeoRaster dependency so if you want GeoRaster output, this is the alternative mechanism
# before
zs = zonal_stats(..., raster_out=True, opt_georaster=True)
# after
zs = zonal_stats(...)
newstats = []
for s in zs:
s['georaster'] = georasters.GeoRaster(
s['mini_raster_array'],
s['mini_raster_affine'].to_gdal(),
nodata_value=s['mini_raster_nodata'],
projection=spatial_ref)
newstats.append(s)
global_src_extent
was inteded for cases when you wanted to pull your entire raster into a numpy array once rather than reading off the disk for each feature. The prefered alternative is to do this directly with rasterio and pass the array in manually
# before
zonal_stats(raster="a.tif", ..., global_src_extent=True)
# after
with rasterio.open("a.tif) as src:
arr = src.read(1)
aff = src.affine
nodata = src.nodata
zonal_stats(raster=arr, affine=aff, nodata=nodata)
Instead of __fid__
being appended to each result, use geojson_out=True
to preserve feature ids and other properties
Instead of copy_properties=True
, use geojson_out=True
to preserve the entire feature including any properties.
-
nodata_value
changed tonodata
for consistency, old style will work until 1.0 with a deprecation warning.
A new dependency on rasterio