{"id":142,"date":"2015-04-30T08:41:31","date_gmt":"2015-04-30T08:41:31","guid":{"rendered":"http:\/\/transnationalhistory.net\/mapping\/?page_id=142"},"modified":"2023-08-29T15:13:38","modified_gmt":"2023-08-29T15:13:38","slug":"performing-queries","status":"publish","type":"page","link":"https:\/\/transnationalhistory.net\/mapping\/tutorials\/performing-queries\/","title":{"rendered":"Performing Queries"},"content":{"rendered":"<p style=\"text-align: right;\"><em><strong>Tutorial 6<\/strong><\/em><\/p>\n<p>&nbsp;<\/p>\n<p>So far we have seen ways to depict and show phenomena and trends on a map. As historians, this opens up many opportunities for every researcher&#8217;s project. This tutorial is about learning from your map and getting data you didn&#8217;t know was already there for you. Layers aren&#8217;t just lines and shapes: they contain different types of information that you may find useful. It is something we saw already with CSV lists:\u00a0we\u00a0could add any information\u00a0we wanted in our CSV, but only the lat\/long points would be displayed. Let&#8217;s learn how to make the most out of your shapefiles.<\/p>\n<p>We will use the <em>communes<\/em> (towns)\u00a0and <em>d\u00e9partements<\/em> (districts) of France as a case study.<\/p>\n<p><strong>STEP 1: GETTING FAMILIAR WITH ATTRIBUTE TABLES<\/strong><\/p>\n<p>I have added a coastline base layer and downloaded territorial data from the French governmental\u00a0<a href=\"http:\/\/professionnels.ign.fr\/bddvecteur\" target=\"_blank\" rel=\"noopener\">IGN Donn\u00e9es<\/a> website.<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-map-france-all-communes.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-152\" src=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-map-france-all-communes.jpg\" alt=\"\" width=\"571\" height=\"502\" srcset=\"https:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-map-france-all-communes.jpg 571w, https:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-map-france-all-communes-300x264.jpg 300w\" sizes=\"auto, (max-width: 571px) 100vw, 571px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-open-attribute-table.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-153\" src=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-open-attribute-table.jpg\" alt=\"6 open attribute table\" width=\"297\" height=\"234\" \/><\/a>The map which is displayed here features 36,595 towns. As we said before, this layer is not just showing them &#8211; it has a detailed list of their names as well as other data. To see this, we need to access the <strong>attribute table<\/strong>. To do so, right click on the name of the layer and choose <strong>Open Attribute Table<\/strong>.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-attributetable.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" size-large wp-image-154 aligncenter\" src=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-attributetable-1024x473.jpg\" alt=\"6 attributetable\" width=\"690\" height=\"319\" srcset=\"https:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-attributetable-1024x473.jpg 1024w, https:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-attributetable-300x139.jpg 300w, https:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-attributetable.jpg 1323w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/a><\/p>\n<p>As you can see, the table precisely lists each town&#8217;s name, postcode, lat\/long, area, population, and the <em>d\u00e9partement<\/em> and <em>r\u00e9gion<\/em> it is part of. In other words, this is way more than what the map seemed to show!<\/p>\n<p><strong>STEP 2: FILTERING\u00a0YOUR LAYER<\/strong><\/p>\n<p>The attribute table is great to access more information, but this sometimes needs to be filtered in order to only keep what is necessary. You can do so through the attribute table but this tutorial is going to show you a quicker way to filter your layer.<\/p>\n<p>We want to\u00a0focus on the French Riviera, on the south-eastern coast of France. More precisely I would like to only display the towns located in the <em>d\u00e9partement<\/em> (district) of\u00a0<em>Alpes-Maritimes<\/em>.<\/p>\n<p>Close your attribute table and right click again on your layer name, and choose <strong>Filter<\/strong>.\u00a0This part of the process is a bit tedious. In the window that just opened you will need to insert\u00a0an expression. Expressions are similar to mathematical formulas.<\/p>\n<p><a href=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-querybuilder1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-344\" src=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-querybuilder1.jpg\" alt=\"6 querybuilder1\" width=\"743\" height=\"699\" srcset=\"https:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-querybuilder1.jpg 743w, https:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-querybuilder1-300x282.jpg 300w\" sizes=\"auto, (max-width: 743px) 100vw, 743px\" \/><\/a><\/p>\n<p>In the left column, you will find all the fields that you previously saw in the attribute table. Here we want to filter by district name, therefore we are selecting\u00a0<strong>NOM_DEPT<\/strong> and by clicking on <strong>All<\/strong>\u00a0in the right column, all the different district names appear. You can now easily build your expression by double clicking on each of its elements. Therefore, as you only the towns located in the <em>Alpes-Maritimes<\/em> district to appear, your expression should be as follows:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-formula1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-345\" src=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-formula1.jpg\" alt=\"\" width=\"238\" height=\"17\" \/><\/a><\/p>\n<p style=\"text-align: left;\">Click on\u00a0<strong>OK<\/strong>.\u00a0The map is now only showing the\u00a0<em>communes\u00a0<\/em>of the\u00a0<em>d\u00e9partement\u00a0<\/em>of\u00a0<em>Alpes-Maritimes<\/em>, but you will always have the option of re-adding some other parts of the layer by changing your formula.<\/p>\n<p style=\"text-align: left;\"><a href=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-filtered-alpes-maritimes.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-169\" src=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-filtered-alpes-maritimes.jpg\" alt=\"\" width=\"447\" height=\"354\" srcset=\"https:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-filtered-alpes-maritimes.jpg 447w, https:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-filtered-alpes-maritimes-300x238.jpg 300w\" sizes=\"auto, (max-width: 447px) 100vw, 447px\" \/><\/a><\/p>\n<p><strong>STEP 3: FILTERING YOUR ATTRIBUTE TABLE BY DATA<\/strong><\/p>\n<p>Now that we have selected this\u00a0<em>d\u00e9partement<\/em>, we would like to only show the towns which have a population higher than 20,000. <strong>This is a choice we are making for this tutorial. Step 2 and Step 3 can of course be done independently from each other.<\/strong><\/p>\n<p>Back in the <strong>Filter<\/strong> option, we are repeating the same process, by operating a new query.\u00a0The previous formula will still be there, you need to add the\u00a0<strong>&#8220;POPULATION&#8221; &gt; 20000<\/strong> one\u00a0afterwards. Both should be separated by <strong>AND<\/strong> which is necessary in order to take both conditions under consideration.<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-double-formula.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-346\" src=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-double-formula.jpg\" alt=\"6 double formula\" width=\"418\" height=\"15\" srcset=\"https:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-double-formula.jpg 418w, https:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-double-formula-300x11.jpg 300w, https:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-double-formula-387x15.jpg 387w\" sizes=\"auto, (max-width: 418px) 100vw, 418px\" \/><\/a><\/p>\n<p>We now have gone from over 36,000 towns to only 10.<\/p>\n<p><a href=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-final.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-173\" src=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-final.jpg\" alt=\"6 final\" width=\"349\" height=\"221\" srcset=\"https:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-final.jpg 349w, https:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-final-300x190.jpg 300w\" sizes=\"auto, (max-width: 349px) 100vw, 349px\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>Final result with railways added to the map<\/em><\/p>\n<p><strong>MORE THAN ONE QUERY ON THE SAME SHAPEFILE?<\/strong><\/p>\n<p><a href=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-duplicate.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-230\" src=\"http:\/\/transnationalhistory.net\/mapping\/wp-content\/uploads\/2015\/04\/6-duplicate.jpg\" alt=\"6 duplicate\" width=\"282\" height=\"104\" \/><\/a>Should\u00a0you want to filter two different elements of one single shapefile (e.g. two groups of French <em>communes<\/em>), and deal with them separately, you may duplicate your layer and perform different queries on each of them. To duplicate a layer, right click on its name and click on duplicate.<\/p>\n<p><strong><a href=\"http:\/\/transnationalhistory.net\/mapping\/tutorials\/performing-queries\/advanced\/\">One step further: creating a new layer out of a query<\/a><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Last update: 1 June\u00a02015 on QGIS 2.8.1 Wien.<\/p>\n<p style=\"text-align: right;\"><a href=\"http:\/\/transnationalhistory.net\/mapping\/tutorials\/datavis-circles\/\">Next tutorial:<\/a><br \/>\n<strong><a href=\"http:\/\/transnationalhistory.net\/mapping\/tutorials\/datavis-circles\/\">Data Visualisation on your Map<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tutorial 6 &nbsp; So far we have seen ways to depict and show phenomena and trends on a map. As historians, this opens up many opportunities for every researcher&#8217;s project. This tutorial is about learning from your map and getting data you didn&#8217;t know was already there for you. Layers aren&#8217;t just lines and shapes: [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":8,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-142","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/transnationalhistory.net\/mapping\/wp-json\/wp\/v2\/pages\/142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/transnationalhistory.net\/mapping\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/transnationalhistory.net\/mapping\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/transnationalhistory.net\/mapping\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/transnationalhistory.net\/mapping\/wp-json\/wp\/v2\/comments?post=142"}],"version-history":[{"count":2,"href":"https:\/\/transnationalhistory.net\/mapping\/wp-json\/wp\/v2\/pages\/142\/revisions"}],"predecessor-version":[{"id":597,"href":"https:\/\/transnationalhistory.net\/mapping\/wp-json\/wp\/v2\/pages\/142\/revisions\/597"}],"up":[{"embeddable":true,"href":"https:\/\/transnationalhistory.net\/mapping\/wp-json\/wp\/v2\/pages\/8"}],"wp:attachment":[{"href":"https:\/\/transnationalhistory.net\/mapping\/wp-json\/wp\/v2\/media?parent=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}