0

I am trying to plot a raster with rasterio but somehow that data is being resampled, I think.

The map created does not show the detail in the data. See here: python plot

...compared to the original data (plotted with GIS): topo data

Any idea how to stop rasterio from interpolating/resampling the data?

Here is my code:

import rasterio 
from rasterio.plot import show
import matplotlib.pyplot as plt

topo = rasterio.open('../topo_raster/nz100dem2ihs21.tif')
nz_mask_file  = '../gis_data/NZ_mask.shp'
nzmask  = gpd.read_file(nz_mask_file)

fig= plt.figure(dpi=300. )
ax = plt.axes( projection=ccrs.epsg(27200))

show(topo.read(1,masked=True), ax=ax,transform=topo.transform,interpolation='none',zorder=1,cmap='gist_gray')
nzmask.plot(ax=ax,facecolor="white", edgecolor='black', lw=linewidths_rr,zorder=0.5)

plt.savefig('../newzealand.png')
plt.clf()
  • it would help if you would be more specific, e.g. "I want 300 dpi, I get 100 dpi". If visuals are important, include those. Don't make posters do the legwork. – Konrads Jun 01 '21 at 05:02
  • Hey - thanks for the reply - I did include visuals (please see post?) - 300 dpi would be fine but that doesn't seem to be the problem. I think rasterio is resampling the data, perhaps? If you look at the visuals I provided you might understand my problem better? – Ashley Broadbent Jun 01 '21 at 05:10
  • Did you look at the actual data as read by rasterio to determine whether it is being resampled or not? I doubt that rasterio does that. savefig has a dpi parameter; have you tried changing it? – mcsoini Jun 01 '21 at 06:11
  • I can confirm that `rasterio` does not resample data if you simply `read()`, unless you pass an `out` or `out_shape` argument to the function which differs from the raster's actual shape in which case resampling/decimation is applied ([source](https://rasterio.readthedocs.io/en/latest/api/rasterio._io.html#rasterio._io.DatasetReaderBase.read)), but you are not doing this here. – guampi Jun 03 '21 at 14:59

0 Answers0