![]() The window_transform function can either take a 2D N-D array indexer in the form of a tuple ((row_start, row_stop), (col_start, col_stop)) or provide offset as written in its documentation Cropped raster and vector overlay Luckily rasterio has a window_transform method on the dataset reader which can compute the new transformation from the old one by passing the bounds of the layer. To avert this problem, we need to find the new affine transformation of the cropped image. with rs.open(path_to_file, "r") as src:įig.2 - Overlaid cropped raster and vector layer with incorrect spatial extents When you slice the image, the affine transformation is not the same anymore and thus plotting the sliced image would result in a plot having the spatial extent of the original image while the sliced image being magnified (Fig. _ = show(img, transform = src.transform, ax=ax)īut what if you want to plot a subset of the raster image, in the sense that you would like to slice the image arbitrarily and plot it. Moreover, if we pass a numpy array to the show function, the spatial extent of that array has to be explicitly passed using the transform parameter of the show function since the numpy array does not know the corner location of the raster and thus the plot would begin with x,y: 0,0 as shown below. _ = vector_ot(ax=ax) # `vector_layer` is a geodataframe (geopandas)įig.1 -Overlay raster with vector layer. _ = show(src, ax=ax) # from ot import show with rs.open(path_to_file, "r") as src: # import rasterio as rs When we pass a reader object, the spatial extent is automatically read by show function. Rasterio does offer a plotting function show which can plot a raster layer with the correct spatial extent for you when we pass the dataset reader object. It is known that we first need to identify the spatial extent of each layer, having the same coordinate reference system. I recently faced a problem of having to plot “cropped raster” layer and a vector layer on the same axes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |