{"id":133,"date":"2017-04-21T16:34:53","date_gmt":"2017-04-21T15:34:53","guid":{"rendered":"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/?p=133"},"modified":"2017-04-26T16:57:42","modified_gmt":"2017-04-26T15:57:42","slug":"hexmaps-in-qgis","status":"publish","type":"post","link":"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/2017\/04\/21\/hexmaps-in-qgis\/","title":{"rendered":"Hexmaps in QGIS"},"content":{"rendered":"<p>Hexes! If you like boardgames you probably love those awesome maps were terrain has been transformed into a grid of hexagons (popularly known as <em>hexes<\/em>). Beyond this geeky interest hex-based maps can be used to create interesting visualizations where you want to colour the map based on a specific variable.<\/p>\n<p>These visualizations are technically known as <a href=\"https:\/\/en.wikipedia.org\/wiki\/Choropleth_map\">choropleth<\/a> maps and they divide the space into a set of polygons that could be anything: country boundaries, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Voronoi_diagram\">Voronoi diagrams<\/a> or regular tiles.<\/p>\n<figure style=\"width: 1280px\" class=\"wp-caption alignright\"><a href=\"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/f\/f7\/Australian_Census_2011_demographic_map_-_Australia_by_SLA_-_BCP_field_2715_Christianity_Anglican_Persons.svg\/1280px-Australian_Census_2011_demographic_map_-_Australia_by_SLA_-_BCP_field_2715_Christianity_Anglican_Persons.svg.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/f\/f7\/Australian_Census_2011_demographic_map_-_Australia_by_SLA_-_BCP_field_2715_Christianity_Anglican_Persons.svg\/1280px-Australian_Census_2011_demographic_map_-_Australia_by_SLA_-_BCP_field_2715_Christianity_Anglican_Persons.svg.png\" width=\"1280\" height=\"1007\" class=\"size-large\" \/><\/a><figcaption class=\"wp-caption-text\">A choropleth map that visualizes the fraction of Australians that identified as Anglican at the 2011 census by <a href=\"https:\/\/commons.wikimedia.org\/wiki\/User:99of9\">Toby Hudson<\/a><\/figcaption><\/figure>\n<p>Regular tiles are interesting if you don&#8217;t have a relevant distribution of pre-existing polygons. But what type of tile would you use? The typical approach is to use a grid of squares but <em>as boardgamers already know<\/em> this is far from perfect. The issue here is that the distance between a square centre and its neighbours depends on their configuration: it will be larger for the ones in the corners than the ones at right\/left\/top\/bottom as Pythagoras knew some centuries ago. Hexagons better capture the spatial relation between tiles because the 6 neighbors of each hexagon are roughly positioned at the same distance of its centre. Also, did I mention that hexmaps look awesome?<\/p>\n<p>Ok, let&#8217;s see how can we create an hexagon-based map with QGIS.<\/p>\n<h2>Roman camps in Scotland<\/h2>\n<p>We know that the Romans legions adventured beyond the Antonine wall; the sources <a href=\"https:\/\/en.wikipedia.org\/wiki\/Battle_of_Mons_Graupius\">talk about military campaigns<\/a> and archaeological evidence support this idea because several temporary march camps have been found in Scotland. But where do we find these camps? To answer this question let&#8217;s create an hexmap where the hexes are coloured based on the number of temporary camps in the region.<\/p>\n<h3>Load the dataset<\/h3>\n<p>This <a href=\"https:\/\/git.io\/v9OgM\">zip file<\/a> contains 2 vector files in Shapefile format:<br \/>\n&#8211; <em>scotland_boundaries.shp<\/em> has the boundaries of the region<br \/>\n&#8211; <em>roman_camps.shp<\/em> is the set of identified Roman temporary camps compiled by Canmore.<\/p>\n<figure id=\"attachment_149\" aria-describedby=\"caption-attachment-149\" style=\"width: 625px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/01_base-1024x569.png\" alt=\"\" width=\"625\" height=\"347\" class=\"size-large wp-image-149\" srcset=\"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/01_base-1024x569.png 1024w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/01_base-300x167.png 300w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/01_base-768x427.png 768w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/01_base-600x333.png 600w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/01_base-200x111.png 200w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/01_base.png 1301w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><figcaption id=\"caption-attachment-149\" class=\"wp-caption-text\">Roman temporary camps in Scotland<\/figcaption><\/figure>\n<h3>Install the <em>mmqgis<\/em> plugin<\/h3>\n<p>Go to <em>Plugins -&gt; Manage and Install Plugins<\/em> and install <a href=\"http:\/\/michaelminn.com\/linux\/mmqgis\/\">mmqgis<\/a>. This plugin extends the functionality of QGIS for vector map layers.<\/p>\n<figure id=\"attachment_150\" aria-describedby=\"caption-attachment-150\" style=\"width: 625px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/02_mmqgis-1024x585.png\" alt=\"\" width=\"625\" height=\"357\" class=\"size-large wp-image-150\" srcset=\"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/02_mmqgis-1024x585.png 1024w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/02_mmqgis-300x171.png 300w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/02_mmqgis-768x439.png 768w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/02_mmqgis-600x343.png 600w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/02_mmqgis-200x114.png 200w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/02_mmqgis.png 1098w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><figcaption id=\"caption-attachment-150\" class=\"wp-caption-text\">Install mmqgis using the plugin manager<\/figcaption><\/figure>\n<h3>Create an hexagonal grid<\/h3>\n<p>Once <em>mmqgis<\/em> is enabled you can use its functionality to create the hexes; go to <em>MMQGIS -&gt; Create -&gt; Create Grid Layer<\/em> and select <em>Hexagons<\/em> as the layer type.<\/p>\n<p>You should set as extent the layer <em>scotland_boundaries<\/em> because we want the grid to cover the entire region. You can finally define the size of the hexes; I chose here 25km because it is roughly the distance a legion can cover in a day.<\/p>\n<figure id=\"attachment_151\" aria-describedby=\"caption-attachment-151\" style=\"width: 1006px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/03_grid.png\" alt=\"\" width=\"1006\" height=\"651\" class=\"size-full wp-image-151\" srcset=\"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/03_grid.png 1006w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/03_grid-300x194.png 300w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/03_grid-768x497.png 768w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/03_grid-600x388.png 600w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/03_grid-200x129.png 200w\" sizes=\"auto, (max-width: 1006px) 100vw, 1006px\" \/><figcaption id=\"caption-attachment-151\" class=\"wp-caption-text\">Parameters for a 25km-based hexagonal grid of Scotland<\/figcaption><\/figure>\n<h3>Intersect the grid with the boundaries<\/h3>\n<p>You probably got an hexagonal grid covering a large rectangle; it is kind of useless because to my knowledge Romans did not have submarines, so we should remove from the grid everything that is not land. In essence we want to remove from the grid everything outside the <em>scotland_boundaries<\/em> layer. You can do this using the command <em>Intersection<\/em> from <em>Vector -&gt; Geoprocessing Tools<\/em>.<\/p>\n<p>You need to specify the hex grid as the <em>Input layer<\/em> and the boundaries as the <em>Intersect Layer<\/em>. Please be aware that this process will take a while, specially if you defined a small hex size.<\/p>\n<h3>Count the number of camps per hex<\/h3>\n<p>The last step is to create a new hexagonal layer with an attribute defining the number of camps per hex. This algorithm is not in the Menus so you should open the <em>Toolbox<\/em> inside the <em>Processing<\/em> menu. Go to <em>QGIS -&gt; Vector analysis tools<\/em> and select <em>Count points in polygon<\/em>.<\/p>\n<figure id=\"attachment_153\" aria-describedby=\"caption-attachment-153\" style=\"width: 625px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/04_toolbox-1024x636.png\" alt=\"\" width=\"625\" height=\"388\" class=\"size-large wp-image-153\" srcset=\"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/04_toolbox-1024x636.png 1024w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/04_toolbox-300x186.png 300w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/04_toolbox-768x477.png 768w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/04_toolbox-600x373.png 600w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/04_toolbox-200x124.png 200w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/04_toolbox.png 1253w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><figcaption id=\"caption-attachment-153\" class=\"wp-caption-text\">The algorithm is hidden in the toolbox<\/figcaption><\/figure>\n<p>The input parameters for the algorithm are straightforward; fill them and create this new layer.<\/p>\n<figure id=\"attachment_152\" aria-describedby=\"caption-attachment-152\" style=\"width: 849px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/04b_count.png\" alt=\"\" width=\"849\" height=\"558\" class=\"size-full wp-image-152\" srcset=\"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/04b_count.png 849w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/04b_count-300x197.png 300w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/04b_count-768x505.png 768w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/04b_count-600x394.png 600w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/04b_count-200x131.png 200w\" sizes=\"auto, (max-width: 849px) 100vw, 849px\" \/><figcaption id=\"caption-attachment-152\" class=\"wp-caption-text\">Not much to explain here&#8230;<\/figcaption><\/figure>\n<h3>Visualize the result<\/h3>\n<p>Double-click on the new layer and set the type of <em>Style<\/em> to Graduated based on the attribute <em>NUMPOINTS<\/em>. Classify using a decent color ramp and you are done!<\/p>\n<figure id=\"attachment_155\" aria-describedby=\"caption-attachment-155\" style=\"width: 912px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/05_color.png\" alt=\"\" width=\"912\" height=\"821\" class=\"size-full wp-image-155\" srcset=\"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/05_color.png 912w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/05_color-300x270.png 300w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/05_color-768x691.png 768w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/05_color-600x540.png 600w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/05_color-200x180.png 200w\" sizes=\"auto, (max-width: 912px) 100vw, 912px\" \/><figcaption id=\"caption-attachment-155\" class=\"wp-caption-text\">Standard Deviation is a good color mode for this type of data<\/figcaption><\/figure>\n<figure id=\"attachment_154\" aria-describedby=\"caption-attachment-154\" style=\"width: 625px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/06_color-1024x653.png\" alt=\"\" width=\"625\" height=\"399\" class=\"size-large wp-image-154\" srcset=\"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/06_color-1024x653.png 1024w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/06_color-300x191.png 300w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/06_color-768x489.png 768w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/06_color-600x382.png 600w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/06_color-200x127.png 200w, http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-content\/uploads\/sites\/7\/2017\/04\/06_color.png 1274w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><figcaption id=\"caption-attachment-154\" class=\"wp-caption-text\">Looks like an 80s-Avalon Hill-style wargame!<\/figcaption><\/figure>\n<h3>Discussion<\/h3>\n<p>You can use this method to overlap several layers of information:<\/p>\n<figure style=\"width: 2413px\" class=\"wp-caption alignright\"><a href=\"https:\/\/github.com\/xrubio\/pastByNumbers\/raw\/master\/gallery\/hexes_romans.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/github.com\/xrubio\/pastByNumbers\/raw\/master\/gallery\/hexes_romans.png\" width=\"2413\" height=\"3449\" class=\"size-large\" \/><\/a><figcaption class=\"wp-caption-text\">Blending hexes with the Stamen Terrain layer<\/figcaption><\/figure>\n<p>What can we say from this visualization? Some interesting spatial patterns are clearly visible:<br \/>\n1. The Firth of Forth seems to concentrate the majority of camps<br \/>\n2. The Romans definitely did not like Western Scotland. They probably did not want to move far from the coast where their fleet supported them<br \/>\n3. The route followed by the armies was probably used as the basis for the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Gask_Ridge\">Gask Ridge<\/a> fortification line<\/p>\n<h3>Acknowledgements<\/h3>\n<p>This post was heavily inspired by the entry written by Anita Graser in <a href=\"https:\/\/anitagraser.com\/2012\/03\/04\/mapping-density-with-hexagonal-grids\/\">her blog<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hexes! If you like boardgames you probably love those awesome maps were terrain has been transformed into a grid of hexagons (popularly known as hexes). Beyond this geeky interest hex-based maps can be used to create interesting visualizations where you want to colour the map based on a specific variable. These visualizations are technically known [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":162,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[15,4,20,10,11],"class_list":["post-133","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-gis","tag-dataviz","tag-qgis","tag-romans","tag-shp","tag-warfare"],"_links":{"self":[{"href":"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-json\/wp\/v2\/posts\/133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-json\/wp\/v2\/comments?post=133"}],"version-history":[{"count":7,"href":"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":135,"href":"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-json\/wp\/v2\/posts\/133\/revisions\/135"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-json\/wp\/v2\/media\/162"}],"wp:attachment":[{"href":"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/research.shca.ed.ac.uk\/past-by-numbers\/wp-json\/wp\/v2\/tags?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}