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:
- Create and design your project: Add layers and styles.
- Zoom to the desired zoom level.
- 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.)
- Close the project
- 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.
Pingback: Creating high resolution geo-referenced maps « Ecostudies
Even though I’ve set the extents, I still end up with a wide, blank margin. This is how I tried the command:
/Applications/QGIS.app/Contents/MacOS/QGIS --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?
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.
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,
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.
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.
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
C:\Documents and Settings\Desktop\MAP>set PATH=C:\OSGeo4W\apps\grass\grass-
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
i am having the same problem as J.
where can i find the osgeo command line?
You should find OSGeo command line in Windows Start Menu in OSGeo4W folder.
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….
Thanks for this tip, it’ll be useful.
Pingback: Create wld file for map image | Ecostudies
IT works nicely. Unfortunately for me, QGIS does not wait for the background openlayer to load. I get my shapefiles, but no base layer :(
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.
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?