The following two steps are required to prepare the multiple layer map:
- Prepare multiple Shapefiles to be merged into a single map
- Prepare the attribute table of the merged Shapefile (the DBF file)
These two steps explain how to turn them into an interactive map:
In a nutshell: creating a multi-layer interactive map
The layered map works by making map areas with no data invisible. This allows one to selectively hide layers of map areas for which there is no data. It is achieved by setting the variable ‘MAP-ND-TR’ to ‘TRUE’, found in the ‘Settings’ worksheet of the StatPlanet Data Editor. Data is then imported layer by layer, selectively filling only columns (i.e. map areas) that are relevant to that layer. Columns that have no data are not shown. This means that when all objects from all relevant layers are merged into a single Shapefile, StatPlanet can be made to display information for selected objects simply by not putting any data in the columns that relate to other layers.
Tools & knowledge required
- It helps if you are already familiar with the standard StatPlanet process for setting up a single Shapefile and importing data into the map using the StatPlanet data editor. See also the StatPlanet Quick Guide.
- Quantum GIS is used to merge the Shapefiles in this example. This task can be completed using other GIS software, including MapWindow. It helps if you are familiar with Quantum GIS or MapWindow GIS, including viewing attribute tables and re-projections.
- OpenOffice Calc is used to prepare DBFs in this example. It is possible to open DBFs in Excel 2003 and earlier but the results can be haphazard. Attributes can also be edited directly in Quantum GIS but if extensive editing is needed, OpenOffice is to be preferred.
You will need a set of polygon Shapefile layers. These need to be aligned correctly to each other and merged into a single Shapefile.
Things to bear in mind at the Shapefile preparation stage
- Shapefile simplification routines may affect the registration of individual polygons within the individual Shapefiles or the final merged shapefile. You may need to experiment to achieve a compromise between file size and quality of registration.
- Getting the projection of each layer of the map the same is vital.
- The example I have prepared has just over 1,000 separate polygons within 4 different layers. At the highest level of detail, the model does slow down. You may need to experiment and test to ensure performance is sufficiently smooth for your purpose, audience and delivery method (web or file).
Procedure for Shapefile preparation
- In Quantum GIS, start a new project and add the Shapefile polygon layers that you wish to include in your final map.
- You may wish to modify the projection of your Quantum project or layers to alter the perspective of the map – you must ensure that each Shapefile you wish to merge is set to the same projection.
- Check the registration of your Shapefiles –they should all line up correctly at each level of detail.
- If you are having difficulty in getting the Shapefiles to share the same projection and to register on top of each other, I usually find MapWindow is better at re-projecting layers. MapWindow currently only allows the merger of 2 shapefiles so Quantum remains more efficient at merging more than 2 layers.
- Once you are happy with registration, in the Layers toolbar, right click each layer and ‘Save As…’ to save a copy of each layer inside a new folder. The new folder should only contain the saved shapefiles you wish to merge.
- Optionally, prepare the individual layer DBF files at this stage, before merger (see DBF Preparation Stage below).
- In the Vector menu, Data Management Tools sub-menu, select ‘Merge shapefiles to one’.
- Switch on the option ‘Select by layers in the folder’.
- Navigate to your newly-created folder and select each Shapefile you wish to include (carefully if they have been re-projected) – the order in which they are added is not important.
- Browse to the same folder to output the merged Shapefile and give the merged file a name – I usually include ‘merge’ somewhere in the name.
- Choose to add the finished merged shapefile to the canvas to confirm it has merged correctly: check the attribute table to ensure each polygon is present.
- You only need to click OK once – Quantum may add layers twice if you hit OK twice! Click cancel to go back to your map.
- Zoom to the layer extents of your new merged layer to ensure the merge process has worked properly.
- As a final check, use the Quantum GIS Browser (rather than desktop) to view the merged Shapefile – if the preview shows the area you wish to display, with no stray polygons dispersed from the main map, you are ready to proceed. If not, you will need to check through the merge process again to see what has gone wrong – almost always, mixed projections are to blame for failure at this stage.
The merged Shapefile will have merged all the attributes of your individual layers but you will need to tidy it up. Ultimately all you need is two columns in the final DBF: one with a unique ID and one with the area name.
Things to bear in mind at the DBF preparation stage:
- NEVER re-order or sort a Shapefile’s attribute table (DBF) unless you know you can get it back in exactly the same order e.g. by adding in a row number column before you start.
- You will need to make sure that you do not have duplicate names / references across multiple layers. This is particularly important for multiple layer files as it is entirely possible to have an identical name for objects that feature in multiple layers. In the provided example, the Wards have all had the acronym ED (Electoral Division) added to their names because one Ward (Mawr) is also the name of the same area at the LSOA level.
- You may prefer to amend your original source Shapefiles rather than fix them after they are merged. The consistent use of column names is needed for this to work first time. You should still check the merged Shapefile to ensure it only has the minimum necessary columns and all the required rows.
Procedure for DBF preparation
- Open the merged Shapefile DBF using OpenOffice Calc accepting the appropriate character set.
- I find it useful to rename the column that contains the unique reference GEOGID – making sure you don’t delete the first comma or the characters after it as these describe the type of data held in the column. It is also usually a good idea to make this the first column if it is not already so.
- I also find it useful to rename the field that contains the name of the object to AREANAME.
- You will usually need to move data from later columns back to columns 1 and 2 – remember, no re-ordering or sorting of rows.
- Delete any extraneous columns from the DBF – they have no purpose in StatPlanet.
- In saving the changes you have made, ensure you ‘Keep Current Format’ rather than saving as ODF file format.
You will now be setting up the merged Shapefile within StatPlanet so that the Data Editor can see all the names and IDs ready for importing of data.
Things to bear in mind at the Statplanet preparation stage
- You may wish to retain any data in the existing model so that you can check whether the map is loading correctly even if the data is gibberish for your map.
- If you use custom regions in your work, you will need to remember that these will work best if you remember to include the relevant objects from each layer. See example for illustration of this.
Procedure for preparing StatPlanet
The process for loading the merged map is identical to loading any Shapefile:
a. Copy your merged Shapefile and related DBF to the \map and \web\map directories
b. Run update_map.bat within the \map sub-folder to prepare the Shapefile & DBF.
c. Open StatPlanet_data_editor.xlsm, ensure macros are running and go to the Import page.
d. Click on ‘Setup shapefile map’. Navigate to your prepared DBF in the \map sub-directory and open it.
e. You will be presented with a worksheet showing your DBF table and asking you to specify which column is an ID. If you have prepared as described above, you should select the GEOGID column, which is Column 1. Sometimes the macro will also suggest Column 1 as the name field - if you have prepared as described above, you want Column 2 (AREANAME) to provide your object names. To do this, simply type 2 into the dialog box to point StatPlanet to your names.
f. The Shapefile will then have been loaded.
- Go to the ‘Map Regions’ worksheet of the Data Editor. If this is a brand new project, then you should remove all rows after row 2. Because you are adding a new map, you will need to alter the ‘All regions’ settings so that the map can make an initial appearance in something like the right place:
|MAP / REGION NAME||X||Y||ZOOM|
- Go back to the Import worksheet and choose ‘Save Data’.
- Run the StatPlanet.exe file to check whether the new map is visible. Don’t worry about the appearance at this stage – it just needs to be visible for now.
- As with any other Shapefile map, it may not work first time. You can experiment with renaming SHPreader.swf to SHPreader_old.swf and SHPreader2.swf to SHPreader.swf and running StatPlanet.exe again.
- If the map now appears, you are nearly ready to import data. Make any changes to the position and zoom of the map in the usual way: right-click map, ‘copy map co-ordinates’, paste into the ‘All regions’ row (see step 2).
- If the map does not appear, it may be that the map extents are inaccurate because of misaligned projection data. Return to the section on preparing the Shapefile or the user manual for general advice on loading Shapefiles.
If you have a visible map, you can now start to prepare data ready to import data using the StatPlanet Data Editor.
The layered map works by setting MAP-ND-TR to ‘TRUE’ to make columns (i.e. map areas) that have no data invisible. Data is then imported layer by layer, selectively filling only columns that are relevant to that layer. Columns that have no data are not shown.
Things to bear in mind at the data importing stage
- You might want to consider how you wish to present the information – you could set the geography levels as your primary categories, with the rest of the data as sub-categories and indicators. The example shows the geography as sub-categories of the indicator sets.
- You might want to consider how you handle missing data for individual polygons in a layer. The datasets used in the example do not have any null data points in any layer as they are based on Census data.
Procedure for preparing data for import
- The layered map is made possible by changing the setting MAP-ND-TR to ‘TRUE’ in the Settings worksheet of the Data Editor.
- Click on ‘Clear Data’ in the Data Editor (Import worksheet) and OK the clearance.
- Because you will need to import data a layer at a time, you will need to prepare your import files so that they can be imported level by level. This will often mean a separate file for each geography layer.
- As ever, you will need to be mindful of ensuring that the IDs and names included in your import files match the names and IDs held in the Data Editor so that the Import macro can detect them properly.
- You must continue to follow the general StatPlanet rules for importing data e.g. only one instance of an area ID / name per imported file.
- You may have to edit the category and time details to make better sense of the data.
- When you have finished importing data, choose ‘Save Data’ on the Import worksheet.
- Run the StatPlanet.exe file to check whether the map is now displaying the layers correctly.
Hopefully after a couple of runs at this set of methods, you will be able to create multi-layered maps without significant difficulties. Once a map is set up any amount of data can be imported from any number of sources quite easily.
Version 1.0 by John B Grenfell, May 2013