Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

计算meanDEM ,计算影像范围区域行列有误 #6

Open
farewell-lc opened this issue May 27, 2021 · 0 comments
Open

计算meanDEM ,计算影像范围区域行列有误 #6

farewell-lc opened this issue May 27, 2021 · 0 comments

Comments

@farewell-lc
Copy link

in base.py

# DEM分辨率 pixelWidth = geotransform[1] pixelHight = geotransform[5]
# DEM起始点:左上角,X:经度,Y:纬度    originX = geotransform[0]    originY = geotransform[3]
# 研究区左上角在DEM矩阵中的位置    yoffset1 = int((originY - pointUL['lat']) / pixelWidth)    xoffset1 = int((pointUL['lon'] - originX) / (-pixelHight))
# 研究区右下角在DEM矩阵中的位置    yoffset2 = int((originY - pointDR['lat']) / pixelWidth)    xoffset2 = int((pointDR['lon'] - originX) / (-pixelHight))
# 研究区矩阵行列数    xx = xoffset2 - xoffset1    yy = yoffset2 - yoffset1    # 读取研究区内的数据,并计算高程    DEMRasterData = DEMBand.ReadAsArray(xoffset1, yoffset1, xx, yy)<br class="Apple-interchange-newline"><!--EndFragment-->

计算出的影像区域行列起始号与行列数存在问题,建议如下写法:

geo = ds.GetGeoTransform()
inv_geo = gdal.InvGeoTransform(geo)
pointUL = dict()
pointDR = dict()
pointUL["lat"] = float(''.join(re.findall('CORNER_UL_LAT_PRODUCT.+',data2)).split("=")[1])
pointUL["lon"] = float(''.join(re.findall('CORNER_LL_LON_PRODUCT.+',data2)).split("=")[1])
pointDR["lat"] = float(''.join(re.findall('CORNER_LR_LAT_PRODUCT.+',data2)).split("=")[1])
pointDR["lon"] = float(''.join(re.findall('CORNER_UR_LON_PRODUCT.+',data2)).split("=")[1])
extent = [pointUL["lon"], pointUL["lat"], pointDR["lon"], pointDR["lat"]]

off_ulx, off_uly = map(int, gdal.ApplyGeoTransform(inv_geo, extent[0], extent[1]))
off_drx, off_dry = map(math.ceil, gdal.ApplyGeoTransform(inv_geo, extent[2], extent[3]))
columns = off_drx - off_ulx
rows = off_dry - off_uly

data = ds.GetRasterBand(1).ReadAsArray(off_ulx, off_uly, columns, rows)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant