Re: How to specify the name of the input files with the geographical metadata?
Sean Gillies
Hi, On Tue, Feb 23, 2021 at 9:28 AM <juanjo.gomeznavarro@...> wrote: Good morning, The naming of the auxiliary files is a GDAL convention and cannot, to my knowledge, be changed. Neither does rasterio allow a user to open an image in read only mode and add or replace the spatial referencing and other metadata. I agree that would be handy in your case. Workarounds include: Opening your PNGs in "r+" mode and patching them, like with rasterio.open("example.png", "r+") as dataset: dataset.crs = rasterio.crs.CRS.from_epsg(3857) dataset.transform = rasterio.transform.Affine.translation(ulx, uly) * rasterio.transform.Affine.scale(dx, -dy) Note that this would produce .pgw and .png.aux.xml files on your system. Or you could make a generic VRT XML wrapper template and substitute PNG paths into it. See https://gdal.org/drivers/raster/vrt.html. The XML string can then be opened by rasterio. with rasterio.open("<VRTDataset>...</VRTDataset>") as dataset: ... That's not a well known feature of GDAL/rasterio but I use it quite a bit. Sean Gillies
|
|
How to specify the name of the input files with the geographical metadata?
juanjo.gomeznavarro@...
Good morning,
I'm working with PNG files, and the metadata is stored in two separate files: .pgw and .png.aux.xml. Currently I'm forced to use the same name for the three files, i.e. the image and the two auxiliary files with the geographical information. This is cumbersome and inconvenient, because I have a set of images that share the same georeferentiation and currently I'm forced to clone the .pgw and .png.aux.xml files in a somewhat silly way for introducing each image. Is there a way to tell rasterio.open that the two files with the metadata are named different from the PNG image? Thanks a lot!
|
|
Re: Georeference and warp a drone image based on sensor orientation and location using transform.from_gcps()
Sean Gillies
Hi, On Mon, Jan 11, 2021 at 11:10 AM <pgrayobx@...> wrote:
First of all, I apologize for not responding sooner. You must use the rasterio.warp.reproject function to warp. Warping is never implicit in the dataset read/write methods, these are very low-level and always operate strictly in the dataset's row-column space. Sean Gillies
|
|
Re: Clarification on usage with QGIS
Ari Meyer
That's exactly what I hoped to hear, Christina -- thank you so much!
One question: are there any other libraries commonly used in the QGIS space that depend upon a particular version of GDAL? I'm hoping I won't be facing any version conflicts with this setup. Ari
|
|
Re: Clarification on usage with QGIS
Ratcliff, Christina (A&F, Waite Campus)
I've successfully developed the PAT plugin for QGIS using rasterio, geopandas (uses fiona, shapely). All of these libraries are available in the osgeo4w installer through the advanced install. You will also have to ensure the correct GDAL dll is also installed for the version of rasterio you are using.
My method was to create a windows bat file containing the relevant installation which then can be run as administrator to install the libraries. This will use a command line install of rasterio, geopandas and GDAL dll via OSGeo4W. Have a look at the following osgeo4w and QGIS tickets for answers to some of the issues I came across. For some older versions of QGIS see Installing Fiona, Geopandas or rasterio using OSGeo4W breaks QGIS python
I hope this helps. Christina
|
|
Re: Open Santinel 2 archives with Rasterio
lucavlad50@...
That's it, thank you very much!
|
|
Re: Open Santinel 2 archives with Rasterio
Luke
GDALs Sentinel2 driver exposes the data as subdatasets, with (sort of) one for each resolution - https://gdal.org/drivers/raster/sentinel2.html#level-2a
To access the subdataset that contains the 10m bands, you could use something like the following: import rasterio
|
|
Re: Open Santinel 2 archives with Rasterio
lucavlad50@...
Hello,
Thanks for the reply. I saw that but there is no example of a zip file being opened. I saw this: on: https://gdal.org/drivers/raster/sentinel2.html and was wondering if it is possible to read directly from the zip file without unzipping it. Something like: with rio.open("satelite_datasets/S2A_MSIL2A_20201020T092031_N0214_R093_T34TGS_20201020T120739.zip") as f:
print(f.read(4))
Sorry if the question seems stupid, I am new to this. Thank you!
|
|
Re: Open Santinel 2 archives with Rasterio
Sean Gillies
Hi, Please see https://rasterio.readthedocs.io/en/latest/quickstart.html#reading-raster-data for a quick tour of data access features.
On Fri, Feb 12, 2021 at 8:01 AM <lucavlad50@...> wrote: Hello, --
Sean Gillies
|
|
Open Santinel 2 archives with Rasterio
lucavlad50@...
Hello,
I saw that rasterio support reading Santinel 2 archives directly, but I can not find any example. How should I access the bands inside the archive after I read it. For example I have: with rio.open("satelite_datasets/S2A_MSIL2A_20201020T092031_N0214_R093_T34TGS_20201020T120739.zip") as f:
print(...)
Thank you in advance!
|
|
Re: Reading and plotting rotated rasters
Sean Gillies
Hi Denis, On Fri, Feb 5, 2021 at 4:16 PM Denis Rykov <rykovd@...> wrote:
Yes, this is expected. Exactly as with https://gdal.org/api/gdaldataset_cpp.html#classGDALDataset_1ad2a643880bf8b3c492783e1ab5fbc667. Sean Gillies
|
|
reproject: partially covered raster cells reset fully to nodata
Fabian Hofmann
Dear community,
I'm trying to tackle the following problem: Raster A has a high resolution and a small extent. I should be projected to Raster B with small resolution and large extent. Cells from Raster A which partially cover cells in Raster B are getting ignored in the reprojection. Only cells in Raster B which are fully (!) covered by Raster A are getting non-nodata entries. I am not sure if this is intended. Reproduce the behavior with ``` import numpy as np import rasterio as rio from rasterio.warp import reproject, transform_bounds src_crs = 3035 src_top = 3200000.0 src_left = 4000000.0 src_res = 100 src_shape = (100, 100) src_transform = rio.Affine(src_res, 0.0, src_left, 0.0, -src_res, src_top) src_right, src_bottom = src_transform * src_shape src = np.ones(src_shape) dst_crs = 4326 dst_top = 52 dst_left = 5 dst_res = 0.25 dst_shape = (10, 10) dst_transform = rio.Affine(dst_res, 0, dst_left, 0, -dst_res, dst_top) dst_right, dst_bottom = dst_transform * dst_shape dst = np.zeros(dst_shape) # check destination bounds comprise source bounds covered = prj_left, prj_bottom, prj_right, prj_top = ( transform_bounds(src_crs, dst_crs, src_left, src_bottom, src_right, src_top)) assert prj_left > dst_left and prj_bottom > dst_bottom assert prj_right < dst_right and prj_top < dst_top reproject(src, dst, src_transform=src_transform, src_crs=src_crs, dst_transform=dst_transform, dst_crs=dst_crs, resampling=rio.warp.Resampling.average, src_nodata=0, dst_nodata=0, init_dest_nodata=True) assert dst.max() > 0 ``` As soon as you change the target resolution to dst_res=0.1, the reprojected values contain non-zero values. However cells which should have some values, because Raster A partially covers it, get only nodata (in this case 0). What I'm doing to avoid the issue is to pad around the src values. But this needs an extra calculation to get the needed pad_width in order to cover the whole cells in Raster B. (The operation is done many times). Is there a better way? Or is this even a bug? Hope the explanation was clear, thanks in advance! Best, Fabian Hofmann -- Fabian Hofmann Frankfurt Institute for Adavanced Studies (FIAS) FIAS Renewable Energy Systems & Network Analysis (FRESNA) Ruth-Moufang-Straße 1, 60438 Frankfurt am Main T +49 69 798 47605 | hofmann@fias.uni-frankfurt.de
|
|
Reading and plotting rotated rasters
Denis Rykov
Is it expected that during reading process rasterio doesn't take into account rotation angle for rotated rasters (transform has non-zero rotation) ? In order to make it works properly I had to do gdalwarp. Same question for the "show" method. It just draws array as it is without considering the rotation angle.
|
|
Re: HDF4 format support
Alan Snow
HDF4 files are currently not supported out of the box with rasterio wheels (https://github.com/rasterio/rasterio-wheels/issues/36).
|
|
HDF4 format support
bsmith@...
```python import rasterio as rio from osgeo import gdal ``` I cannot open HDF4 files without including the osgeo gdal library. Is there a reason that osgeo isn't a dependency in order to open HDF4 files?
|
|
Re: Clarification on usage with QGIS
Ari Meyer
Looking through the older messages, it seems like integration with QGIS, in particular, is a common enough use case that it really should be discussed separately in the docs. I will be making a request to the QGIS team that Rasterio be included in the core distribution. A couple questions for the group:
1) Does anyone have experience writing QGIS plugins using Rasterio? If so, did you run into any problems, particularly those related to issue I pointed to above? 2) Is there a technical reason why Shapely was included in QGIS but Rasterio was not? Thanks, Ari
|
|
Re: Clarification on usage with QGIS
Ari Meyer
FYI, Sean Gillies responded on https://github.com/mapbox/rasterio/issues/2096 : I'm certain that until rasterio is included with QGIS, shared library compatibility ("DLL Hell") will be a problem for your plugin. For a compiled program like QGIS, it's fairly simple to make sure that only one instance of a library is loaded, this is the job of the linker. In a Python program, there's no built in way to prevent conflicts when different extension modules cause different instances of the same shared library to be loaded. If I were writing QGIS plugins, I would try to stick to using https://qgis.org/pyqgis/master/.
|
|
Clarification on usage with QGIS
Ari Meyer
Note: I originally submitted this as a github issue, as I'd like to see an update to the documentation regarding using Rasterio with QGIS (and perhaps for integrating with any apps that use GDAL). We're looking to simplify our code for a QGIS plugin to use Rasterio/Shapely in place of GDAL/OGR. Shapely is included in the standard QGIS distribution, but Rasterio is not (not sure why). In any case, I found on Does this imply that we may have problems if we try to port the GDAL Python code of our QGIS plugin to Rasterio that we may run into problems, as QGIS is built on GDAL? Can you add a section to rasterio.readthedocs.io clarifying interoperability with QGIS?
|
|
GDAL Error 4 triggers when working with geo-referenced jpeg
I used gdal_translate to convert a geotiff to a jpg with jpg.aux.xml file. The following is part of the script I used to get and write the tiles to disk
import rasterio as rio im = rio.open('./rgb.tif') meta = im.meta.copy() for window, transform in get_tiles(w,h,im): tile_name = f"{window.col_off}_{window.row_off}" meta["transform"] = transform meta["width"], meta["height"] = window.width, window.height outpath = "./tiles/" + tile_name with rio.open(outpath, "w", **meta) as outds: outds.write(self.im.read(window=window)) Now when the input is the original geotiff, writing the tiles to disk works perfectly. However, if my input is the jpeg that I created via gdal_translate, writing to tiles still works however it keeps printing out ERROR 4: tiles/0_0.jpg: No such file or directory for each tile. So it'll go something like this: ERROR 4: tiles/0_0.jpg: No such file or directory ERROR 4: tiles/0_1000.jpg: No such file or directory ERROR 4: tiles/0_2000.jpg: No such file or directory ......................... and so on despite successfully writing the jpeg tiles. I'm confused as to why this error gets printed out and would appreciate any clarification regarding this behaviour.
|
|
Re: TypeError: open() takes at most 8 arguments (14 given) when writing
ashnair0007@...
Yes. That was exactly it. My bad. Thanks.
|
|