簡體   English   中英

從長緯度坐標和高程數據創建 tif 文件

[英]Create tif file from long lat coordinate and elevation data

我想從坐標數據和高程數據列表中創建一個 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
-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 中做到這一點?

我在這里使用答案幾乎成功地回答了我自己的問題:

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

但是,它將紅色值寫為正值而不是負值。 紅色數組是 -78..-76 但它寫成 180..178 我不知道為什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM