我目前在将光栅转换为数组方面遇到了一些麻烦。最终我想将一个栅格从一个整数转换为一个float32,这样我就可以运行一个gdal_calc但是,为了做到这一点,我无法正确更改类型。
所以,我很感激有人可以提供任何帮助。这是我的剧本,很短。
{
Title: "Suits",
Year: "2011–",
Rated: "TV-14",
Released: "23 Jun 2011",
Runtime: "44 min",
Genre: "Comedy, Drama",
Director: "N/A",
Writer: "Aaron Korsh",
Actors: "Gabriel Macht, Patrick J. Adams, Rick Hoffman, Meghan Markle",
Plot: "On the run from a drug deal gone bad, Mike Ross, a brilliant college-dropout, finds himself a job working with Harvey Specter, one of New York City's best lawyers.",
Language: "English",
Country: "USA",
Awards: "7 nominations.",
Poster: "http://ia.media-imdb.com/images/M/MV5BMTk1MjYzOTU2Nl5BMl5BanBnXkFtZTgwMzAxMTg5MTE@._V1_SX300.jpg",
Metascore: "N/A",
imdbRating: "8.7",
imdbVotes: "244,979",
imdbID: "tt1632701",
Type: "series",
totalSeasons: "6",
Response: "True"
}
提前谢谢你,
摩西
答案 0 :(得分:2)
方法ReadAsArray()将创建一个带有栅格数据集dtype的numpy.ndarray。您的目标是将整数dtype转换为float32。最简单的方法是使用astype()方法进行ndarray。
# Convert Raster to Array
hvArray = hvRaster.GetRasterBand(1).ReadAsArray().astype(np.float32)
vhArray = vhRaster.GetRasterBand(1).ReadAsArray().astype(np.float32)
答案 1 :(得分:0)
免责声明:我是以下库的作者。
lidario.Translator可以帮助您将栅格转换为点云(np.array):
import lidario as lio
# Create a Translator object which will take a tif file and return a np.array
translator = lio.Translator("geotiff", "np")
# Translate the tif file and get the np.array
point_cloud = translator.translate("/path/to/file.tif")
Lidario在引擎盖下使用GDAL。