Example #1
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()
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,
                            sharing=sharing,
                            **kwargs)
     try:
         yield dataset
     finally:
         dataset.close()
         memfile.seek(0)
         fp.write(memfile.read())
         memfile.close()
Example #3
0
# #Subset the region of Danube RB (9 km)
# [lat_9km_dan, row_dan_9km_ind, lon_9km_dan, col_dan_9km_ind] = \
#     coordtable_subset(lat_world_ease_9km, lon_world_ease_9km, shp_dan_extent[3], shp_dan_extent[2], shp_dan_extent[1], shp_dan_extent[0])

masked, mask_transform = mask(dataset=dst, shapes=crop_shape, crop=True)

reproj_out = rasterio.open('/Users/binfang/Downloads/raster.tif',
                           'w',
                           'GTiff',
                           height=dst.height,
                           width=dst.width,
                           count=1,
                           dtype='float32',
                           crs='EPSG:4326',
                           transform=dst.transform)
reproj_out.write(dst.read().squeeze(), 1)
reproj_out.close()

########################################################################################################################
# Function 2. Subset and reproject the Geotiff data to WGS84 projection


def sub_n_reproj(input_mat, kwargs_sub, sub_window, output_crs):
    # Get the georeference and bounding parameters of subset image
    # kwargs_sub = input_ds.meta.copy()
    kwargs_sub.update({
        'height':
        sub_window.height,
        'width':
        sub_window.width,
        'transform':