1

I downloaded a bunch of images from Maxar's Open Data program covering pre- and post-images of recent disasters. See https://www.maxar.com/open-data

The pre-event and post-event images cover the same (or very similar) areas of interest. In other words, the intersection of a pair of pre- and post-event images is almost the same as the union of the pair, but not necessarily the same.

What I would like to do is to use QGIS to take a pair of pre- and post-images covering a given location and then crop the images into, say 512 by 512 pixels, chips such that in the intersection of the pair of images, a chip from the pre-image would have a matching chip covering exactly the same coordinates from the post-image.

Any ideas on how I can do that?

2
  • My scripts (bash and Python) may help you to create image mosaics: github.com/OSGeoLabBp/tutorials/blob/master/english/…
    – Zoltan
    Commented Dec 23, 2020 at 18:12
  • Thanks, @Zoltan. The challenge here though is that I want a chip from the pre-image to have a matching chip from the post-image. Your script would work if the pre-image covers exactly the same location as the post-image. Unfortunately the images in the Open Data program are often partially offset so applying the script to the images would give us mismatched chips.
    – TCR
    Commented Dec 23, 2020 at 18:39

2 Answers 2

1

Extending my comment I upgraded my script to handle more input parameters called mosaicplus.py. It is available on GitHub: https://github.com/OSGeoLabBp/tutorials/blob/master/english/data_processing/lessons/code/mosaicplus.py

Here is the usage info:

mosaicplus.py [-h] [--rows ROWS] [--cols COLS] [--width WIDTH]
                     [--height HEIGHT] [--minx MINX] [--miny MINY]
                     [--maxx MAXX] [--maxy MAXY] [--over OVER]
                     [file_names [file_names ...]]

positional arguments:
  file_names       image files to process

optional arguments:
  -h, --help       show this help message and exit
  --rows ROWS      number of mosaic rows, default 4
  --cols COLS      number of mosaic cols, default 4
  --width WIDTH    width of mosaic tiles
  --height HEIGHT  height of mosaic tiles
  --minx MINX      minimal x coordinate of extent to clip from image
  --miny MINY      minimal y coordinate of extent to clip from image
  --maxx MAXX      maximal x coordinate of extent to clip from image
  --maxy MAXY      maximal y coordinate of extent to clip from image
  --over OVER      overlap between rows and columns in pixels, default 1
  --extend         create last patial row and column

You should find first the common area of the two rasters in projected coordinates

python3 mosaicplus.py --width 512 --height 512 --minx 608100 --miny 170200 --maxx 750000 --maxy 313000 first.tif second.tif

The output files are in the same folder as the input image.

4
  • Thank you! Your script worked perfectly!
    – TCR
    Commented Jan 5, 2021 at 14:24
  • Is there a way that you can further extend your script so that it exhausts the entire original image by padding black parts to the last part of the image? For example, say the image is 1,100 by 1,100 pixels and I want to chip it 500 by 500 pixels. Currently the script would create four chips leaving out the 100 pixels on the right and 100 pixels on the bottom. What I want is to include those as well by padding them with black pixels.
    – TCR
    Commented Jan 14, 2021 at 18:23
  • I've added a new switch --extend to get partial column and row. Please download again mosaicplus.py from GitHub.
    – Zoltan
    Commented Jan 14, 2021 at 23:09
  • This is fantastic! Thank you!
    – TCR
    Commented Jan 15, 2021 at 20:38
1

You can solve it with three processing tools:

  1. Extract layer extents, one for pre and one for post
  2. Intersect them
  3. Clip raster by mask layer, with the intersection as mask layer
1
  • 1
    This was great; thank you! As an aside, do you know why the image resolution (the number of pixels) are not the same after Clip raster by mask layer?
    – TCR
    Commented Jan 5, 2021 at 14:24

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.