首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >rasterio变换与仿射

rasterio变换与仿射
EN

Stack Overflow用户
提问于 2016-08-17 16:46:18
回答 1查看 6.5K关注 0票数 4

我试着做一些基本的图像过滤。我从rasterio食谱中逐字添加了一个片段(我从中值过滤器输出中删除了.astype() )。问题是,我的输入和输出光栅应该有相同的程度,但没有。对于输入和输出,变换和仿射是不同的。这是预期的行为吗?我是否需要对仿射进行一些处理并进行转换,以使输出与输入相同?

Python2.7.11\Anaconda 4.0.0 ( 64位)x(缺省值,2016年2月16日,09:58:36) MSC v.1500 64位(AMD64) on win32

rasterio==0.36.0

代码语言:javascript
复制
import rasterio
from scipy.signal import medfilt

path = "map.tif"
output = "map2.tif"

with rasterio.open(path) as src:
    array = src.read()
    profile = src.profile

# apply a 5x5 median filter to each band
filtered = medfilt(array, (1, 5, 5))

# Write to tif, using the same profile as the source
with rasterio.open(output, 'w', **profile) as dst:
    dst.write(filtered)

    print profile
    print dst.profile

>>> {'count': 1, 'crs': CRS({'init': u'epsg:3857'}), 'interleave': 'band', 'dtype': 'float64', 'affine': Affine(100.0, 0.0, -13250000.0, 0.0, 100.0, 3980000.0), 'driver': u'GTiff', 'transform': (-13250000.0, 100.0, 0.0, 3980000.0, 0.0, 100.0), 'height': 1700, 'width': 1700, 'tiled': False, 'nodata': None}
>>> {'count': 1, 'crs': CRS({'init': u'epsg:3857'}), u'interleave': 'band', 'dtype': 'float64', 'affine': Affine(-13250000.0, 100.0, 0.0, 3980000.0, 0.0, 100.0), 'driver': u'GTiff', 'transform': (0.0, -13250000.0, 100.0, 100.0, 3980000.0, 0.0), 'height': 1700, 'width': 1700, u'tiled': False, 'nodata': None}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-18 15:08:50

rasterio文档包括一个您可能认为有用的历史仿射/变换用法。我以前有几行代码来处理这个问题,如下所示:

代码语言:javascript
复制
out_profile = src.profile.copy()
out_affine = out_profile.pop("affine")
out_profile["transform"] = out_affine

# then, write the output raster

with rasterio.open(output, 'w', **out_profile) as dst:
    dst.write(filtered)

我认为这才是必要的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39002173

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档