Example #1
0
def reproject_like(this, reproject_this):
    dst = MemoryFile()

    d_transform, d_width, d_height = calculate_default_transform(
        reproject_this.crs, this.crs, reproject_this.width,
        reproject_this.height, *reproject_this.bounds)

    dst_profile = reproject_this.profile.copy()
    dst_profile.update({
        "driver": "GTiff",
        "crs": this.crs,
        "transform": d_transform,
        "width": d_width,
        "height": d_height,
    })
    #
    with rio.open(dst, 'w', **dst_profile) as dst_file:
        reproject(source=reproject_this.read(1),
                  destination=rio.band(dst_file, 1),
                  src_transform=reproject_this.transform,
                  src_crs=reproject_this.crs,
                  dst_transform=d_transform,
                  dst_crs=this.crs,
                  resampling=Resampling.bilinear)

    dst.seek(0)
    return dst.open()
Example #2
0
 def fp_writer(fp):
     memfile = MemoryFile()
     dataset = memfile.open(driver=driver, width=width, height=height,
                            count=count, crs=crs, transform=transform,
                            dtype=dtype, nodata=nodata, **kwargs)
     try:
         yield dataset
     finally:
         dataset.close()
         memfile.seek(0)
         fp.write(memfile.read())
         memfile.close()
 def fp_writer(fp):
     memfile = MemoryFile()
     dataset = memfile.open(driver=driver, width=width, height=height,
                            count=count, crs=crs, transform=transform,
                            dtype=dtype, nodata=nodata, sharing=sharing, **kwargs)
     try:
         yield dataset
     finally:
         dataset.close()
         memfile.seek(0)
         fp.write(memfile.read())
         memfile.close()