2

I have two raster layers.

(A) is state-sized, 30m.

(B) is county-sized, 3m.

I'd like to get a new raster (C) which is the part of (A) which coincides with (B), preferably scaled to the same resolution as (B).

Is there a way to do this from the command line? From Python or C++?

1 Answer 1

4

This is best done with the gdalwarp command-line tool. The functionality also has a GDAL Warp API for C++ and is exposed for Python too (see help(gdal.ReprojectImage) from a Python shell).

For example, using the gdalwarp command-line:

gdalwarp -te xmin ymin xmax ymax -tr 3 3 -r bilinear A_state_30m.tif C_county_3m.tif

where:

  • -te target extents, you need to supply this from your (B) county-sized raster; try using gdalinfo to help determine this extent
  • -tr target resolution, 3 m
  • -r bilinear, a good algorithm for orthophotos and DEMs, but not for others; other algorithms are available
  • A_state_30m.tif, input (A) file
  • C_county_3m.tif, output (C) file
2
  • 1
    I didn't get where the overlap is obtained.
    – wondim
    Jan 22, 2020 at 14:23
  • @wondim this does not do any intersection. You need to specify -te xmin ymin xmax ymax and -tr 3 3 based on the reference raster that needs to be matched to.
    – Mike T
    Jan 22, 2020 at 21:02

Your Answer

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

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