1

I am using QGIS (2.8.6-Wien) and I would like to do the following: Load a GeoTIFF, add a grid-layer (with cell size specified in pixels), select some cells and save each cell content as an individual image (e.g. as a .png file).

Since I am not very experienced with QGIS, I am not sure whether this is actually feasible with QGIS. What I managed to do so far is the griding. Below is a small example, where I used the Natural Earth Admin 0 - Countries dataset. I did the griding with "Vector" -> "Research Tools" -> "Vector Grid", Parameters X: 4.0, Y: 4.0 (output grid as polygons).

enter image description here

Now, I would like to select the cell indicated by "X" (Panama) and save the cell content as an image. I tried some of the QGIS geoalgorithms (Vector selection tools) but failed to reach my goal. Ultimately, I would like to select several cells and save each cell as an image, individually.

Could anyone give me a hint?

2
  • Did you try select by location?
    – aldo_tapia
    Feb 12, 2018 at 14:44
  • You could use an the atlas generator in print composer. Add a field to the grid layer and use that field to filter the atlas.
    – csk
    Feb 12, 2018 at 18:36

1 Answer 1

3

Solution using Atlas Generator

Step 1: Add a field to the vector grid layer to use as a filter

Field name: Filter; field type: whole number; field length: 1; expression: 0. enter image description here

Step 2: Selected cells in grid layer and change Filter value to 1

  • Select all cells that you want saved as images
  • Open the grid layer attribute table, turn on editing for this layer, and enter 1 in the Filter field for the selected features

enter image description here

Step 3: Set a Print Composer layout

  • Create a new print composer: Project menu > New Print Composer
  • Set page size proportional to the dimensions of the grid cells. Eg, if the cells are square, make the page length the same as the page width.

enter image description here

  • Add a map, and re-size it to fill the page

Step 4: Generate an Atlas, using the grid layer as the coverage layer and Filter field as filter

  • Set up the atlas: enter image description here

  • Select the map item, and under item properties check the box for "Controlled by Atlas."

  • Set "Margin around feature" to 0

enter image description here

Step 5: Preview and Export Atlas

  1. On the atlas toolbar, click the Preview Atlas button.
  2. Use the left and right arrow buttons to flip through the pages of the atlas and make sure they are the pages you want to print.
  3. Click the button "Export atlas as images."

enter image description here

  1. At this point you have the option to set the image width/height in pixels, or specify image resolution in DPI.

enter image description here

Note: The option to specify export resolution after clicking the Export button was introduced sometime after version 2.8. In earlier versions of QGIS, export resolution can be specified in the Composition panel of the Print Composer.

5
  • That's already quite close to what I would like to do, thanks! I would like to save the cells exactly as they are, i.e. 300 by 300 pixels for instance. If I see correctly, the suggestion so far requires to set the image size manually which distorts the actual pixel-resolution. Is there a way how to save the patches directly? Feb 13, 2018 at 13:11
  • It's possible to specify the dpi or size in pixels of the export image. I edited my answer to reflect this.
    – csk
    Feb 13, 2018 at 17:37
  • Another way to approach this question would be to use Python code to print directly from the QGIS project. I'm not very experienced with Python so I can't help with that method, but here's a link that would help if you want to explore that possibility. docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/…
    – csk
    Feb 13, 2018 at 17:40
  • Step 5.4 (choosing export options) was not available in my version of QGIS (2.8.6-Wien). After "Export atlas as images", the patches were directly saved, hence my question. With another version it works exactly as asked. Thank you very much, csk! Feb 16, 2018 at 8:49
  • I edited my answer to include a link to method for specifying export resolution in earlier versions.
    – csk
    Feb 16, 2018 at 20: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.