geoio.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:uncover-ml 作者: GeoscienceAustralia 项目源码 文件源码
def __init__(self, shape, bbox, crs, name, n_subchunks, outputdir,
                 band_tags=None):
        # affine
        self.A, _, _ = image.bbox2affine(bbox[1, 0], bbox[0, 0],
                                         bbox[0, 1], bbox[1, 1],
                                         shape[0], shape[1])
        self.shape = shape
        self.outbands = len(band_tags)
        self.bbox = bbox
        self.name = name
        self.outputdir = outputdir
        self.n_subchunks = n_subchunks
        self.sub_starts = [k[0] for k in np.array_split(
                           np.arange(self.shape[1]),
                           mpiops.chunks * self.n_subchunks)]

        # file tags don't have spaces
        if band_tags:
            file_tags = ["_".join(k.lower().split()) for k in band_tags]
        else:
            file_tags = [str(k) for k in range(self.outbands)]
            band_tags = file_tags

        if mpiops.chunk_index == 0:
            # create a file for each band
            self.files = []
            for band in range(self.outbands):
                output_filename = os.path.join(outputdir, name + "_" +
                                               file_tags[band] + ".tif")
                f = rasterio.open(output_filename, 'w', driver='GTiff',
                                  width=self.shape[0], height=self.shape[1],
                                  dtype=np.float32, count=1,
                                  crs=crs,
                                  transform=self.A,
                                  nodata=self.nodata_value)
                f.update_tags(1, image_type=band_tags[band])
                self.files.append(f)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号