25

I am exporting a QGIS map to an image format. I would like to have control over the output settings of the image (dpi), as currently it is only exporting the images at 96 dpi.

Does anyone know if this is possible?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
James S
  • 4,264
  • 2
  • 32
  • 46
  • The command snapshot only works if you use a width/height values that are lower than the screen resolution (display). If not, QGIS adds a blank space to make a higher resolution image. Am I using the command properly? Try to use, for example, --height 4096 --width 4096. – user1717649 Jul 17 '13 at 09:57
  • Welcome to GIS SE! Because you say "Am I using the command properly?" I am left wondering whether you are asking another question, just answering this question or trying to make a comment. Would you perhaps be able to edit your answer to make that clearer, please? – PolyGeo Jul 17 '13 at 10:29

3 Answers3

22

Currently it's not possible to adjust the resolution of an output image using "Save as Image".

To create high-resolution output, you have to use Print Composer.

In QGIS 3 it's possible to control the extent and resolution using Export Map to Image...


There is also a way to get a high-resolution image with world file: With QGIS from command line you have the option to create PNGs in any size including world files.

Available options are:

[--snapshot filename] emit snapshot of loaded datasets to given file
[--width width] width of snapshot to emit
[--height height] height of snapshot to emit
[--project projectfile] load the given QGIS project
[--extent xmin,ymin,xmax,ymax] set initial map extent

You have to prepare your project first and then create a snapshot.

eg.

C:\Users\MyUser\QGis_Projects>qgis --snapshot italy.png --width 1500 --height 1000 --project italy.qgs
Albine Pro
  • 310
  • 2
  • 14
underdark
  • 84,148
  • 21
  • 231
  • 413
  • Thanks for answering. This way will work fine for what I need. Just a shame as it doesn't export a world file this way. – James S Nov 22 '10 at 10:50
  • I have googlemap as an additional layer in my project file. Using the commandline options above, I can render the other layers but not the googlemap layer. It doesn't cache the googlemap. I didn't test this for other WMSes. – maning Jan 11 '11 at 08:35
  • @maning: You might want to post a bug report on http://trac.osgeo.org/qgis/. – underdark Jan 11 '11 at 09:24
  • this is known problem, unfortunately, 3rd party plugins are not maintained in the core. I will try to contact the plugin author. – maning Jan 11 '11 at 11:36
  • I have trouble with Print Composer and a plug-in (RT SQL Layer). Is it a common problem? (in particular, labels are completely out of control) – Antonin Jul 13 '12 at 15:57
  • @Antonin Never heard of such a behavior before. – underdark Jul 13 '12 at 16:07
  • Oh, no, sorry, it's with a CSV file. Don't know if it changes anything. – Antonin Jul 13 '12 at 16:17
  • @underdark Where can I find the values needed for the --extent option? I am a QGIS newbie. – JJD Sep 16 '12 at 10:25
  • @underdark I am using QGIS 1.8.0 Lisboa on Ubuntu Precise. When I run the command without the --extent option QGIS launches and the QGIS start label is visible. No layer is visible. The terminal has some warnings but no error. That's it. Nothing happens. Just the busy icon of the mouse.. What can I do? – JJD Sep 16 '12 at 22:57
16

If you are willing to use the print composer in the latest versions of QGIS, it's relatively easy to get a decent map image at the resolution you want.

First, get the map looking more or less how you want in the regular editing window, then click on "New Print Composer" from the Project menu.

Opening print composer

Once you've got the print composer open, use the "Add new map" button (1 in the image below), and drag across the page to create a new map (you can also change the canvas size if you need a specific size or aspect ratio). Bear in mind that any white space around the map will be rendered in your image, so you might want to stretch the map to the edge of the canvas, or even slightly over. If the map is not centered correctly, you can move it around using the "Move item content" button (above the "Add new map" button in the image). If you need to zoom in and out, you can set the scale in "Item properties" tab.

enter image description here

Once the map looks right, you can set your desired resolution in the "Composition" tab (2 in the above image). If you are wanting a particular sized output image (say 800x600 pixels), a trick is to set the size of the canvas to a custom value in inches, and then manipulate the resolution to get the correct image size. So to get an 800x600 resolution output image, you would need to set the resolution to 100dpi for an 8x6 inch canvas. To output the image, click on the "Export as image" button (3 above), and save in the desired format.

Finally, if you need the output file to be georeferenced, select the "World file on" checkbox in the "Composition" tab (just under 2 in the image above), and a world file will be saved together with your image.

rudivonstaden
  • 5,354
  • 4
  • 26
  • 43
  • Thanks for this, I would say this is the correct answer in 2023. Slightly confusing though, because in the main QGIS map window (not print) you can export a PDF and the DPI option is provided in the dialogue. – Josh May 21 '23 at 09:30
2

To change the output resolution (tested on QGIS 3.10), make sure you are in your map layout:

  1. Projects > Layouts > YourMap

From your map layout:

  1. Layout > Layout Properties...

  2. Choose the Layout Tab > Export Settings > Export resolution

enter image description here

Aaron
  • 51,658
  • 28
  • 154
  • 317
  • I am trying to export a map from the Print Composer as a horizontal A4 at an Export resolution of 300 dpi, so the output would be 2480 x 3508 pixels; however, it overrides the Export Settings and results in a 595 x 842 pixels PDF file. Weirdly enough, if I export it as a TIFF, it gets the resolution correctly. Any ideas? – Trikelians Apr 20 '23 at 20:52