You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dear
I have tried to export as tif the results of the interpolation as it says in another post but it doesn't work, allways the tif is bigger compare with my area, someone could help me.
My code is:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Dear
I have tried to export as tif the results of the interpolation as it says in another post but it doesn't work, allways the tif is bigger compare with my area, someone could help me.
My code is:
datafile='EC.csv'
df=pd.read_csv(datafile,delimiter=',')
lons=np.array(df['Lon'])
lats=np.array(df['Lat'])
data=np.array(df['Vn'])
Kriging data
grid_space = 0.5
gridx = np.arange(np.amin(lons), np.amax(lons), grid_space) #grid_space is the desired delta/step of the output array
gridy = np.arange(np.amin(lats), np.amax(lats), grid_space)
extent=[np.amin(lons), np.amax(lons), np.amin(lats), np.amax(lats)]
OK = OrdinaryKriging(lons, lats, data, variogram_model='linear', verbose=False, enable_plotting=False)
#OK = OrdinaryKriging(lons, lats, data, variogram_model='gaussian', verbose=True, enable_plotting=False,nlags=5)
z, ss = OK.execute("grid", gridx, gridy)
fig, ax = plt.subplots(figsize=(10,10))
cs=ax.imshow(z,extent=extent, cmap="jet")
xres = np.amax(lons) - np.amin(lons)
yres = np.amax(lats) - np.amin(lats)
ysize = len(lats)
xsize = len(lons)
ulx = np.amin(lons) - (xres / 2.)
uly = np.amax(lats) - (yres / 2.)
driver = gdal.GetDriverByName('GTiff')
ds = driver.Create('test.tif', xsize, ysize, 1, gdal.GDT_Float32)
srs = osr.SpatialReference()
srs.ImportFromEPSG(4326)
ds.SetProjection(srs.ExportToWkt())
gt = [ulx, xres, 0, uly, 0, yres ]
ds.SetGeoTransform(gt)
outband = ds.GetRasterBand(1)
outband.WriteArray(z)
ds = None
plt.show()
Thanks
Beta Was this translation helpful? Give feedback.
All reactions