Guest User

Untitled

a guest
Mar 11th, 2020
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. #K-mean cluster of Gandhinagar SRTM 30m DEM Using SCIPY Lib
  2.  
  3. import scipy as sp
  4. #reading rasterdata into array form "osgeo"
  5. from osgeo import gdal
  6. #plot graph
  7. from pylab import plot,show
  8. import numpy as np
  9. from scipy.cluster.vq import kmeans,vq
  10.  
  11. dem=gdal.Open(r"C:\Users\lenovo\Desktop\scipy\SRTM-30.tif")
  12. features = np.array(dem.GetRasterBand(1).ReadAsArray(),dtype=float)
  13.  
  14. print (features.shape)
  15. print (features)
  16.  
  17. # computing K-Means with K = 2 (2 clusters)
  18. codes = 2
  19.  
  20. # assign each sample to a cluster
  21. centroids,_ = kmeans(features,codes)
  22. #centroids will show me the important pattern of data
  23.  
  24. #vq= vector quantization
  25. #vq vector quantaization =Assign codes from a code book to observations.
  26. idx,_ = vq(features,centroids)
  27.  
  28. # some plotting using numpy's logical indexing
  29. plot(features[idx==0,0],features[idx==0,1],'ob',
  30. features[idx==1,0],features[idx==1,1],'or')
  31. plot(centroids[:,0],centroids[:,1],'sg',markersize=8)
  32. show()
Add Comment
Please, Sign In to add comment