Extracting specific netcdf info and converting to GeoTIFF in python -


i attempting extract specific set of data netcdf file , convert said data geotiff.

so far have managed extract data want using netcdf4, data in file stored 1d arrays (lat, lon, data want) , assigning them 2d array. netcdf file working subsetted specific region. here @ loss.

i have slight understanding of how geotiff conversion works via have read @ these links:

https://borealperspectives.wordpress.com/2014/01/16/data-type-mapping-when-using-pythongdal-to-write-numpy-arrays-to-geotiff/

http://adventuresindevelopment.blogspot.co.uk/2008/12/create-geotiff-with-python-and-gdal.html

and here have currently:

import netcdf4 import numpy np osgeo import gdal osgeo import osr  #reading in data files , extracting said data ncfile = netcdf4.dataset("data.nc", 'r')  dataw = ncfile.variables["dataw"][:] lat = ncfile.variables["latitude"][:] long = ncfile.variables["longitude"][:]   n = len(dataw) x = np.zeros((n,3), float)  x[:,0] = long[:] x[:,1] = lat[:] x[:,2] = dataw[:]  nx = len(long) ny = len(lat) xmin, ymin, xmax, ymax = [long.min(), lat.min(), long.max(), lat.max()] xres = (xmax - xmin) / float(nx) yres = (ymax - ymin) / float(ny) geotransform = (xmin, xres, 0, ymax, 0, -yres)  #creates 1 raster band file dst_ds = gdal.getdriverbyname('gtiff').create('mygeotiff.tif', ny, nx, 1, gdal.gdt_float32)  dst_ds.setgeotransform(geotransform)    # specify coords srs = osr.spatialreference()            # establish encoding srs.importfromepsg(3857)                # wgs84 lat/long dst_ds.setprojection(srs.exporttowkt()) # export coords file dst_ds.getrasterband(1).writearray(x)   # write r-band raster dst_ds.flushcache()                     # write disk dst_ds = none                           # save, close 

the process of geotiff creation above have largely sourced here:

how write/create geotiff rgb image file in python?

i have attempted based on understanding array want write raster 2d array 3 columns, 2 of co-ords , 1 of data. result check in snap black page white line along lhs.

so question follows:

how can extract necessary geotransform data netcdf file, adjust geotransform parameters appropriately , subsequently use extracted lat long + dataw arrays write geotiff file?


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -