0

I have a raster file with the extent of [-169.04000663757324, 42.95999826798774, -54.3399982452392, 9.76000022888184]

I want to extract part of this raster by bounding box of (-148.966066831209, 64.22028035980699, -148.32886683120898, 64.444380359807)

Is there any way to do that?

1
  • 4
    Read the documentation of gdal_translate and/or gdalwarp.
    – user30184
    Aug 16, 2022 at 10:16

1 Answer 1

0
from osgeo import gdal
from osgeo.gdal import gdalconst
import geopandas as gpd

inputpath = r'input_path_raster' # Original raster

outputpath = r'output_path_raster' # Save new raster

# Choose your values for minx, miny, maxx, maxy

minx = -148.966066831209
miny = 64.22028035980699
maxx = -148.32886683120898
maxy = 64.444380359807



# First option to cut the raster

cut = gdal.Warp(destNameOrDestDS = outputpath, 
                srcDSOrSrcDSTab  = inputpath,
                outputBounds     = (minx, miny, maxx, maxy),
                cropToCutline    = True,
                format           = "GTiff",
                dstSRS           = "EPSG:32635",
                outputType       = gdalconst.GDT_UInt16) # Choose the data type format

cut = None

# Second option to cut the raster

cut = gdal.Warp(destNameOrDestDS = outputpath, 
                srcDSOrSrcDSTab  = inputpath,
                outputBounds     = (minx, miny, maxx, maxy),
                cropToCutline    = True,
                copyMetadata     = True)

cut = None

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.