Skip to main content
Tweeted twitter.com/StackGIS/status/1574368209108697095
edited tags
Link
Ian Turton
  • 83.2k
  • 6
  • 89
  • 189
title statement; naming; formatting
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

How to merge Merge rasters and clip by a shapefile

I was wondering how to merge multiple tiff files together and clip the mosaic by the bounds of a intersecting shapefile. I've been able to merge them and output as a .tiff, but am not sure how to to mask the mosaic before outputting.

import os import rasterio from rasterio.merge importI was wondering how to merge

tiffs_path = ['my_file1','my_file2' ]

shape_path = 'my_shape'

raster_to_mosaic = [] for x in tiffs_path: raster = rasterio.open(x) raster_to_mosaic.append(raster)

multiple TIFF files together and clip the mosaic, output = merge(raster_to_mosaic)

output_meta = raster.meta.copy() output_meta by the bounds of a intersecting shapefile.update({ 'driver' I've been able to merge them and output as a :'GTiff', 'height': mosaic.shape[1]tiff, 'width': but am not sure how to to mask the mosaic before outputting.shape[2], 'crs':'EPSG:4326', 'compress':'lzw', 'transform': output })

with rasterio.open('merged_raster.tiff', 'w+', **output_meta) as m: m.write(mosaic)

import os 
import rasterio 
from rasterio.merge import merge

tiffs_path = ['my_file1','my_file2' ]

shape_path = 'my_shape'

raster_to_mosaic = []
for x in tiffs_path:
    raster = rasterio.open(x)
    raster_to_mosaic.append(raster)

mosaic, output = merge(raster_to_mosaic)

output_meta = raster.meta.copy()
output_meta.update({
        'driver' :'GTiff',
        'height': mosaic.shape[1],
        'width': mosaic.shape[2],
        'crs':'EPSG:4326',
        'compress':'lzw',
        'transform': output
        })

with rasterio.open('merged_raster.tiff', 'w+', **output_meta) as m:
        m.write(mosaic)

How to merge rasters and clip by a shapefile

I was wondering how to merge multiple tiff files together and clip the mosaic by the bounds of a intersecting shapefile. I've been able to merge them and output as a .tiff, but am not sure how to to mask the mosaic before outputting.

import os import rasterio from rasterio.merge import merge

tiffs_path = ['my_file1','my_file2' ]

shape_path = 'my_shape'

raster_to_mosaic = [] for x in tiffs_path: raster = rasterio.open(x) raster_to_mosaic.append(raster)

mosaic, output = merge(raster_to_mosaic)

output_meta = raster.meta.copy() output_meta.update({ 'driver' :'GTiff', 'height': mosaic.shape[1], 'width': mosaic.shape[2], 'crs':'EPSG:4326', 'compress':'lzw', 'transform': output })

with rasterio.open('merged_raster.tiff', 'w+', **output_meta) as m: m.write(mosaic)

Merge rasters and clip by a shapefile

I was wondering how to merge multiple TIFF files together and clip the mosaic by the bounds of a intersecting shapefile. I've been able to merge them and output as a .tiff, but am not sure how to to mask the mosaic before outputting.

import os 
import rasterio 
from rasterio.merge import merge

tiffs_path = ['my_file1','my_file2' ]

shape_path = 'my_shape'

raster_to_mosaic = []
for x in tiffs_path:
    raster = rasterio.open(x)
    raster_to_mosaic.append(raster)

mosaic, output = merge(raster_to_mosaic)

output_meta = raster.meta.copy()
output_meta.update({
        'driver' :'GTiff',
        'height': mosaic.shape[1],
        'width': mosaic.shape[2],
        'crs':'EPSG:4326',
        'compress':'lzw',
        'transform': output
        })

with rasterio.open('merged_raster.tiff', 'w+', **output_meta) as m:
        m.write(mosaic)
added 12 characters in body
Source Link
uqazi
  • 41
  • 3

I was wondering how to merge multiple tiff files together and clip the mosaic by the bounds of a intersecting shapefile. I've been able to merge them and output as a .tiff, but am not sure how to to mask the mosaic before outputting.

I was wondering how to merge multiple tiff files together and clip the mosaic by the bounds of a intersecting shapefile. I've been able to merge them and output as a .tiff, but am not sure how to to mask the mosaic before outputting.

import os import rasterio from rasterio.merge import merge

tiffs_path = ['my_file1','my_file2' ]

shape_path = 'my_shape'

raster_to_mosaic = [] for x in tiffs_path: raster = rasterio.open(x) raster_to_mosaic.append(raster)

mosaic, output = merge(raster_to_mosaic)

output_meta = raster.meta.copy() output_meta.update({ 'driver' :'GTiff', 'height': mosaic.shape[1], 'width': mosaic.shape[2], 'crs':'EPSG:4326', 'compress':'lzw', 'transform': output })

with rasterio.open('merged_raster.tiff', 'w+', **output_meta) as m: m.write(mosaic)

I was wondering how to merge multiple tiff files together and clip the mosaic by the bounds of a intersecting shapefile. I've been able to merge them and output as a .tiff, but am not sure how to to mask the mosaic before outputting.

import os import rasterio from rasterio.merge import merge

tiffs_path = ['my_file1','my_file2' ]

shape_path = 'my_shape'

raster_to_mosaic = [] for x in tiffs_path: raster = rasterio.open(x) raster_to_mosaic.append(raster)

mosaic, output = merge(raster_to_mosaic)

output_meta = raster.meta.copy() output_meta.update({ 'driver' :'GTiff', 'height': mosaic.shape[1], 'width': mosaic.shape[2], 'crs':'EPSG:4326', 'compress':'lzw', 'transform': output })

with rasterio.open('merged_raster.tiff', 'w+', **output_meta) as m: m.write(mosaic)

I was wondering how to merge multiple tiff files together and clip the mosaic by the bounds of a intersecting shapefile. I've been able to merge them and output as a .tiff, but am not sure how to to mask the mosaic before outputting.

import os import rasterio from rasterio.merge import merge

tiffs_path = ['my_file1','my_file2' ]

shape_path = 'my_shape'

raster_to_mosaic = [] for x in tiffs_path: raster = rasterio.open(x) raster_to_mosaic.append(raster)

mosaic, output = merge(raster_to_mosaic)

output_meta = raster.meta.copy() output_meta.update({ 'driver' :'GTiff', 'height': mosaic.shape[1], 'width': mosaic.shape[2], 'crs':'EPSG:4326', 'compress':'lzw', 'transform': output })

with rasterio.open('merged_raster.tiff', 'w+', **output_meta) as m: m.write(mosaic)

Source Link
uqazi
  • 41
  • 3
Loading