如何在GTIFF中记录反射率和辐射率

时间:2019-07-09 04:09:30

标签: python glob gdal

有2个文件:
1.数据包括反射率和辐射率。
2.包含该地点的坐标参考。

如何将此数据绑定到GEOTIFF文件。 尝试了很多选择。 什么都没想到。

获得总数的方法

def getRadianceAndReflectance(filePath):
    with h5py.File(filePathToSVI01, "r") as f:
        a_group_key = list(f.keys())
        group = f['All_Data']
        data = group['VIIRS-I1-SDR_All']
        print(data['/All_Data/VIIRS-I1-SDR_All/Radiance'])
        print(data['/All_Data/VIIRS-I1-SDR_All/Reflectance'])

        n1 = np.array(data['/All_Data/VIIRS-I1-SDR_All/Radiance'])
        n2 = np.array(data['/All_Data/VIIRS-I1-SDR_All/Reflectance'])
    return Data(n1, n2)
def getLatLon(filePath):
    with h5py.File(filePath, "r") as f:
        data = f['All_Data']
        dt = data['/All_Data/']
        inputArray = np.array(dt['/All_Data/VIIRS-IMG-GEO_All/Latitude'])
        resultArray = inputArray[inputArray[..., 0] >= 0]
        secondInputArray = np.array(dt['/All_Data/VIIRS-IMG GEO_All/Longitude'])
        secondResultArray = secondInputArray[secondInputArray[..., 0] >= 0]
    return Coord(resultArray, secondResultArray)

写到文件然后出现问题

from osgeo import gdal
from osgeo import osr
import numpy as np
import os, sys

image_size = (400,400)

obj = getLatLon(filePathToGIMGO)

#  Choose some Geographic Transform (Around Lake Tahoe)
lat = [obj.lat.min(),obj.lat.max()]
lon = [obj.lon.min(),obj.lon.max()]
print(lat)
print(lon)

#  Create Each Channel

#r_pixels = np.zeros((image_size), dtype=np.uint8)
#g_pixels = np.zeros((image_size), dtype=np.uint8)
#b_pixels = np.zeros((image_size), dtype=np.uint8)

#  Set the Pixel Data (Create some boxes)
for x in range(0,image_size[0]):
    for y in range(0,image_size[1]):
        if x < image_size[0]/2 and y < image_size[1]/2:
            r_pixels[y,x] = 255
        elif x >= image_size[0]/2 and y < image_size[1]/2:
            g_pixels[y,x] = 255
        elif x < image_size[0]/2 and y >= image_size[1]/2:
            b_pixels[y,x] = 255
        else:
            r_pixels[y,x] = 255
            g_pixels[y,x] = 255
            b_pixels[y,x] = 255

# set geotransform
nx = image_size[0]
ny = image_size[1]
xmin, ymin, xmax, ymax = [min(lon), min(lat), max(lon), max(lat)]
xres = (xmax - xmin) / float(nx)
yres = (ymax - ymin) / float(ny)
geotransform = (xmin, xres, 0, ymax, 0, -yres)

var = getRadianceAndReflectance(filePathToSVI01) #get Radiance and Reflectance
# I need to write an int array

# create the 3-band raster file
dst_ds = gdal.GetDriverByName('GTiff').Create('myGeoTIFF.tif', 1500, 1500, 3, 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()   # This!

dst_ds.FlushCache()                     # write to disk
dst_ds = None

请帮助我,我在Google上花费了很多时间。一切都没用。

0 个答案:

没有答案