Re: A question about the rasterio precision & python floats (Pixel width & height)
thomaswanderer@...
Thank you for the info. I saw shorter values tan in QGIS and those came from Python's float limitations. When using the Decimal class I also get the same over-precise values.
|
|
Get bounds after rasterio merge
ashnair0007@...
I merged two tiffs via the rasterio.merge function which returned the merged numpy array and the geo transform. Is there a way to get the bounds (in latitude and longitude) of this new merged image?
|
|
can resampling not populate cell if source has nodata?
Nick Forfinski-Sarkozi
Hi rasterio. New user here. Thanks for a fantastic module. During resampling, is there a way to force the cells of the resampled raster to nodata if any of the corresponding original cells are nodata? (If by chance anyone is familiar with it, I'm looking for functionality analogous to arcpy's Aggregate function with ignore_data=True https://pro.arcgis.com/en/pro-app/tool-reference/spatial-analyst/aggregate.htm )
Thanks, Nick
|
|
Re: A question about the rasterio precision & python floats (Pixel width & height)
Sean Gillies
Hi, On Mon, May 25, 2020 at 3:30 AM <thomaswanderer@...> wrote:
QGIS and rasterio both use GDAL to read raster data and all of these use double precision floats to store values of the georeferencing matrix. I believe you're seeing different string representations of the same numbers. Since the hex representations of the two numbers are the same, I suspect the values shown by QGIS are overly precise and that the last digits are meaningless. >>> 0.0008333333299974727193.hex() '0x1.b4e81b312a043p-11' >>> 0.0008333333299974727.hex() '0x1.b4e81b312a043p-11' Sean Gillies
|
|
Re: Create raster aligned with one created by gdal_translate
thomaswanderer@...
I also still fight with the shifted by one pixel problem for 1 extent out of 5 extents. 4 return perfectly aligned clipped subsets of the source raster, 1 does not.
|
|
Re: Create raster aligned with one created by gdal_translate
Denis Rykov
Thanks Thomas. I've tried your approach but it still gives me a shifted output compared to gdal_translate.
|
|
A question about the rasterio precision & python floats (Pixel width & height)
thomaswanderer@...
When opening my raster with QGIS, I can see the Pixel Size of my raster as:
When I read he same raster with rasterio, I get pixel size values with a lower precision and I guess this causes some problems when calculating new affines for another extent
I have tries to pass the decimal_precision=X when opening my raster with rasterio, but this has no effect. I guess this is a general float problem on my system. My suggestion therefore would be to use python Decimals or any other type representing real floats.
|
|
Re: Create raster aligned with one created by gdal_translate
I had a very similar approach to calculate the new affine & width/height manually as you. But I have now replaced it with just rasterio functions and when comparing the results of the new affine, they were identical :-)
I just wonder, why you add 0.5 when calculating the height & width? My code looked like this (windows is the extent I am matching my raster to, profile is the target raster profile, copied from my source raster and then modified)
But i have replaced all this now by:
Both methods actually created and affine with the same values, that is why I replaced my own code with the rasterio functions.
|
|
Re: Window from bounds is shifted by 1 Pixel
Good to know I am not the only one.
I guess it could be rounding problems, but the extent I use for creating the window aligns perfectly with the input rater (as seen above). But the output window get's shifted and only if my extent overlaps on the western side of the original source raster. All other windows (created from the intersection extents) are just fine for both input and output! Very strange. Ah by the way, I use rasterio 1.13.
|
|
Re: Window from bounds is shifted by 1 Pixel
Denis Rykov
Hi! I had faced the similar shifting issue yesterday: https://github.com/mapbox/rasterio/issues/1932
|
|
Window from bounds is shifted by 1 Pixel
thomaswanderer@...
Hi. this is my first post. I am new to raster.io and really like it so far. Thumbs up for all the work :-)
But I have already a first problem: I created a function which creates a new raster for a given geographical extent and copies the values of the source raster into it. The new raster has the same characteristics as the source raster. The geographical extents can now
For all of these cases, I create a new affine for the new raster and then fill it with the values of the source raster (or any other optionally specified value). I still have a problem when copying over the values from the source to the target raster. In one case the two rasters (source -> copy) are not aligned but shifted by 1 pixel. (See yellow extent in above images - All other extents create perfectly aligned new rasters) My strategy for copying data from the source to the target is the following:
My guess is that the write_window = target.window(*intersection.bounds)) is the part where the error happens. While the read_window still reads the correct data, the write window places the copied data shifted by 1 pixel. I use the same intersection extent for the creation of both windows, and the intersection is also pixel aligned as visible in the above image. So I wonder what I do wrong. Is this maybe a rounding or precision error?
|
|
Create raster aligned with one created by gdal_translate
Denis Rykov
Hi everyone! I tried to convert
Eventually I came up with the following solution that produces raster aligned with one produced by
It works fine but I still have couple of questions:
Any advice would be appreciated.
|
|
Re: Create sparse raster with Rasterio. Is this possible?
Brendan Ward
Ben - I'm not sure I follow your intent here.
Is the idea to make the smallest possible geotiff after rasterizing all shapes in test.shp to pixels, where SPARSE_OK omits non-rasterized pixels where possible from the geotiff? In rasterio, the best way to approach that would be to first do a windowed read of your data from raster that overlap the bounding box of all features in test.shp (see geometry_window() https://github.com/mapbox/rasterio/blob/master/rasterio/features.py#L387), then rasterize within that smaller window, then write it out to a new geotiff (note: it will have a different geotransform / width / height than the original). If your shapes in test.shape are scattered around the raster with large areas of nodata in between, there's not really a way to handle that case aside from windowing out and writing each rasterized shape to a separate geotiff, then maybe making a VRT of the individual geotiffs it in GDAL to mosaic them back together.
|
|
Create sparse raster with Rasterio. Is this possible?
BDHudson@...
Hi All -
I have benefited greatly from Rasterio - and first want to say thanks. Second, I am trying to move bash GDAL code into rasterio and python. Is it possible to use rasterio rasterize to create a sparse raster? In gdal_rasterize setting the SPARSE_OK=TRUE flag does this. Because rasterio rasterize creates a numpy array, (not a geotiff) I am assuming this may not be possible but wanted to ask. I also might imagine a way to use scipy sparse matrices to do something like this. I am doing this to save on memory requirements. here is the full call - any advice on how to replicate appreciated. gdal_rasterize \ Regards, Ben
|
|
Re: Does Rasterio support tiling of large geotiffs?
Sean Gillies
Hi, On Sun, May 17, 2020 at 6:35 AM <ashnair0007@...> wrote: I would like to crop my large geotiff into 800 x 800 tiles. While it's possible to do so otherwise, I was wondering if rasterio has an internal functionality to crop large geotiffs to tiles of a specific size. The rasterio package includes a clip command: https://rasterio.readthedocs.io/en/latest/cli.html#clip. I don't remember how we arrived at calling this "clip" instead of "crop", but it's the same idea. Internally, the clip command uses rasterio's windowed reading feature: https://rasterio.readthedocs.io/en/latest/topics/windowed-rw.html#reading. -- Sean Gillies
|
|
Does Rasterio support tiling of large geotiffs?
ashnair0007@...
I would like to crop my large geotiff into 800 x 800 tiles. While it's possible to do so otherwise, I was wondering if rasterio has an internal functionality to crop large geotiffs to tiles of a specific size.
|
|
Re: rasterio 1.1.4
vincent.sarago@...
This is really cool, thanks for the hard work Sean!
|
|
rasterio 1.1.4
Sean Gillies
Hi all, Rasterio 1.1.4 has been released. Here are the changes: Here are the distributions on PyPI Please note that there is no wheel for Python 2.7 and OS X. We've lost the ability to build them and I'm not sure why. We may need help from the Travis CI team to get that particular build job unstuck. But as we're moving on from supporting Python 2.7, I'm not super concerned about this right now. The biggest changes in the wheels on PyPI aren't mentioned in rasterio because they are outside the project scope. See https://github.com/rasterio/rasterio-wheels/blob/master/CHANGES.md#2020-05-06 for details. In a nutshell, we're upgrading NetCDF to 4.6.2, patching GDAL 2.4.4 to fix two different bugs, and are using a patched version of auditwheel to add a rasterio-specific tag, "rasterio", to the SONAME of shared libraries in the linux wheels. In rasterio.libs you will see shared libraries with names like libcurl-rasterio-ea538880.so.4.4.0 instead of libcurl-ea538880.so.4.4.0. These wheels include 2.4.4. I felt like upgrading to 3.0 or 3.1 while also trying to fix the SONAME collision problem was too much for me, so we'll tackle the GDAL/PROJ upgrades in a future release. Thanks for your help, everyone! -- Sean Gillies
|
|
Re: Rasterio.features.geometry_window error when geojson has GeometryCollection
filthyhands@...
Thanks again Brendan, very helpful.
|
|
Re: Rasterio.features.geometry_window error when geojson has GeometryCollection
Brendan Ward
The target release date that will include this fix is 5/1/2020 (https://github.com/mapbox/rasterio/issues/1911)
If you need changes sooner, you have a few options: 1) clone the repo and checkout the maint-1.1 branch, and rebuild the Cython files. This can be a bit involved depending on your OS / env; you'll need a compiler, GDAL, Cython, etc. (https://github.com/mapbox/rasterio/blob/master/CONTRIBUTING.rst#development-environment) 2) coerce each GeometryCollection to FeatureCollection 3) use shapely to union each GeometryCollection into a single geometry object before passing into bounds() 4) calculate bounds on each individual geometry within a GeometryCollection, then union the bounds. Here's how it was done in the Cython file (https://github.com/mapbox/rasterio/pull/1915/files#diff-83bc1acea1f8d435fd6c4798a58fc072R411-R426); you can do the same thing on your end.
|
|