Python 从长纬度坐标和高程数据创建tif文件
我想从坐标数据和高程数据列表创建tif文件。它们是我自己为解决玩具问题而创建的数据。数据如下:Python 从长纬度坐标和高程数据创建tif文件,python,Python,我想从坐标数据和高程数据列表创建tif文件。它们是我自己为解决玩具问题而创建的数据。数据如下: -78.5000 32.5000 -78 1 1 -78.5000 32.5100 -78 1 2 -78.5000 32.5200 -78 1 3 -78.5000 32.5300 -78 1 4 -78.5000 32.5400 -78 1 5 -78.5000 32.5500 -78 1 6 -78.5000 32.5600 -78 1 7 -78.5000 32.5700 -78 1 8 -7
-78.5000 32.5000 -78 1 1
-78.5000 32.5100 -78 1 2
-78.5000 32.5200 -78 1 3
-78.5000 32.5300 -78 1 4
-78.5000 32.5400 -78 1 5
-78.5000 32.5500 -78 1 6
-78.5000 32.5600 -78 1 7
-78.5000 32.5700 -78 1 8
-78.5000 32.5800 -78 1 9
-78.5000 32.5900 -78 1 10
-78.5000 32.6000 -78 1 11
-78.5000 32.6100 -78 1 12
-78.5000 32.6200 -78 1 13
-78.5000 32.6300 -78 1 14
-78.5000 32.6400 -78 1 15
-78.5000 32.6500 -78 1 16
-78.5000 32.6600 -78 1 17
-78.5000 32.6700 -78 1 18
-78.5000 32.6800 -78 1 19
-78.5000 32.6900 -78 1 20
-78.5000 32.7000 -78 1 21
-78.5000 32.7100 -78 1 22
-78.5000 32.7200 -78 1 23
-78.5000 32.7300 -78 1 24
-78.5000 32.7400 -78 1 25
-78.5000 32.7500 -78 1 26
...
第一列是长柱,第二列是横柱,第三列是以英尺为单位的深度。第四个和第五个是另一种类型的坐标数据,用于每个网格单元的特定问题(i,j)值
如何创建这些数据的tif文件?在python中有没有实现这一点的方法 我几乎成功地用一个答案回答了自己的问题:
然而,它将红色值写为正值而不是负值。红色数组是-78..76,但它将它们写为180..178,我不知道为什么。您尝试了什么?有密码吗?我想说清楚,你说“tif”是指什么?我唯一熟悉的“tif”是。@AlexanderCécile是的,这就是我所指的tif。我还没有找到很多可以尝试的。我试着用这个,但无法找到如何让它为我工作。我只成功创建了一个.csv文件。您创建TIFF文件的目标是什么?它的用途是什么?我需要将其用作光栅统计的输入-我正在尝试从我拥有的shapefile中索引多边形内的光栅点(所以是较长的lat坐标和深度值)。然后我需要对它们进行统计。好的,我会试着在几天前给出。
from osgeo import gdal
from osgeo import osr
import numpy as np
image_size = (201,201)
lon = np.zeros((image_size), dtype=np.float64)
lat = np.zeros((image_size), dtype=np.float64)
red = np.zeros((image_size), dtype=np.int8)
for x in range(0,image_size[0]):
for y in range(0,image_size[1]):
lon[y,x] = -1*(78.5+0.01*-x)
lat[y,x] = 32.5+0.01*y
red[y,x] = lon[y,x]
# set geotransform
nx = red.shape[0]
ny = red.shape[0]
xmin, ymin, xmax, ymax = [lon.min(), lat.min(), lon.max(), lat.max()]
xres = (xmax - xmin) / float(nx)
yres = (ymax - ymin) / float(ny)
geotransform = (xmin, xres, 0, ymax, 0, -yres)
# create the 1-band raster file
dst_ds = gdal.GetDriverByName('GTiff').Create('myGeoTIFF.tif', ny, nx, 1, gdal.GDT_Byte)
dst_ds.SetGeoTransform(geotransform) # specify coords
srs = osr.SpatialReference() # establish encoding
srs.ImportFromEPSG(3857) # WGS84 lat/long
dst_ds.SetProjection(srs.ExportToWkt()) # export coords to file
dst_ds.GetRasterBand(1).WriteArray(red) # write r-band to the raster
dst_ds.FlushCache() # write to disk
dst_ds = None # save, close