用rasterio调整栅格阵列时如何限制小数
我有多个栅格图像。当前,所有单元格都有一个数值的值。我想将此视为百分比。我使用以下代码做到这一点:
这可以正常工作,但是它为某些值创建了很多小数(33.33333333)。因为我正在使用大型横梁,所以这大大增加了文件大小。我不需要很多小数,那么如何限制它们?
import rasterio as rio
def Percentage(path_in, granule):
path_out = os.path.join(certain_path, granule + ".jp2")
for granule in glob.glob(r"path_to_rasters\*"):
with rio.open(path_in) as src:
# Read as numpy array
array = src.read()
profile = src.profile
array = (array / count) * 100
with rio.open(path_out, 'w', **profile) as dst:
# Write to disk
dst.write(array)
I have multiple raster images. Currently all the cells have a value which is a count of something. I would like to have this as a percentage. I did this with the following code:
This works fine, but it creates a lot of decimals for some values (33.33333333). Because I'm working with big rasters this greatly increases file size. I do not have need for a lot of decimals, so how do I limit them?
import rasterio as rio
def Percentage(path_in, granule):
path_out = os.path.join(certain_path, granule + ".jp2")
for granule in glob.glob(r"path_to_rasters\*"):
with rio.open(path_in) as src:
# Read as numpy array
array = src.read()
profile = src.profile
array = (array / count) * 100
with rio.open(path_out, 'w', **profile) as dst:
# Write to disk
dst.write(array)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这个小数的三个小数:
编写ASCII时对我有用。
Try this, for 3 decimals:
It worked for me when writing a ASCII.