A while ago, I wrote about my experience using Ordnance Survey data to generate maps of the UK using the free and open-source Geographical Information System package QGIS 3. At that time I was using the then-current Long-Term Release, QGIS 3.4. Things have moved on, though, and this report uses the current QGIS LTR, version 3.28.
If you hang about this blog much, you’ll have noticed that there are a lot of maps. My UK maps are all generated using QGIS, but my world maps are a bit of a mix-and-match set drawn from various public domain sources, prominently Ian Macky’s excellent Portable ATlas site.
But (you’ll also have noticed) I do like making my own maps, and it’s been on my to-do list for a while, to make use of the free and well-curated data resources provided by Natural Earth.
So that’s what this is about. My project is to generate a map of Alaska, for reasons that will become obvious in another post, but what I write about here will be applicable to other mapping projects, too.
The Natural Earth download page provides data suitable for three different scales—1:10 million, 1:50 million and 1:110 million. My Alaska project realistically would be fine with the 1:50 million scale, but I’ll be using the 1:10 million dataset because I have other larger scale projects in mind for later.
For the base layer of my map, I download a 1:10 million shaded relief raster image—specifically their “Gray Earth with Shaded Relief, Hypsography, and Flat Water”. This comes as a zip file, which I unzip into a suitable new folder on my hard-drive. The data are in an image file called GRAY_HR_SR.tif, which I can open in QGIS using the menu bar at the top of the screen: Layer>Add Layer>Add Raster Layer…, and then navigating to the file.
This is a pretty thing, but if we zoom in on Alaska there are two problems—Alaska is stretched out from west to east, and the nearby Chukchi Peninsula in Russia is truncated by the edge of the map.
So I need to find a more suitable map projection. I can do this from the menu bar again: Raster>Projections>Warp (Reproject)…, which brings up a dialogue box. The “Input layer” should be the name of my raster image (in this case, GRAY_HR_SR), and the “Source CRS” (Coordinate Reference System) is just the default reference system established as the Project CRS when I open the tif file. I also want to save the generated projection for later use, so I skip down to the “Reprojected” text box, click on the button marked with […] to tell the program I want to save a file, and enter a suitable name.
Immediately below the “Reprojected” text box, I’ve unchecked the little box labelled “Open output file after running algorithm”. (Leaving this ticked means that QGIS will load my newly-created reprojected map, but will undo the reprojection, forcing it to conform to the original Project CRS.)
To find the correct entry for “Target CRS”, I have to click on the little globe to the right of that drop-down box, which opens a new dialogue. Under “Select CRS” I choose “Predefine CRS”, and that gives me access to the huge number of map projections QGIS knows about. If I type “Alaska” into the “Filter” box, I can find projections suitable for Alaska, and I choose NAD83(NSR2007)/Alaska Albers. Hitting the Run button at the bottom of the window then starts the reprojection process running.
That takes a while. After it completes, I can open a new project from the menu bar (Project>New), and load my reprojected map:
QGIS has reprojected the whole world, but it’s extremely distorted in regions that aren’t at Alaska’s high latitude. If I zoom in on Alaska, I can see that there’s been a good result there, and that the two edges of the original map have been brought together seamlessly to complete the Chukchi Peninsula:
But the rest of the distorted world map is of no use to me, so I’d like to crop out just the area that interests me, above. I do this by right-clicking on the file name in the “Layers” panel at the left of the interface, and then choosing Export>Save As… from the pop-up menu. This brings up a dialogue box in which I enter the name under which I want to save my cropped file, and then click on the Map Canvas Extent button to stipulate that I want to save just the area I’ve made visible on the screen. Keeping the tick in the “Add saved file to map” check-box ensures that my cropped file is loaded on top of the original, once processing is finished. Then I hit OK to create the new file.
Once the export is finished, the new layer appears in the “Layers” window, though the display doesn’t change much. I can now right-click on the original map layer, and dispose of it by selecting Remove Layer…, leaving just my new, cropped layer on display.
This is (at last) the base layer for my new “Alaska” project. I right-click on its name in the “Layers” panel, and choose Layer CRS…>Set Project CRS from Layer, and then save my new project from the top menu bar with Project>Save.
Now I want to lay some of Natural Earth’s vector mapping on top of this. Initially, I downloaded Admin 0 – Countries, Admin 0 – Boundary Lines, and Admin 1 – States, Provinces from their Cultural Vectors page, and Coastline and Ocean from Physical Vectors. All of these are provided as zip files, which I unzipped into a new folder on my hard drive. (Although I was tempted to give each set of files their own folder, they’re easier to batch process later if all the shape files are grouped together.)
QGIS will happily reproject all these files to match the Project CRS when I lay them on top of my Alaska base map. But (as with my raster map), I’d like to clip out just the area around Alaska before I start using them. I can do that using a batch process, but first I need to make a small adjustment to QGIS’s settings. Some of the Natural Earth files are, at time of writing, slightly badly behaved—their geometry contains tiny overlaps that are more or less invisible, but which will be detected and rejected during processing by QGIS. The ideal solution would be to fix these geometries, but that’s a whole other tutorial. So instead I’ll ask QGIS to ignore the problem. I go to the top menu and select Settings>Options…. In the dialogue box that appears, I scroll down the options in the left panel to click on Processing near the bottom, choose General, and set Invalid features filtering to Do not filter (better performance).
There are various ways to do the clipping I want. This time I’m going to create a mask layer, which tells QGIS which bits of the map I want to keep, and which I want rid of.
First I go through Project>New to open a temporary project in which I can generate my mask. Then to provide a reference I load one of my new vector world maps. Layer>Add Layer>Add Vector Layer…, and then navigate to my vectors folder. The files I want are the *.shp files, and I load ne_10m_admin_0_countries.shp, which brings up a world map tiled with all the various countries.
Now I create an overlying layer for my mask. Layer>Create Layer>New Shapefile Layer…. In the dialogue box that appears, I give the new layer a suitable filename and set “Geometry Type” to polygon.
Once my layer has been created, I make it editable by clicking on the little pencil icon in one of the top menu bars, and then on the green “Add Polygon Feature” icon a short distance to its right.
Now I can use the cursor to create a polygon, left-clicking in each place I want a vertex, and then right-clicking to end the process. A little dialogue box pops up, and I accept its default setting, and now I have my mask layer superimposed on the countries map.
To make sure this mask is saved to disk, I right-click on my mask layer in the “Layers” window at left of screen, and choose Save Layer Edits.
Project>New again clears the decks to run the batch process in which I clip all my new vector maps according to the mask layer I’ve just created. Vector>Geoprocessing Tools>Clip…, and then click on the Run as Batch Process… button at bottom left of the dialogue box. This brings up a new dialogue, containing three columns headed “Input Layer” (the files I want to clip), “Overlay Layer” (my newly created mask layer), and “Clipped” (the new files I want to create, containing just the vicinity of Alaska). Each column is headed with an Autofill… button, which is used to populate the three file lists. (A powerful but mildly counterintuitive tool.)
The first thing I do is to tug at the margins of the first two columns, sliding them to the right so that I can read the filenames I’m about to insert. For the first column, I choose the Select Files… option from Autofill, and select my five vector *.shp files. In the second column, I click on the […] button of the first row, and then Select File…. The file to select is the *.shp file for my Alaska mask. Once this is entered in the first row of the second column, I can copy it into the other rows with Autofill…>Fill Down.
The last column is where things get a little counterintuitive. I click on […] in the first row again, and in the “Save as type” textbox choose *.shp. But under “File name” I don’t enter a full filename, but just a prefix—I want all my newly generate clipped files to be prefixed “alaska_”, so that’s what I type into that text box. When I hit Save a little dialogue box appears, offering me autofill options. I choose Fill with parameter values, and leave the default parameter to use as Input Layer.
And (presto!) the “Clipped” column is populated with filenames echoing the original but prefixed “alaska_”.
Hitting Run will throw up some error messages about absent spatial indices which aren’t a big problem for this project, and our five clipped Alaska files are generated.
Time to open my original project, and add the ocean layer to mask off the dark grey sea. Here it is, zoomed back a bit to show that I’ve successfully trimmed off the rest of the world.
There’s an unfortunate seam at 180 degrees longitude, but I can fix that by double-clicking on the ocean layer in the “Layers” window, to bring up the Layer Properties dialogue box. Under Symbology, I click on Simple Fill, and set both “Fill color” and “Stroke color” to a nice shade of oceanic blue, using the little down arrows at the right of each drop-down box.
And, having finally produced a halfway acceptable map of Alaska, I’ll leave it there until next time.
or