numpy 배열을 래스터로 변환 한 후 이상한 좌표
NumPy 배열과 경계 상자 좌표가 있습니다. 이 답변을 기반으로 rasterio를 사용하여 래스터로 변환하려고 시도 했으며 래스터로 저장했지만 rasterio.show를 사용할 때 좌표가 매우 잘못되었습니다.
이것은 내가 사용한 스크립트입니다.
bbox_coords_wgs84=[-101.7359960059834, 20.21904081937658, -100.5717967351885, 20.8312118894487]
#variables for the projection:
minx=bbox_coords_wgs84[0]
maxy=bbox_coords_wgs84[3]
pixel_size= 10
#according to the post on GIS SO:
import rasterio
from rasterio.transform import from_origin
transform=from_origin(minx,maxy,pixel_size,pixel_size)
crs_img='EPSG:4326'
with rasterio.open('test1.tif',
'w',
driver='GTiff',
height=ndvi.shape[0],
width=ndvi.shape[1],
count=1,
dtype=ndvi.dtype,
crs=crs_img,
nodata=None, # change if data has nodata value
transform=transform) as dst:
dst.write(ndvi, 1)
#display the results:
from matplotlib import pyplot
from rasterio.plot import show
src = rasterio.open('test1.tif')
show(src)
![](https://post.nghiatu.com/assets/images/s/TQ2Yb.png)
보시다시피 숫자는 절대적으로 정확한 좌표가 아닙니다.
내 최종 목표는 NumPy 배열을 WGS84로 올바르게 재 투영하는 것입니다.
*이 게시물은이 게시물과도 관련 이 있습니다.
답변
이것이 당신이 사용 하는 affine transform을 가진 Reproject a NumPy 배열 의 모음이라고보고하지 않습니다.rasterio.transform.from_bounds
에서 rasterio.transform 모듈
rasterio.transform.from_bounds (west, south, east, north, width, height)
주어진 경계, 너비 및 높이가 지정된 Affine 변환을 반환합니다.
서쪽, 남쪽, 동쪽, 북쪽 경계와 너비 및 높이 (픽셀 수)가 지정된 지리 참조 된 래스터에 대한 Affine 변환을 반환합니다.
과
rasterio.transform.from_origin (west, north, xsize, ysize)
왼쪽 상단과 픽셀 크기가 주어지면 Affine 변환을 반환합니다.
지리 참조 된 래스터의 왼쪽 위 모서리 서쪽, 북쪽 및 픽셀 크기 xsize, ysize의 좌표가 주어지면 Affine 변환을 반환합니다.
같은 것이 아니고 결과가 다릅니다
rasterio.transform.from_bounds( -101.7359960059834,20.21904081937658,-100.5717967351885,20.8312118894487,1103,2039)
Affine(0.0010554843796871222, 0.0, -101.7359960059834,
0.0, -0.0003002310299519955, 20.8312118894487)
rasterio.transform.from_origin(-101.7359960059834,20.8312118894487,10,10)
Affine(10.0, 0.0, -101.7359960059834,
0.0, -10.0, 20.8312118894487)
새로운
경계에서 래스터의 네 모서리 (너비 = 1103, 높이 = 2039)
fig,ax = plt.subplots()
ax.plot(0,0,'ro')
ax.plot(1103,0,'bo')
ax.plot(0,2039,'go')
ax.plot(1103,2039,'co')
plt.show()
![](https://post.nghiatu.com/assets/images/s/GTDob.png)
변형
trans = rasterio.transform.from_bounds(-101.7359960059834,20.21904081937658-100.5717967351885,20.8312118894487,1103,2039)
trans*(0,0)
(-101.7359960059834, 20.8312118894487)
trans*(1103,0)
(-100.5717967351885, 20.8312118894487)
trans*(0,2039)
(-101.7359960059834, 20.21904081937658)
trans*(1103,2039)
(-100.5717967351885, 20.21904081937658)
fig,ax = plt.subplots()
ax.plot(*(trans*(0,0)),'ro')
ax.plot(*(trans*(1103,0)),'bo')
ax.plot(*(trans*(0,2039)),'go')
ax.plot(*(trans*(1103,2039)),'co')
plt.show()
![](https://post.nghiatu.com/assets/images/s/yVPqL.png)