import numpy as np import arcpy # Inputs xyzfile = "e:/file.xyz" outname = "e:/raster.asc" skiprows = 1 delimiter = "," ncols = 5974 nrows = 5505 xllcorner = 682000 yllcorner = 205000 cellsize = 1.0 nodataval = -9999 zgrid = np.zeros((nrows,ncols), dtype=np.float32) zgrid.fill(nodataval) # process the xyz file with open(xyzfile) as f: # if header found in xyz file, skip line 1 if skiprows == 1: next(f) # put all available xyz values into correct positions on the zeros grid, # all other positions keep the nodatavalue for line in f: item = line.rstrip().split(delimiter) #print item idx = (float(item[0])-xllcorner) / cellsize idy = (float(item[1])-yllcorner) / cellsize zgrid[idy,idx] = item[2] # write the header and grid to an ascii file with open(outname, "w") as outfile: # write ascii raster header outfile.write("ncols " + str(int(ncols))+ "\n") outfile.write("nrows " + str(int(nrows))+ "\n") outfile.write("xllcorner " + str(xllcorner) + "\n") outfile.write("yllcorner " + str(yllcorner) + "\n") outfile.write("cellsize " + str(cellsize) + "\n") outfile.write("nodata " + str("%.2f" % float(nodataval)) + "\n" + "\n") # write grid to outfile np.savetxt(outfile,zgrid[::-1], fmt="%.2f", delimiter= " ")
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.