将栅格像元大小与另一个栅格匹配

问题描述 投票:0回答:1

我一直在使用发布的here代码将栅格的像元大小与另一个栅格相匹配。更具体地说,我有一个带有20m cell \ pixel size的sentinel-2 band(jp2格式)波段,我想将\ resample \ resize它调整为10m。到目前为止,我做的很棒,就是使用我添加的链接中的脚本,我输入两个光栅:20米波段,另一个10米波段。它们都具有相同的空间范围,相同的crs。我现在遇到的奇怪问题是这个脚本仍然有效,但输出栅格大小约为500mb,原始大小约为1000kb。我不明白为什么会发生这种情况。有任何想法吗?我在win 10机器上使用python 3。如果你有另一种方法使用gdalrasterio或其他python图书分割单元格大小,它也可能有所帮助。我只想将每20m像素分成4个像素的10m,具有相同的值,即每个新的10m单元将具有20m单元的相同值。我正在发布我正在使用的代码:

from osgeo import gdal, gdalconst

# Source
src_filename = r'C:\SN2 sr\T36SXB_20180406T081601_B05_20m.jp2'
src = gdal.Open(src_filename, gdalconst.GA_ReadOnly)
src_proj = src.GetProjection()
src_geotrans = src.GetGeoTransform()

# We want a section of source that matches this:
match_filename = r"C:\SN2 sr\T36SXB_20180406T081601_B04_10m.jp2"
match_ds = gdal.Open(match_filename, gdalconst.GA_ReadOnly)
match_proj = match_ds.GetProjection()
match_geotrans = match_ds.GetGeoTransform()
wide = match_ds.RasterXSize
high = match_ds.RasterYSize

# Output / destination
dst_filename = r'C:\SN2 sr\try5.jp2'
dst = gdal.GetDriverByName('Gtiff').Create(dst_filename, wide, high, 1, gdalconst.GDT_Float32)
dst.SetGeoTransform( match_geotrans )
dst.SetProjection( match_proj)

# Do the work
gdal.ReprojectImage(src, dst, src_proj, match_proj, gdalconst.GRA_NearestNeighbour)

del dst # Flush

print ("finish")
python image-resizing gdal resampling rasterio
1个回答
0
投票

奇怪的问题,因为代码看起来不错。我猜两个原始的sentinel-2文件也是Float32,所以这可能不是问题。我提到的一件事是当你创建新文件时,你正在使用'Gtiff'驱动程序指定'.jp2'扩展名。 jp2的驱动程序是'JPEG2000'。这可能是你的问题?希望能帮助到你

© www.soinside.com 2019 - 2024. All rights reserved.