Creating High-Resolution Images Using QGIS

Creating high-resolution output with QGIS can be tricky. “Save as image” saves the current map extent and creates a world file, but the output size cannot be specified directly. It simply saves the currently visible map. Most of the time this resolution will not be satisfactory.

Using “Print Composer” enables you to create full-grown maps including legend, scale bar, text annotations, north arrow, attribute table, decorations, etc. You are free to chose any size/resolution for the output image. Unfortunately, this way you will not get a world file.

That’s where the third possibility comes in handy:  Using QGIS from command line to create a snapshot of a map. This way, you can create images of any size and with corresponding world file. The work-flow can be divided into the following steps:

  1. Create and design your project: Add layers and styles.
  2. Zoom to the desired zoom level.
  3. Write down the extent of the map window. Use coordinates in the project’s projection. (You can skip this step and don’t specify –extent option. The project will be restored in it’s original saved state if you do so.)
  4. Close the project
  5. Go to command line and run
C:\...>qgis --project myproject.qgs --snapshot image.png
            --width 1500 --height 1000 --extent xmin,ymin,xmax,ymax

QGIS will start, load the project, create the snapshot, and close again. That’s it!

Things to be aware of: QGIS will start, load the project, set the given extent (if specified), enlarge the map canvas and then take the snapshot. As a consequence, the extent given doesn’t match the extent of the resulting image. The image will have a bigger extent and contain surrounding areas.

Together with the new labeling tools this can be a fast and (semi-)automatic way to create nice looking high-resolution map images and corresponding world files from QGIS projects.

  1. Rowan said:

    Hi Underdark,

    Even though I’ve set the extents, I still end up with a wide, blank margin. This is how I tried the command:

    /Applications/ --project /Users/sorbus/Desktop/Garden.qgs --snapshot image.png --width 2330 --height 3312 --extent 542807,161260,543227,160762

    Should this work on Mac OS X too?



    • underdark said:

      Hi Sorbus,
      Sorry, I’ve no way to test on OS X.
      As mentioned above: “As a consequence, the extent given doesn’t match the extent of the resulting image. The image will have a bigger extent and contain surrounding areas.”
      Try zooming in a little and save the project that way. Then run the command again. The white margin should shrink.
      Best wishes,

      • Sorbus said:

        Hi Underdark,
        I’ve found a new, GUI based way of exporting hi-res images:

        1. select a layer that includes the required area
        2. run the ‘html image map’ plugin
        3. use it to ‘set’ the map canvas size to the desired size in pixels
        4. keeping the plugin window open, use the ‘view’ menu to ‘zoom to layer’
        5. use the ‘save as image…’ command to output your image.

        I’ve exported 10k x 10k png images, zoomed right into desired areas, under OS X. Sometimes I’ve had to repeat steps 3 and 4, if the image hasn’t zoomed/sized properly.

        I hope this helps,


  2. david said:

    Hi underdark

    Do you see any possibility to make several snapshots without opening QGIS evey time? It’s quite time consuming if you have to take over 1000 snapshots.
    I tried the Python Console within QGIS but I wasn’t able to create a single snapshot… If I use the command line outside QGIS it works, but because it opens QGIS every time it’s quite slow.

    cheers david

    • underdark said:

      Hi David,
      I don’t think that this is currently possible, but it would be a nice addition. You could file an enhancement request. I think it shouldn’t be to hard to implement.
      Best wishes,

  3. J said:

    I cannot seem to make this work, the map loads although no image is outputted

    I go into cmd.exe cd into the directory of my project and

    MAP.qgs --snapshot image.png--width 1500 --height 1000

    QGIS loads up, and nothing happens

    Command line outputs this

    C:\Documents and Settings\Desktop\MAP>MAP.qgs --snapshot image.png--widt
    h 1500 --height 1000

    C:\Documents and Settings\Desktop\MAP>call "C:\OSGeo4W"\bin\grass-env.bat

    C:\Documents and Settings\Desktop\MAP>set GISBASE=C:\OSGeo4W\apps\grass\gra

    C:\Documents and Settings\Desktop\MAP>set WINGISBASE=C:\OSGeo4W\apps\grass\

    C:\Documents and Settings\Desktop\MAP>set GRASS_SH=C:\OSGeo4W\apps\msys\bin

    C:\Documents and Settings\Desktop\MAP>set GRASS_WISH=C:\OSGeo4W\bin\wish.ex

    C:\Documents and Settings\J\Desktop\NYCMAP>set GRASS_PYTHON=C:\OSGeo4W\bin\pytho

    C:\Documents and Settings\Desktop\MAP>set GRASS_PROJSHARE=C:\OSGeo4W\share\

    C:\Documents and Settings\Desktop\MAP>set GRASS_HTML_BROWSER=C:\Program Fil
    es\Internet Explorer\iexplore.exe

    C:\Documents and Settings\Desktop\MAP>set PATH=C:\OSGeo4W\apps\grass\grass-
    ;C:\Program Files\QuickTime\QTSystem\;C:\OSGeo4W\apps\msys\bin

    • underdark said:

      Try using the exactly same syntax from Osgeo command line instead of cmd.exe:

      C:\...>qgis --project myproject.qgs --snapshot image.png
      --width 1500 --height 1000 --extent xmin,ymin,xmax,ymax

  4. Dilmore said:

    i am having the same problem as J.
    where can i find the osgeo command line?

    • underdark said:

      You should find OSGeo command line in Windows Start Menu in OSGeo4W folder.

  5. julia said:

    Hello Underdark,

    Do you happen to know where I might find an example of the proper syntax to use to specify a postgis vector layer to add on the command line?

    And if there is a way to indicate a where clause to display only specific feature, that would be perfect. If not, just adding the postgis layer and zooming to a known extent would still work.

    Been googling for a long time and have not been able to find examples anywhere, even though the documentation indicates that a postgis layer can be used at the command line….



  6. Thanks for this tip, it’ll be useful.

  7. A Wiedmer said:

    IT works nicely. Unfortunately for me, QGIS does not wait for the background openlayer to load. I get my shapefiles, but no base layer :(

    • underdark said:

      I doubt that it works with OpenLayers. As far as I know, you cannot use them even with print composer. In general, there is no way to produce good-looking, high-resolution output from any of the web sources (Google/Bing maps or OSM). Maybe if you save the background as PNG with world file and use that instead of the “live” OpenLayers background, you could get some kind of output.

  8. andre said:

    I do exactly as you wrote, but not quite getting what we would like. The file contains a reduced copy of my map, the result does not depend on the zoom in the project and specified parameters. More precisely, if extent is not specified, we get a thumbnail image of the entire map in the corner of a white canvas, if extent is specified – get a thumbnail image of that part of the project, which was on the screen when saving. That just did not try to get a normal full-scale image did not work. Perhaps there are plugins that allow you to get high-resolution images using QGIS?

%d bloggers like this: