Skip to content

Instantly share code, notes, and snippets.

@xinyuanwylb19
Last active June 4, 2019 00:09
Show Gist options
  • Save xinyuanwylb19/bd494578db3aa5abe6f9d1079d0913af to your computer and use it in GitHub Desktop.
Save xinyuanwylb19/bd494578db3aa5abe6f9d1079d0913af to your computer and use it in GitHub Desktop.
Moving Windows
#Version 1.0
#Xinyuan Wei 04/22/2018
'''
This program can reconstruct the .
'''
import numpy as np
import gdal
import osr
#read the .csv data
SDWs=np.genfromtxt('3.MW_Process.csv',delimiter=',')
#create a map 2900*2900
array=[[0 for x in range (2900)] for y in range (2900)]
array=np.array(array)
#Reconstruct the G-FC map
for i in range (801):
print(i)
for j in range (801):
if SDWs[i][j]>1:
array[i:(i+2100),j:(j+2100)]=array[i:(i+2100),j:(j+2100)]+1
#np.savetxt('EER_1200.csv',array,delimiter=',')
#conver array to raster
def arraytoraster(newRaster,rasterOrigin,pixelWidth,pixelHeight,array):
cols=array.shape[1]
rows=array.shape[0]
originX=rasterOrigin[0]
originY=rasterOrigin[1]
driver=gdal.GetDriverByName('GTiff')
outRaster=driver.Create(newRaster,cols,rows,1,gdal.GDT_UInt16)
outRaster.SetGeoTransform((originX, pixelWidth,0,originY,0,pixelHeight))
outband=outRaster.GetRasterBand(1)
outband.WriteArray(array)
outRasterSRS=osr.SpatialReference()
outRasterSRS.ImportFromEPSG(4326)
outRaster.SetProjection(outRasterSRS.ExportToWkt())
outband.FlushCache()
rasterOrigin=(0,0)
pixelWidth=1
pixelHeight=1
newRaster='EER_1200.img'
array=np.array(array)
arraytoraster(newRaster,rasterOrigin,pixelWidth,pixelHeight,array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment