Guest User

Untitled

a guest
Jan 7th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. # imports
  2. from osgeo import gdal, ogr, osr
  3. import os
  4. import matplotlib.pyplot as plt
  5. import scipy.interpolate as il
  6. import numpy as np
  7. from itertools import cycle
  8.  
  9.  
  10. # obtaining xyz to interpolate
  11. a=[] # to store all x valuesa
  12. b=[] # to store all corresponding y values
  13. c=[] # to store all corresponding z values
  14. # input output
  15. shapefile = r"P:May2014TestLielaisIV_Bp_Schichten.shp"
  16. outras=r"P:Interpolatio_spline_with_bariersoutras.tif"
  17. ## opening a shape file
  18. DriverName = ogr.GetDriverByName("ESRI Shapefile")
  19. dataSource = DriverName.Open(shapefile, 0)
  20. print dataSource
  21. layer = dataSource.GetLayer()
  22. srs= layer.GetSpatialRef()
  23. #looping through features to get geometry reference for each ........
  24. for i in range(0, layer.GetFeatureCount()):
  25. # Get the input Feature
  26. inFeature = layer.GetFeature(i)
  27. geom = inFeature.GetGeometryRef()
  28. x= geom.GetX()
  29. a.append(x)
  30. y= geom.GetY()
  31. b.append(y)
  32. z= inFeature.GetField("of_wth_01")
  33. c.append(z)
  34. # obtaining max and min extent
  35. xmin,xmax,ymin,ymax = [min(a),max(a),min(b),max(b)]
  36.  
  37. #size of 1 m grid
  38. nx = (int(xmax - xmin)+1)
  39. ny = (int(ymax - ymin)+1)
  40. # Generate a regular grid to interpolate the data.
  41. xi = np.linspace(xmin, xmax, nx)#, endpoint=False)
  42. yi = np.linspace(ymin, ymax, ny)
  43. xi, yi = np.meshgrid(xi, yi)
  44. # Interpolate the values of z for all points in the rectangular grid
  45. zi = il.griddata((x, y), c, (xi, yi),method='linear')
  46.  
  47. # Interpolate the values of z for all points in the rectangular grid
  48. zi = il.griddata((x, y), c, (xi, yi),method='linear')
  49. # ^ ^
Add Comment
Please, Sign In to add comment