将光栅转换为点的工具
raster2points的Python项目详细描述
拉斯特2分
将一个或多个光栅图像转换为点。 工具将读取第一个输入光栅并提取纬度/经度坐标和值 对于所有有数据的像素。可选它根据像素大小计算每个点的测地线面积。 连续输入光栅将使用来自第一个输入光栅的数据掩码。
返回pandas数据框,cli将结果导出为csv文件。
输入文件可以是本地文件路径或s3路径,也可以是混合路径。供阅读
S3,你需要AWS credentials configured,
例如在环境中使用~/.aws
中的配置文件和AWS_PROFILE
变量。
multi-worker只处理s3输入,不处理本地文件。
安装和依赖项
此模块使用光栅,需要GDAL>=1.11
。
使用pip安装。
pip install raster2points
cli用法:
raster2csv.py [-h][--col_names COL_NAMES [COL_NAMES ...]][--separator {,,;,t}][--max_block_size MAX_BLOCK_SIZE][--calc_area [CALC_AREA]][--workers WORKERS] INPUT [INPUT ...] OUTPUT
python用法
也可以在python中直接使用该模块。它将返回 熊猫数据框与您的数据。
获取熊猫数据帧
fromraster2pointsimportraster2dfraster1="path/to/file1.tif"raster2="path/to/file2.tif"df=raster2df(raster1,raster2,col_names=["name1","name2"],calc_area=True)print(df.columns)print(df.dtypes)df.head()
导出到TSV
fromraster2pointsimportraster2csvraster1="path/to/file1.tif"raster2="path/to/file2.tif"output="path/to/newfile.tsv"raster2csv(raster1,raster2,output,col_names=["name1","name2"],separator="\t",calc_area=True)