Nothing Special   »   [go: up one dir, main page]

Academia.eduAcademia.edu
Introductory exercise for archaeologists to QGIS This exercise was designed for an upper-level undergraduate course in cultural resource management practices in April 2024 at the University of Oslo (https://www.uio.no/studier/emner/hf/iakh/ARK2110/v24/timeplan/index.html). This exercise uses publicly accessible data from Norway to demonstrate how to use raster and vector data, including points, lines and polygons to create a basic map. Users who are not at the University of Oslo should ignore the parts about using “Silver”. Also, general members of the public will need to convert the data from Mjærum et al. (2022) from a csv file into a shapefile on their own. Of course, you can also track me down, send me an email and I can send you shapefiles if that is a barrier to you to give the exercise a try. Also, please note that the word “flyke” in Norwegian translates to “county” in English. I use them rather interchangeably in this exercise. Please let me know if you found this exercise helpful or discouraging or whatever. While the data are focused on Norway, the general process can be done anywhere in the world. All the best, David K. Wright University of Oslo 15 April 2024 Kartfest kulturminner 1. Background of the QGIS project QGIS is an open-source Geographical Information System (GIS) platform written in C++ computer language. It is currently associated with the Open Source Geospatial Foundation (http://www.osgeo.org), which is a community of developers committed to providing a highly functional GIS environment with a Graphical User Interface (GUI) at no cost to users. There are a whole range of webinars and resources available for users on the website. Compared to ArcGIS (https://www.arcgis.com), which is the most commonly used proprietary GIS platform, QGIS provides most of the functionality and ease of use as the industry flagship. In addition, QGIS has a robust user community who develop plugins (https://plugins.qgis.org), usually written in the Python computer language, for users to download. The plugins provide additional, targeted functions that specific users will find useful, but are not of general interest to most users. For example, pyArchInit (https://plugins.qgis.org/plugins/pyarchinit/) is a plugin that structures common archaeological database construction including stratigraphic units, sites, chronologies, taphonomy and multimedia interfaces. Since most of the users of QGIS are not archaeologists, this plugin is not of general appeal to the community, but is of great value to users like us. Because it is an unpaid developer-based platform, QGIS has evolved as a hybrid program that blends together several different open-source initiatives. For example, GRASS GIS (https://grass.osgeo.org) is a powerful, non-GUI GIS platform that is designed to interface with other open-source software such as R (https://www.r-project.org) and operate in 3D-raster (voxel) environments. Users with familiarity in Ubuntu or Linux command-lines will feel comfortable in GRASS. The most recent version of the software also has a GUI. Since GRASS and QGIS are both part of the Open Source Geospatial Foundation, all of the GRASS tools can be installed into QGIS, which provides the user with significant statistical operability. 2a. Use of Silver app in VMWare The exercises in this class are built in a VMware client so as to standardise the presentation of the data. This is a virtual desktop environment that you can link to your OneDrive. If you are using the desktop PCs in the computer lab, the C: drives are accessible, but USIT wipes the drive every Friday so you will want to work from your OneDrive. To access the client: (1) Open the VMware Horizon client on your desktop. You will be asked to add a server and you will type “view.uio.no” and then you need to sign in with your UiO administrator username and password and the two-step authentication that the university requires for everything (Figure 1). Fig 1. Accessing Silver from VMware (2) Double click the Silver app and a new desktop screen will open for you. Type “QGIS” into the Search bar and you should be able to open QGIS Desktop 3.34.5. I have written this module using American English, so you are going to need to change the settings (Innstillinger > Generalt) to American English if you want to follow this exercise precisely. If you want to keep the settings in Norwegian, you will just need to translate the terms yourself, but everything is organised precisely the same way in the menu layouts regardless of the language you use (Figure 2). Fig. 2. Changing the language settings. 2b. Installing the Software Your second option is to download QGIS for yourself and install it on your personal computer. Go to www.qgis.org and download the most recent version of the software and install it according to your operating system requirements (Figures 3, 4). These modules are written in Version 3.34.5 in April 2024. Fig 3. QGIS download interface. Fig. 4. Install your software. Install the program into your C:/ drive (Programs folder) on a PC or in your Applications folder (Mac OS). Click on the Q icon ( ) at the bottom of your desktop. The program will open (Figure 5) and you will create a new project by clicking the “ ” icon in the upper lefthand corner. You now have a blank template in which to begin working. Fig. 5. Open the program. Read Section 1 for how to change the language settings. 3. Plugins One of the best features of QGIS is the robust set of free developer plugins that can be installed to help you with particular aspects of your work. Go to Plugins > Manage and Install Plugins… to see the full list. It is usually easier to type a keyword for something you want to do. For example, go to the Plugins menu and search for “HCMGIS”, download it and it will appear as a menu item. Click on HCMGIS > Basemaps > Google Satellite and a panchromatic (“true colour” satellite) image of the world will appear. If you use the wheel on your mouse, you can zoom in and out. With the little hand tool, you can navigate to landscape features you are interested in seeing. 4. The QGIS Interface (General Overview) QGIS is comprised of a GUI (graphical user interface) that can be generally subdivided into three components (Figure 6): (a) the toolbars provide shortcuts to the basic functional tools that are used in a GIS environment. The top horizontal bar includes saving, viewing and calculation tools. The second row includes line and point tools for vector-based operations. Toward the right of these, labelling functions are hosted and the far right includes a tool that allows you to access the Plugins quickly. The final row includes tools for measuring, creating and manipulating polygon vectors. The remaining tools to the right are for raster manipulation and the generation of raster statistics. Fig. 6. GUI interface components to QGIS. On the left vertical side of the screen are tools for adding vector, raster and various types of database files. You can also import GPS data and perform various calculations between multiple types of vector files from this toolbar. The layer menu allows you to quickly access your files from the computer and/or network. The panels give you a quick view of the files you can work with. Clicking and unclicking the files only affect the viewing environment of QGIS. A quick view of statistical outputs can also be viewed and copied here. Finally, the map window shows the user (you) the layers that are active and operational in QGIS. This view is not printable or exportable in this environment because GIS is not explicitly about making maps—the operational environment is designed to allow users to visualise and calculate relationships between datasets. Exportable maps can be created, but we will not worry about that initially. Now that you know the basics, let’s get started! The most important thing with any GIS is to maintain good file organization. GIS works by linking files together in a single operating environment and it is very difficult to move files around a system without creating a mess in your GIS operating environment. The project files you create (*.qgs) will not have any selfcontained data—it only serves as a map of paths to where your data is hosted. Therefore, you will want to create a simple, but expandable architecture in your hard drive or network that can be modified through time. An example of such a basic structure is provided in Figure 7. Fig. 7. Example of flexible data structure architecture in setting up your GIS. 5. Dealing with Coordinate Systems There are many ways to measure space and one of the challenges of representing space in two dimensions is that the earth is a three-dimensional object! Translating three-dimensional space into two dimensions involves “projecting” the space. There is a good summary of projections here: https://www.gislounge.com/map-projection/. Reprojected space is measured in coordinates. The coordinate system you are probably the most familiar with is latitude relative to the equator and longitude relative to the prime meridian in Greenwich, UK, but you probably aren’t aware that since 3D space is projected in different ways, there are different interpretations of which coordinates apply to the space you are sitting on. This is because with different topographic and gravity models of earth’s surface, a radian degree (the units that latitude/longitude are measured in) is not always the same distance on the ground because all radians are measured up to 360°. Until recently, there was no precise way to measure the entire circumference of the earth and there are many legacy coordinate systems that reflect old imprecisions. Here is a link nice summary of coordinate systems, projections and the issues involved with translating spatial dimensions. In the lower right-hand corner of your Map Window, you will notice that there is a little grey circle after which it says, “EPSG:4326.” This is your coordinate system and datum (lat/long using the WGS84 datum….Google it if you don’t understand what this means). This is the default coordinate reference system (CRS) used in QGIS and most GIS programs. But, there are many instances where you will not want to have your data in EPSG:4326 (cf., this website). This is because archaeologists typically work in meters, but EPSG4326 is in degrees radian, which uses a geographic coordinate system and is difficult to translate into metres. 6. Adding raster data In this first exercise, we will get a digital elevation model (DEM) from a public repository and reproject it. Let’s go to https://earthexplorer.usgs.gov. You are going to need to create a username and password in order to download data. Once you have done that, navigate to Norway and create a polygon box around the southern part of the peninsula by left clicking in the approximate areas that you want to target (Figure 8). You can also add the coordinates manually, as I have done in Figure 9, if you want more precision. Fig. 8. The Navigation pane in the USGS’s Earth Explorer (https://earthexplorer.usgs.gov). Select an area roughly this size or bigger. Now click the “Data Sets” tab and scroll to “Digital Elevation” and select “GMTED2010.” (Figure 9). Click the “Results>>” tab at the bottom of the data selection menu. Fig. 9. Select the data platform you want to download in the USGS’s Earth Explorer. You will see six DEMs appear. Click the little foot to see the footprint of where the DEM covers (Figure 10). You can zoom in on the map using the mouse wheel or the + sign in the lower right hand of the map display window. Click on the GMTED2010N50E000_150 entity and download it as a zip file. Fig. 10. View the data coverage of your selection in the USGS’s Earth Explorer Navigation pane. You will want to save the zip file in your OneDrive drive so you can work with it. In Figure 11, you can see how I saved mine after extracting them from the zip file downloaded. I recommend that you have four master folders as shown in Figure 7. DEMs are raster files, so save the tif files in your Raster folder. Fig. 11. Save raster data in your OneDrive. We want to work with the DEM in QGIS. The simplest way to open it up is to drag the DEM into the Layers Panel of QGIS. However, for learning purposes, we are going to manually add the image. Click on Layer > Add Layer… > Add Raster Layer… and a box will open. Click the three dots and navigate to 50n000e_20101117_gmted_dsc150.tif (Figure 12). Click ‘Add’ and it will appear in your Map Window. Fig. 12. Add the DEM to our Layer Panel. An image will appear in the Map Window (Figure 13). It’s not a very pretty image just yet, so let’s make it nicer. Fig. 13. Digital Elevation Model (DEM) in your Map Window Right click the DEM file in the Layers Panel and go to ‘Properties’. In the ‘Properties’, click ‘Style’ in the left panel. In ‘Render type’, change the type to ‘Singleband pseudocolor’. If you click the ‘Color palate’, you’ll see that there are many options to choose from. I like Turbo (Figure 14). Also note that I have changed the ‘Resampling’ field toward the bottom of the menu to ‘Cubic (4x4 Kernel)’. Fig. 14. Adjust the colour display. Click all of the OKs and you should have a nice image similar to what is shown in Figure 14. Be sure to save your project somewhere. I like to have a separate ‘Q_files’ folder in my root directory where I save the .qgs files. You can also change the view to a Hillshade (Figure 15). Be sure to adjust the Z-factor to something like 0.00005 and I normally like to check the ‘Multidirectional’ option for the shading. Fig. 15. Hillshading options for your DEM. 7. Adding vector data Vector data is dimensional: points are 1-D, lines and polygons are 2-D and volumetric data are 3-D. We are going to add some lines and polygons to our map before adding points. Go to https://diva-gis.org/gdata and select ‘Norway’ as your country and ‘Inland water’ as your data type (Figure 16). The data will download as a zip file, which you will unzip in your Vector folder. Once it is downloaded, you will see two sets of files: NOR_water_lines_dcw and NOR_water_area_dcw. There are four files in each set called ‘shapefiles’ (https://en.wikipedia.org/wiki/Shapefile) that can easily be read into QGIS. It is super important that you don’t change any of the file names on these files or separate them from each other or they will not work! Fig. 16. Download diva-GIS inland water data Next, you are going to want to add these files to your Layer Panel in the same way you added the DEM, but this time you are going to add Vector data instead of Raster data (Figure 17). Add the files entitled NOR_water_lines_dcw.shp and NOR_water_area_dcw.shp. It is important that you select the files with .shp as their extension—nothing else will work, but the other files need to be present and in the same folder as the .shp file. Fig. 17. Add vector data to the GIS. QGIS will create a random colour scheme for these files, so it is good to adjust the colours so that the lines and polygons make sense. Right click the NOR_water_lines_dcw file and go to ‘Properties…’. Then, in the tab that says Symbology, change the colour to blue. The easiest thing to select is the ‘simple blue line’ option. Similarly, for the NOR_water_area_dcw file, you can select ‘simple blue fill’. Fig. 18. Change the symbology of the vectors. Next, go to https://kartkatalog.geonorge.no/ and type “fylke” into the search bar (Figure 19). You are going to download all of the Adminstrative enheter fylker for the entire country in the projection 3035. Be sure to also select GeoJSON (or GML) as the data type. Fig. 19. Download the administrative districts for Norway. Add the zip file to your Vector folder and unzip it there. You are going to add it as a Layer as you did for the other vector files. GeoJSONs are complicated files and you can either add a line file or a polygon. We are going to add the MultiPolygon (Figure 20). Once that is added, you will see that the files overprint every other type of data, so we are going to go to the Symbology and change the ‘Simple Fill’ to ‘No Brush’. Once you click OK, you will see the administrative boundaries of Norway with rivers and lakes underneath. Fig. 20. Add the fylke polygon layer to the Map Window and change the symbology. The next thing we are going to do is add point files of sites recorded across southern Norway. These data have been downloaded from the article ‘Humanvegetation dynamics in Holocene south-eastern Norway based on radiocarbon dated charcoal from archaeological excavations’ by Mjærum et al (2022—The Holocene 32(7): https://doi.org/10.1177/09596836221088242). The data have been cleaned up a bit and converted into shapefiles for you. If you would like to learn how to convert an Excel or csv file into a shapefile yourself, you can watch this video: https://www.youtube.com/watch?v=drIpvJm7OMs, but today we will skip this step. In Canvas, download the file “mjaerum_et_al_vegetation.zip” and place it in your Vector folder. Add it as a Vector layer as you have the other files. Once you are done, you should see a Map Window similar to the one I have in Figure 21. Fig. 21. Map Window with hillshade DEM in the background, administrative districts, inland waterways and archaeological sites in southern Norway. 8. Querying and managing vector data Now that our data are set, we are going to perform a very simple search to find all of the data we have in Akershus fylke between 1-200 AD. To do this, we are going to open up the ‘Attribute Table’ by right clicking on the mjærum_et_al_vegetation file (Figure 22). Select ‘Open Attribute Table’ and a table will appear on your screen that possesses all of the pollen data from archaeological sites these authors could find from the region. If you scroll back and forth in the table, you can see that there is a lot of information in there! Fig. 22. Open the attribute table for the mjærum_et_al_vegetation shapefile. There is a little button you can see in Figure 22 called ‘select features using an expression’ that you will now click. A dialogue window will open (Figure 23). In the Expression dialogue window, click the ‘Fields and Values’ and then double click “COUNTY”. You will see “COUNTY” appear in the expression dialogue window. Next type the word “LIKE”. It will begin to autopopulate and it will turn purple when you have the right operator. Next click ‘All Unique’ on the lower right-hand side of your window and you will see all the administrative fylke appear. Click ‘Akershus’. Then type “AND”, which is a Boolean logical operator (https://www.codecademy.com/resources/blog/what-is-boolean-logic/). Then click “Period”, type “LIKE”, click ‘All Unique’ again and click ‘1-200 AD’ followed by clicking Select Features. If that doesn’t work, you can copy and paste the following into the Expression dialogue editor: "COUNTY" LIKE 'Akershus' AND "Period" LIKE '1-200 AD' If you have done it correctly, you will have selected 44 features. Fig. 23. Use the Expression dialogue editor to select 44 features. Next, you are going to right click the mjærum_et_al_vegetation file again and select Export > Save features as… and a dialogue box will open (Figure 24). You will export the file as a GeoPackage (you could also select a Shapefile or something else), give it a good name without spaces or special characters. There are a lot of characters that will cause errors in GIS files (ø, å, æ also do not work) so it is best to stick to simple text. Also be sure to select the checkbox ‘Save only selected features’ so that the 44 features we queried up in the expression dialogue are the ones we export. If you do not select it the first time, you will just create a copy of all of the 6135 data points in the original file. Fig. 24. Export the selected data. You will probably need to adjust the symbology of the new vector layer a bit to make the points more visible, which you already know how to do. You can just change the colour to make it more visible. At this stage, I recommend you zoom to the layer by right clicking on the file and clicking the top field (‘Zoom to Layer(s)’). You will get a view of Akershus fylke with your 44 sites standing out against the background of the other raster and vector files (Figure 25). Fig. 25. Zoom to the Akershus layer. 9. Making a map There is an infinite amount of things you can do with data like this, but for now, we will concentrate on making a map that can be printed or included as a figure in a paper you are writing. First, let’s add a label to the fylke so that when we make our map, we have some basic information. Right click on the file and go to Properties. You will see a tab titled ‘Labels’ (below Symbology). You are going to select ‘Single Labels’ from the drop-down menu and for the ‘Value’, select ‘fylkesnavn’. I changed the fonts and added a 1 mm buffer to make it more legible (Figure 26). Fig. 26. Add labels to the administrative districts. Adding labels to the sites is a bit complex because many of the sites are mapped more than once (they are actually radiocarbon ages from sites that have pollen data, so there are multiple points of collection at single sites). Of course, this can be handled, but is a more complex task than you need to learn at this point. So, I recommend that you also add labels to the sites, but you are going to have some sites with as many as four redundant labels surrounding them. This is fine for now. You can go into Rendering and ‘Allow Overlaps without Penalty’ (Figure 27), but you will see some ugly text, particularly in the eastern part of your project area. If you are really ambitious, you can follow one of these instructions: https://gis.stackexchange.com/questions/315002/how-to-hide-individual-labelsin-qgis to hide labels you do not want to see repeated. The easiest thing to do is to activate the ‘Show/hide labels and diagrams’ tool ( ) in the second row of your toolbar, then click one of the labels that is a duplicate. You will be prompted to select a ‘primary key’, which you can click OK to the FID field (default). Then, just click all of the labels you want to eliminate the duplicates of (Figure 28). There is also an option to move the labels around with the button to the right ( reposition the labels a bit, they will be clearer on the map. ). If you Fig. 27. Render the labels of the sites. Fig. 28. Remove the duplicates. Now that the labels are fixed, we can make our map. Click Project>New Print Composer and give it a title. Click the “Add new map” icon on the left side of the panel then drag the cursor across the screen while holding the left mouse button (Figure 29). To adjust the view, click Item properties in the right panel and go down to Extents. I have provided an example in Figure 29 on how to adjust the extents to something appropriate. If you don’t like the view, select the image, and click the Delete key and try again. You can add a scale bar, North arrow and legend from the buttons on the left-hand side of the Map Window. You should also include your name and the date as a text box. • Notice that I have adjusted the Legend items and created a latitude/longitude border of the map. • Add a legend: https://www.youtube.com/watch?v=jvzEaYwepPs • Add a border grid: https://geoafrikana.com/how-add-gridsand-grid-frame-map-qgis/ Once everything is done to your liking, you can export the map as an image, SVG file or PDF by clicking one of the buttons at the top of the Print Layout ( ). Save it in the format you like, and I recommend that you click the ‘crop to content’ option so that you don’t export white space or clip your map to the print layout window. Making a good map takes practice and you have to learn by trial and error. There are lots of resources on YouTube that can assist you, and, of course, I am happy to help. The point is that the consumers of maps should be able to know (1) where you are located, (2) the scale of the map, (3) what information you are intending to communicate, and (4) who you are and when you made it. Fig. 29. Final map of the project area that I produced. Note the legend, scale bar, north arrow, text box with my name, date and the grid I used (it is the same as yours). Also note that I have adjusted the label positions a bit to make them clearer than the default positioning. Just for fun, I activated the Google Satellite map as the background using the HCMGIS, changed the colour of the fylke boundaries, adjusted the legend and generated a similar map. Fig. 30. Second view of the project area with a Google Map background generated in HCMGIS.