我有一段来自here的代码,用于绘制geotiff图像(Landsat):
from mpl_toolkits.basemap import Basemap
from osgeo import osr, gdal
import matplotlib.pyplot as plt
import numpy as np
# Read the data and metadata
ds = gdal.Open(filename)
data = ds.ReadAsArray()
gt = ds.GetGeoTransform()
proj = ds.GetProjection()
xres = gt[1]
yres = gt[5]
# get the edge coordinates and add half the resolution
# to go to center coordinates
xmin = gt[0] + xres * 0.5
xmax = gt[0] + (xres * ds.RasterXSize) - xres * 0.5
ymin = gt[3] + (yres * ds.RasterYSize) + yres * 0.5
ymax = gt[3] - yres * 0.5
ds = None
# create a grid of xy coordinates in the original projection
xy_source = np.mgrid[xmin:xmax+xres:xres, ymax+yres:ymin:yres]
# Create the figure and basemap object
m = Basemap(projection='robin', lon_0=0, resolution='c')
# Create the projection objects for the convertion
inproj = osr.SpatialReference()
inproj.ImportFromWkt(proj)
# Get the target projection from the basemap object
outproj = osr.SpatialReference()
outproj.ImportFromProj4(m.proj4string)
size = xy_source[0,:,:].size
ct = osr.CoordinateTransformation(inproj, outproj)
xy_target = np.array(ct.TransformPoints(xy_source.reshape(2, size).T))
但是,它在ct.TransformPoints(xy_source.reshape(2, size).T))
失败了,我不知道为什么。它给我的错误是:
TypeError: in method 'CoordinateTransformation_TransformPoints', argument 1 of type 'OSRCoordinateTransformationShadow *'
我不明白。有OSR专家在吗?在
谢谢你的阅读。在
编辑1my.TIFF的投影
^{pr2}$还有
>>> m.proj4string
Out[43]: '+lon_0=0.0 +y_0=8615499.05007 +R=6370997.0 +proj=robin +x_0=16986796.165 +units=m '
{cd1>安装包的解决方案是^。否则,
osr
无法理解输入投影。在相关问题 更多 >
编程相关推荐