gdal - how to plot geotiff data in specific area (lat/lon) with python -


i have geotiff raster data sets elevation data init , want plot in specific area, such 60°e - 70° e ,70°s - 80°e.

i have bit of code here,but pcolormesh seem couldn't plot geotif.it's red. picture. picture shown imshow really picture

when try make plot code below:

path = "f:\\mosaic_h1112v28_ps.tif" dataset = gdal.open(path) data = dataset.readasarray() x0, dx, dxdy, y0, dydx, dy = dataset.getgeotransform() nrows, ncols = data.shape londata = np.linspace(x0, x0+dx*ncols) latdata = np.linspace(y0, y0+dy*nrows) lons, lats = np.meshgrid(lonarray, latarray)   fig = plt.figure(figsize=(8, 8)) m = basemap(projection='lcc', lon_0=67.5, lat_0=-68.5, height=950000,             width=580000, resolution='h')  m.drawcoastlines()  x, y = m(lons, lats)  

then dont know how continue . want use imshow, imshow dont specify area(lat/lon).

i appreciate help.

it's question, here solution.

required packages: georaster dependencies (gdal, etc).
data demo purposes downloadable http://dwtkns.com/srtm/

import georaster import matplotlib.pyplot plt mpl_toolkits.basemap import basemap  fig = plt.figure(figsize=(8,8))  # full path geotiff file fpath = r"c:\\path_to_your\geotiff_file\srtm_57_10.tif"  # thailand east  # read extent of image without loading # values in degrees lat/long # geotiff may use other coordinates , projection my_image = georaster.singlebandraster(fpath, load_data=false)  # grab limits of image's extent minx, maxx, miny, maxy = my_image.extent  # set basemap larger extents # set resolution @ intermediate level "i" m = basemap( projection='cyl', \             llcrnrlon=minx-2, \             llcrnrlat=miny-2, \             urcrnrlon=maxx+2, \             urcrnrlat=maxy+2, \             resolution='i')  m.drawcoastlines(color="gray") m.fillcontinents(color='beige')  # load geotiff image, assign variable image = georaster.singlebandraster( fpath, \                         load_data=(minx, maxx, miny, maxy), \                         latlon=true)  # plot image on matplotlib active axes # set zorder put image on top of coastlines , continent areas # set alpha let hidden graphics show through plt.imshow(image.r, extent=(minx, maxx, miny, maxy), zorder=10, alpha=0.6)  plt.show() 

the resulting plot:

enter image description here

edit1

my original answer places focus on how plot simple geotiff image on basic projection basemap. better answer not possible without access required resources (i.e. geotiff file).

here try improve answer.

i have clipped small portion whole world geotiff file. reproject (warp) lcc projection specifications defined basemap() used. process done gdal softwares. resulting file named "lcc_2.tiff". geotiff file, plotting of image done code below.

the important part geotiff file must have same coordinate system (same projection) projection used basemap.

import georaster import matplotlib.pyplot plt mpl_toolkits.basemap import basemap  fig = plt.figure(figsize=(8,8))  m = basemap(projection='lcc', lon_0=67.5, lat_0=-68.5, \             height=950000, width=580000, resolution='h')  m.drawcoastlines() m.fillcontinents(color='beige')  image = georaster.singlebandraster( "lcc_2.tiff", latlon=false) plt.imshow(image.r, extent=image.extent, zorder=10, alpha=0.6)  plt.show() 

the output map:

enter image description here


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -