tag:blogger.com,1999:blog-84787055924647270542017-09-19T02:10:54.559+05:30Quantum GIS (QGIS) TutorialsBeginner to Advanced level Quantum GIS tutorials and tips with screenshotsUjaval Gandhinoreply@blogger.comBlogger31125tag:blogger.com,1999:blog-8478705592464727054.post-3263959165772840902014-05-11T16:03:00.000+05:302014-05-11T16:03:05.334+05:30Tutorials moved to http://qgistutorials.com<div dir="ltr" style="text-align: left;" trbidi="on">I have moved all my QGIS tutorials to a new website. Tutorials are upgraded for QGIS 2.0 and are organized by topics. Completely free and optimized for classroom use.<br /><br />Visit <a href="http://www.qgistutorials.com/">http://www.qgistutorials.com</a> to see the updated tutorials. This blog will no longer be updated.<br /><br />Please follow me on <a href="http://google.com/+UjavalGandhi">http://google.com/+UjavalGandhi</a> to get updates on new tutorials.</div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com0tag:blogger.com,1999:blog-8478705592464727054.post-9934130363990248772013-04-04T18:03:00.000+05:302014-04-07T20:06:41.665+05:30Tutorial: Nearest Neighbor Analysis using QGIS<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc; font-size: large;"><span style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;">Tutorial moved to&nbsp;</span><a href="http://www.qgistutorials.com/en/docs/nearest_neighbor_analysis.html" style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;">http://www.qgistutorials.com/en/docs/nearest_neighbor_analysis.html</a></span><br /><strike><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><br /></span>GIS is very useful is analyzing spatial relationship between features. One such analysis is finding out which features are closest to a given feature. QGIS has a tool called ‘Distance Matrix’ which helps with such analysis. In this tutorial, we will use 2 datasets and find out which points from one layer are closest to which point from the second layer.</strike><br /><strike><br /></strike><br /><a name='more'></a><strike><br /></strike><strike>The topics covered by this tutorial are</strike><br /><ul style="text-align: left;"><li><strike><a href="http://qgis.spatialthoughts.com/2012/01/importing-spreadsheets-or-csv-files-to.html">Importing CSV file to QGIS</a>.</strike></li><li><strike>Understanding and using the Distance Matrix tool.</strike></li><li><strike>Using<a href="http://qgis.spatialthoughts.com/2012/03/using-tabular-data-in-qgis.html"> table joins</a> to merge the result of the analysis with the source data.</strike></li></ul><strike>Let’s get started. In this tutorial, we will walk through the process and answer this question. Given the locations of all known significant earthquakes, find out the nearest populated place for each location where the earthquake happened.</strike><br /><strike><br /></strike><strike>We will be using the <a href="http://www.naturalearthdata.com/downloads/10m-cultural-vectors/10m-populated-places/">Natural Earth Populated Places</a> dataset along with NOAA’s National Geophysical Data Center’s <a href="http://www.ngdc.noaa.gov/nndc/struts/form?t=101650&amp;s=1&amp;d=1">Significant Earthquake Database</a>.</strike><br /><strike><br /></strike><strike>Follow the instructions in <a href="http://qgis.spatialthoughts.com/2012/01/importing-spreadsheets-or-csv-files-to.html">this tutorial</a> to import the Significant Earthquake CSV file to QGIS. Also open the Natural Earth populated places layer using Layer → Add Vector Layer.</strike><br /><div><strike><br /></strike><strike><img src="https://lh5.googleusercontent.com/zBu3BQw2ixbltX8hy28THvyqS51CqStJymOTdYlaZJw8yiBxFtmzNobx91igkyN0RfVv-5bUK5MjvqQjLaA8cB-BSQctjPESEO3tVCcQ-93sjtKMmTjwEyPV" /></strike><br /><strike><br /></strike><strike>In the screenshot, each green point represents the location of a significant earthquake and each blue point represents the location of a populated place. We need a way to find out the nearest point from the populated places layer for each of the points in the earthquake layer.</strike></div><div><strike><br /></strike><strike><img src="https://lh6.googleusercontent.com/yne2nRbzi0y5akWr7oXH_B9Ux9szfNVV9gIH_IykXetfRUHJO9VblnCXrxWFgIy3GV3NNDrhC9wRlO3-dolKUTr6TzYrGR7Rc7owY7l2Bkj1SP8hrc1ZQVtK" /></strike><br /><strike><br /></strike><strike>We will use a tool called ‘Distance Matrix’ for this analysis. Open the tool from Vector → Analysis Tools → Distance Matrix.</strike></div><div><strike><br /></strike><strike><img src="https://lh4.googleusercontent.com/wU05M7uR1b5KIlV-IIDcDzBpdzWrvXCjvaQMHOwUqLx9IdVPeavUIyySXZ5XCWZI1SwK0FZmMo2vcWFls3ish_BZsclezbK2TjnYwjFmmROJ2cXMmjevEPWM" /></strike><br /><strike><br /></strike><strike>Here select the earthquake layer as the Input point layer and the populated places as the target layer. You also need to select a unique field from each of these layers which is how your results will be displayed. In this analysis, we are looking to get only 1 nearest point, so check the box next to ‘Use only the nearest(k) target points, and enter 1. Name your output file ‘matrix.csv’, and click OK.</strike></div><div><strike><br /></strike><strike><img src="https://lh6.googleusercontent.com/x0qhiLKM43ntiVgT-MEWe2rQf_NLnH8StxUJJTyR7ezCvpa4GoJIoPv5dyIilvlKWjQCM4HeLe0paa-sG9L1QCiMTcrMNd27C1mORYZVpfUA_YKCT1lDKfwC" /></strike><br /><strike><br /></strike><strike>Once your file is generated, you can view it in Notepad or any text editor. QGIS can import CSV files as well, so we will add it to QGIS and view it there. Click Layer → Vector Layer. Navigate to the path where you saved ‘matrix.csv’ and click OK.</strike></div><div><strike><br /></strike><strike><img src="https://lh6.googleusercontent.com/_G_Cxnrt0SexW9KaDRt3Hy3b1Gs0lsLyj9oJ9SWwmL5u-F3EIMkgESecdys4hem-WHt0-Pw46tRAEps_6_cqKkfkrTTz024peaNv7OJh4qh825GA5Uwnh7oC" /></strike><br /><strike><br /></strike><strike>You will the the CSV file loaded as a table.&nbsp;</strike></div><div><strike><br /></strike><strike><img src="https://lh3.googleusercontent.com/vHflMxMA82QxmHFQBamn9Puqe4YtvCzY2iYLwSjhYV7Gj5zt1OZYI12Xo0qQDpy36GCJE-wd1JhchXXPie2z5bjqeu7NgN6ZoYVTpkSgfvs6ZJL4R-8dUY23" /></strike><br /><strike><br /></strike><strike>Right click on the table layer and select ‘Open Attribute Table’.</strike></div><div><strike><br /></strike><strike><img src="https://lh4.googleusercontent.com/cW8zKhOiwndK8Mmc5te5s8F8FyhZ5Mi1joK6HMi-8LQtdToNakKcKKD2PJgY4tPS9F9D2hqVmHOWEMC4tB38S4FCz9IKCnLhIZ7bI7iiYyoKu3QrbfhXhtIV" /></strike><br /><strike><br /></strike><strike>Now you will be able to see the content of our results. The InputID field contains the field name from the Earthquake layer. The TargetID field contains the name of the feature from the Populated Places layer that was the closest to the earthquake point. The Distance field is the distance between the 2 points.</strike></div><div><strike><br /></strike><strike><img src="https://lh4.googleusercontent.com/QEt6bXRwquI_J3SzbMcBlxCOQa3YcM8eJBLz2GQywgCUi37tOymfIep3Qumwv2KpzJ7oRA-lA0Bww4WW-KTwGFJG3r3hhvFSzJh0_z2jwFWTzVjPT1rLgz1c" /></strike><br /><strike><br /></strike><strike>This is very close to the result we were looking for. For some uses, this table would be sufficient. I will demonstrate, how we can use Table Joins to integrate this results in our original Earthquake layer. Look at <a href="http://qgis.spatialthoughts.com/2012/03/using-tabular-data-in-qgis.html">this tutorial</a> for more details on Table Joins. Right click on the Earthquake layer, and select Properties.</strike></div><div><strike><br /></strike><strike><img src="https://lh3.googleusercontent.com/rNk6zRe3gY4fAChuIuRGi9JChxN9-VhZ9VxNR7uRGA6uD0_r2UdMjfHIuXHkm_uUMlQW7pIaxj94J51i5Z2X2sCvJcEtBpDwVB_xf4jfAU0eplZlYJffLfPe" /></strike><br /><strike><br /></strike><strike>Go to the Joins tab and click on the ‘+’ button.</strike></div><div><strike><img src="https://lh3.googleusercontent.com/BluQGNOUaLCp2nI6oyRGhBBo3jEwBAWl6lbSqM9dnZB_DqMviYdRI3-K-VPEA2ZQpQNzc8A0dMQZzwc7Rdd310ynak2b6I_ZZ7sfzwUQk1t8Hq9E3CX-YdOr" /></strike><br /><strike><br /></strike><strike>We want to join the data from our analysis result (matrix.csv) to this layer. We need to select a field from each of the layers that has the same values. Select the fields as shown below.</strike></div><div><strike><br /></strike></div><div><strike><img src="https://lh5.googleusercontent.com/KekG3n4Ar2wvs1bu6kATB_NrxT67kQ_2I7bwkTQ-u5O5__a2EwI6kla_AKm6QzJX4tCpKkLf3vs9yiECp1IUhYfcpBN9EKFzBUbV8ek9oVAfy7UVPjUeIgdY" /></strike><br /><strike><br /></strike><strike>You will see the join appear in the Joins tab. Click Ok.</strike></div><div><strike><br /></strike><strike><img src="https://lh6.googleusercontent.com/SUkXXvWCL6WGUW8-caCCqFBbc2GbKV0I0JW-jQNcf8kdubDyuUdgysS6vgO-zhECyPO1NAP_2yfUP5IKDmmPJo392IrwjNFVwzdkdJonFfufRiS57ThrsV_g" /></strike><br /><strike><br /></strike><strike>Now open the attribute table of the Earthquakes layer.</strike></div><div><strike><br /></strike><strike><img src="https://lh6.googleusercontent.com/IbX8Gb9t9HqPyC4hbfHm6ickWFkEn3Usy9Dv0_hPjYdcc3m0hVr4dLDmJpOjWGDTwaGTrR0WzpKX5l9CX0cVGe0GMoRrZvijNmBc8gr1nrzDotbopJZLF_z4" /></strike><br /><strike><br /></strike><strike>You will see that for every Earthquake feature, we now have an attribute which is the nearest neighbor (closest populated place) and the distance to the nearest neighbor.</strike></div><div><strike><br /></strike></div><div><strike><img src="https://lh5.googleusercontent.com/niEczRhD1_mT5DVXVwD1_ha5DmMEg0uNzG2HW0Emr6D1OFq3JDagcjk6uIgxDYQ-8OrX3z2K5EF354Qop5_L6eFozQYt3LPv3Nm6jQYx4k9gMnmN4pxT5tld" /></strike></div><div><strike><br /></strike><strike>A useful thing to note is that you can even perform the analysis with only 1 layer. Select the same layer as both Input and Target. The result would be a nearest neighbor from the same layer instead of a different layer as we used here.</strike><br /><strike><br /></strike><strike>Let me know in the comments how you have used this tool and what kind of cool applications you can think of using it.</strike></div></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com1tag:blogger.com,1999:blog-8478705592464727054.post-15698521471230487832013-02-21T19:44:00.000+05:302014-05-05T12:48:22.894+05:30Tip: Open BIL, BIP and BSQ files in QGIS<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc;"><span style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: medium; line-height: 25.200000762939453px;">Tutorial moved to&nbsp;</span><a href="http://www.qgistutorials.com/en/docs/open_bil_bip_bsq_files.html" style="color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: large; line-height: 25.200000762939453px;">http://www.qgistutorials.com/en/docs/open_bil_bip_bsq_files.html</a></span><br /><strike><br /></strike><strike>When dealing with remote sensing and scientific datasets, one often comes across data in formats like BIL, BIP or BSQ. GDAL, which is used by QGIS to read raster files has support for these formats, but it cannot open these files by itself. I will go through the process of creating support files so these formats can be read by QGIS.</strike><br /><strike><a href="http://draft.blogger.com/blogger.g?blogID=8478705592464727054" name="more"></a><br /></strike><a name='more'></a><strike><br /></strike><div><strike>Band interleaved by line (BIL), band interleaved by pixel (BIP), and band sequential (BSQ) are common methods of organizing image data for multiband images. You can read more about these formats <a href="http://webhelp.esri.com/arcgisdesktop/9.2/index.cfm?TopicName=BIL,_BIP,_and_BSQ_raster_files">here</a>.</strike><br /><strike><br /></strike><strike>Typically, these files are accompanies by a ‘<i>.hdr</i>’ file. If your dataset came with a ‘<i>.hdr</i>’ file, make sure the root name of the <i>.bil</i>, <i>.bsq</i> or <i>.bip</i> file and the <i>.hdf</i> files match and they are in the same directory. For example, if the file is called ‘<i>image.bil</i>’ , the associated file should be named <i>image.hdr</i> and present in the same directory as the <i>image.bil</i> file. Then when you go to Layer → Add Raster Layer, select the ‘<i>.bil</i>’ file and it will open without problems.</strike><br /><strike><br /></strike><strike>Many a times, the files do not come with an associated ‘<i>.hdr</i>’ file. In such cases, you must create this file by hand as shown below.</strike><br /><strike><br /></strike><strike>For this tip, I will use the <a href="http://glcf.umd.edu/data/landcover/data.shtml">AVHRR Global Land Cover Classification</a> data from <a href="http://glcf.umd.edu/">Global Land Cover Facility</a> as an example. The Global Coverage datasets are distributed as a ‘<i>BSQ</i>’ file.</strike><br /><strike><br /></strike><ul><li><strike>Download the <a href="ftp://ftp.glcf.umd.edu/glcf/Global_Land_Cover/Global/1deg/gl-latlong-1deg-landcover.bsq.gz">1 Degree pixel resolution</a> dataset. Unzip and extract the <i>.bsq</i> file. On Windows, you may use the excellent <a href="http://www.7-zip.org/">7-Zip utility</a> to read and extract .gz file. You will see that you only have a .<i>bsq</i> file named gl-latlong-1deg-landcover.bsq. There is no hdr file.<img src="https://lh6.googleusercontent.com/eXjHYu-6gmKHnSBqVzzkSeftmlLCpN7oBin3WMm8u2MDEjGAyq7Jkm55IK_P_ymgaoxX9JDthtTzkWWt0IyP-GsMK5f9XBDxDdAeVPoDq2seYTAgsVPlkXbT" /></strike></li></ul><ul><li><strike>Note that if you try to open the <i>.bsq</i> file in QGIS as it is, you will get an error message. <img src="https://lh6.googleusercontent.com/qTV6cH9HUQ-672oW3izl4MMEcVr1irIupJwICG2YSGdQ-4IRGc3pyJgwliar0avlu2iMhffi4XDo6kKInwybSQ758MOXATWRT2riGDuWmF_gUV8MiNccl39j" /></strike></li><li><strike>To overcome this error, we will create a <i>.hdr</i> file. The hdr file contains information about the dataset and how it is organized. Usually, this information is supplied as part of Metadata for the dataset. If you do not have the metadata, look at the website or documentation for clues. Some of the information can be guessed if you do not know it. In case of this dataset, if you open the <a href="ftp://ftp.glcf.umd.edu/glcf/Global_Land_Cover/Global/1deg/gl-latlong-1deg-landcover.glcf">metadata</a>, you will see much of the information needed.</strike></li></ul><strike><img src="https://lh3.googleusercontent.com/UFcABey8OWC1apN_0IgpEkOMOJJLQzMjH86dhl15RYPcebxOYwyNpihO9Wmq5jFyb_2VFf46kKkJuTB1RWhs888QmwJwsImYMqs4QibX4I8Lz58rRL4cCx-F" /></strike><br /><ul><li><strike>The <i>.hdr</i> file needs to be a plain text file in the following format. Some of these parameters are given to us and some needs to be worked out. More on the format <a href="http://www.gdal.org/frmt_various.html">here</a>.&nbsp;</strike></li></ul><span style="font-family: Courier New, Courier, monospace;"><strike> ncols &lt;number of columns or width of the raster&gt;<br /> nrows &lt;number of rows or height of the raster&gt;<br /> cellsize &lt;pixel size or resolution&gt;<br /> xllcorner &lt;X coordinate of lower-left corner of the raster&gt;<br /> yllcorner &lt;Y coordinate of the lower-left corner of the raster&gt;<br /> nodata_value &lt;pixel value to be ignored&gt;<br /> nbits &lt;number of bits per pixel&gt;<br /> pixeltype &lt;type of values stored in a pixel, typically float or integer&gt;<br /> byteorder &lt;byte order in which image pixel values are stored, msb or lsb&gt;</strike></span><br /><strike><br /></strike><ul><li><strike>Open a text editor and create a file with following text. Save the file as gl-latlong-1deg-landcover.hdr. Make sure the file doesn’t have .txt at the end. Some of the values in the text files are easy to understand. the <b>ncols </b>and <b>nrows </b>come from the metadata as the Number of Lines and Number of Pixels per Line. The <b>cellsize </b>is 1 as the Pixel resolution from the metadata. The X,Y coordinate of lower-left corner needs to be worked out by us. Since the file covers the entire world and units are lat/long, <b>xllcorner </b>and <b>yllcorner </b>are -180 and -90 respectively. We do not have any information about the <b>nodata_value</b> , so -9999 is a safe bet. From metadata again, Pixel Format is Byte, so <b>nbits </b>will equal to 8 and <b>pixeltype </b>will be byte_unsigned. We do not have information about the <b>byteorder</b>, so leave it as msbfirst.<img src="https://lh5.googleusercontent.com/j6w_B-Rowc-S6OQGne2Q9d0JyxU_Z8Z1iSZ6ASge8xXL4XwZUnmWamQBD1fAtLxCzjj8fcBYDj3sUUApj4dX4yY0sTO8mRRcHYrCCtexdU2UbZgyneNDpPZ1" /></strike></li><li><strike>Now that you have the .hdr file, put it in the same directory as gl-latlong-1deg-landcover.bsq. Then in QGIS, go to Layer → Add Raster Layer. select gl-latlong-1deg-landcover.bsq as your input.<img src="https://lh3.googleusercontent.com/w--ee-ZivvWKhtkmXR9rw5SrPUMMRvSGJdiCvD9wS3OElempfIvBeRTR7_cy-LZiijD33mLEvdbUBk-oGg-gPhPqV6gjgHmyyg-4rZ2ecDTi3pN3K0CL5UNi" /></strike></li><li><strike>In the next screen, you will be prompted to choose a CRS. Since the data is in Lat/Long, choose WGS84 EPSG 4326 as your CRS. Now you will see the dataset loaded in QGIS.<img src="https://lh6.googleusercontent.com/lFkwt91huWli8iDKn2nP7cheX4SSzTXRDBrlT1aRM33dT11Gnl7rI913yyEGjpIrWSxag8qOkKsENginhJeYGflgMUlFwiqGEbSrlqLm-goz7A_ThDq86CgC" /></strike></li></ul></div></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com0tag:blogger.com,1999:blog-8478705592464727054.post-30858915843157512772013-02-19T22:28:00.000+05:302014-04-07T21:09:24.928+05:30Tutorial: Advanced Georeferencing in QGIS using a Reference Layer<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc;"><span style="font-size: large;"><span style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;">Tutorial moved to&nbsp;</span><span style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><a href="http://www.qgistutorials.com/en/docs/advanced_georeferencing.html">http://www.qgistutorials.com/en/docs/advanced_georeferencing.html</a></span></span></span><br /><div><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: medium;"><strike><br /></strike></span></div><strike>In the previous tutorial “<a href="http://qgis.spatialthoughts.com/2012/02/tutorial-georeferencing-topo-sheets.html">Georeferencing Topo Sheets, Topo Maps, Satellite Image or Scanned Maps in QGIS</a>”, you learnt the basic process of georeferencing in QGIS. That method involved reading the coordinates from your scanned map and inputting it manually. Many times though you may not have the coordinates printed on your map, or you are trying to georeference a photograph. In that case, you can use another georeferenced data source as your input. In this tutorial, I will show you how you can use existing open data sources in your georeferencing process.</strike><br /><strike><br /></strike><a name='more'></a><strike>The topics covered by this tutorial are</strike><br /><ul><li><strike>Downloading super high-resolution public domain imagery</strike></li><li><strike>Using OpenLayers plugin in QGIS</strike></li><li><strike>Converting coordinates between different projection using cs2cs command-line tool</strike></li><li><strike>Using an existing georeferenced layer to input GCP points in the Georeferencer tool</strike></li><li><strike>Setting a custom no-data value for a layer.</strike></li></ul><div><strike>Let’s get started. In this tutorial, we will be using some gorgeous kite and balloon imagery collected by <a href="http://publiclaboratory.org/archive">The Public Laboratory</a>. They make the georeferenced versions of the images also available, but we will download a non-georeferenced JPG image and go through the process of georeferencing it in QGIS. If you like the imagery they provide, you can<a href="http://google-latlong.blogspot.in/2012/04/balloon-and-kite-imagery-in-google.html"> explore it</a> in Google Earth as well.</strike><br /><ul><li><strike>Go to the <a href="http://publiclaboratory.org/map/washington-square-park-new-york-new-york/2012-10-01">download page</a> for Washington Square Park, New York from Public Laboratory. Right-click on the JPG button and click ‘Save link as’. Save it to your hard drive.</strike></li></ul><div><strike><img src="https://lh6.googleusercontent.com/NuoX20hP9SDPWAL7yYoDMQ9uuwoJpEMxvI2fBqbD1Y8i5TSSUTxnf9YeUGBgDbOHAVshJV10UclxcguOE_amTMZO7p_lopMaC0tnvASotv1SxBkrXRYgSNmo" /></strike></div><ul><li><strike>For this tutorial, we will be using the OpenStreetMap layer as our reference layer. The reference layer could be anything. It could be a georeferenced map that you have for the area or a vector layer which may have roads or landmarks that are in your image. In QGIS, the ‘OpenLayers plugin’ provides easy access to the rich global dataset from OpenStreetMap (OSM). Since OpenStreetMap has global coverage, this method will work well for most georeferencing tasks. Once you have fetched and loaded the plugin, go to Plugins → OpenLayers plugin → Add OpenStreetMap layer.<img src="https://lh5.googleusercontent.com/q_eCZL_XP7exK0PkpSywJwhN7vVaxP-H-2V4CXxkVw2vXSazqg4P6TFRXHLMDz4niGuQdnmHwxwpFj-Ny4xaDxBNk_9eGsw-sk3vSNfbrn5rjkQXAwP-XTMe" /></strike></li><li><strike>Now you have the OpenStreetMap layer loaded in QGIS. Note the Coordinate Reference System (CRS) for this layer. It is set as EPSG 3857 Pseudo Mercator. This is important to note, since the coordinates we ‘infer’ from this layer will be in this CRS.<img src="https://lh5.googleusercontent.com/F4YxgdyLOA65SuDzboJKqKNTWLBCwnSsoaazJEiaFicEZFSH8bXj9F5re5wyt8ao8Lo_qwXwk71jl4quvEiXf7SfywNzpOqKXi779HSjrfQPQ9A8nESTNL5f" /></strike></li><li><strike>Now the task is to locate the general vicinity of the area that we are trying to georeference. You can just use Pan and Zoom tools to locate that area on the OpenStreetMap layer. But I will take this chance to demonstrate another tool that may help you in future. We know that the image we downloaded is for Washington Square Park in New York. If you search for that place, you will be able to locate the wikipedia page for it. The coordinates for the park are listed there.<img src="https://lh3.googleusercontent.com/vs0jBNbcd_OV-XvoHNOZsL8uOQhZ24N2tXs1Sn18EPCDAzmNHWijhOif_d1Sa990aX0jGEtIJ5oVsQR2S2S64gByxkYnKW2O7WLVJXTq8AL6EKXSg9FIMWDA" /></strike></li></ul><strike><br /></strike><ul><li><strike>You will notice that the coordinates are in Degrees/Minute/Seconds and are Latitude and Longitude. But since our layer is in Mercator projection, we will need Mercator coordinates to locate the park. Here’s where a command-line tool called ‘cs2cs’ comes handy. If you have installed QGIS from OSGeo4W installer, you will already have it installed on your system. On Linux and Mac too, it comes pre-installed with QGIS. Launch a terminal window and type ‘cs2cs’ to check if it is available. Windows users can find a terminal at Start → OSGeo4W → MSYS.</strike></li></ul><div><strike><img src="https://lh4.googleusercontent.com/HzeESmvuQWB6T7vKaAXCo7szBHq_T0Oz1lqDY7068TK4X70xchyPmlDCmYobEqWgmuxzG8_xJQvtbjkgsAxZ5_Pw6qUBTRg9pHGicOvbSzOKn2deFEupZ4AW" /></strike></div><ul><li><strike>Once you have verified that the cs2cs tool exists on your system, it is time to convert out Latitude and Longitude to Mercator coordinates. The way this tool works is that you need to specify a ‘source’ and ‘destination’ CRS. The CRS definition could be a PROJ4 string or an EPSG code. Since we already know the EPSG code for out input and output CRS, we will use this. The simplest way to use the tool is to supply the input coordinates on the command line itself. Note that the tool accepts coordinates in the order “X Y”, so we need to enter “Longitude Latitude”. <img src="https://lh5.googleusercontent.com/c_EqqNFKDybKFFaog0cp242jiEpM20TH6JGfaKxmqBR5UawLN5aL-KjO54OkP6z83YoSCBODaS2eEwmdoRoUbZVU-8_qw15zfgylil3XGzY4SoLHCOgzVNS8" /></strike></li><li><strike>Once you press enter, you will see the tool process the coordinates and print out output X Y coordinates in EPSG 3857 CRS. Copy these coordinates and switch to QGIS. At the bottom of the QGIS window, you will see a textbox labeled Coordinates. Enter the coordinates there in X,Y form. Press Enter. You will see the map shift a bit, but not zoom. To zoom to the area, select 1:2500 scale from the Scale drop-down next to the Coordinate box. Voila! you now see Washington Square Park area on your canvas.<img src="https://lh6.googleusercontent.com/Lx-G-AAG2-WheZdcMZp5Udq1qWIBnQ-_bt92cNgM3e1gbdaUGyGAmVcj6FzjSLWm7dQQ0V3L0lC6saGzDgaXjf1AZoA8bRzPRoFOrGIAGji5airW1UnROjgg" /></strike></li><li><strike>Now it is time to start georeferencing. Launch the Georeferencer from Raster → Georeferencer → Georeferencer.<img src="https://lh5.googleusercontent.com/Dw6EX5YOumWEyNAh-rSNatTJZWWAFZGXX38zKXvubfs-wZEJeQXzfnOM0hal0zgq08mxZffzxxld12CYiSyAd62DphWwBjghoF7PAO8A6CUzdbAFdfnz_hcO" /></strike></li><li><strike>Click on Open raster button. Navigate to the 2011-04-27-newyork-newyork-washingtonsquarepark.jpg image saved on your disk. Click OK.<img src="https://lh6.googleusercontent.com/4bqqkqGIrab6vMJEaRiAIyRDYTzP0Wc2AinLUBc5x6EJSIP0Rpx8gRpaorn-zHRmpO5kBctmqVN8Yj0w78h517_ww577me1_po69ZgBxGKrlOELX80OJV25E" /></strike></li><li><strike>In the CRS selected, choose the CRS of the reference layer EPSG 3857.<img src="https://lh6.googleusercontent.com/QI7L-4mL73qfuYdvGoQKcqm7ot2y8bL1QkSEsqNOdBXPyS2FtFgVEB6SoWAIKfdGCOq_gneES7X_BWq2oCRnNizH7_hIIjar7L8niRklwLdtPBqmOJEecqw9" /></strike></li><li><strike>Now click on the ‘Add Point’ button on the toolbar and select an easily identifiable location on the image. Corners, intersections, poles etc. make good control points. Once you click on the image at a control point location, you will see a pop-up asking you to enter map coordinates. Click the button ‘From map canvas’.<img src="https://lh3.googleusercontent.com/7w2mSYyAlUco-W7zBqyo64QToar10f_N3mHQqn8v8Nc7GHk1m_EGPc_CVbaWkdTebt27a9hwbW5RD4QAS319pAe_KtnojBVylMn1ZLTIExjy7F1bRr3mhA-Vqg" /></strike></li><li><strike>Find the same location in your reference layer, i.e. the OpenStreetMap layer and click there.<img src="https://lh4.googleusercontent.com/ABUUxRSgggn9KeFOCszKx6Y4j1p-gnpk2Ayi7BITjxPW80vGLe2J_gsAVE5wUJ63DaN-4DU3C47-cqTKtal9uC3tvTbltLUgahCRFzQTXuuxOOcTKFCa9YI0" /></strike></li><li><strike>The coordinates are auto-populated from your click on the map canvas. Click Ok.<img src="https://lh5.googleusercontent.com/AumErca_5gET_kjWS4aSd-33xilFU3RGssM7M_PB_jn2ycpFEPuBbi22uow_EtfZVXnWrCcSbu6Sqouzh5UjfDZ5vu4MsjFo__Li9zzg8Tx1U4mASRr7Y2r3" /></strike></li><li><strike>Repeat this process till you have found at least 4 ground control points (GCPs). Then click on ‘Transformation settings’ button.<img src="https://lh3.googleusercontent.com/69WrlpkFIYOfZWw6_Tj4GfA764FKMRFHOsyZo3a8ChrhY--8_86rVnMXZHf0xrrv1NgdljxJ8mrZ6E9OW-tKVGyJsmeV6aj4J7NoFXwOGEbvBbiGKuA-7-0m" /></strike></li><li><strike>Choose the settings as shown below. Make sure you check the ‘Load in QGIS when done’ button. Click OK.</strike></li></ul><div><strike><img src="https://lh5.googleusercontent.com/mVV48BpKQcY63-3kmho1zTa5lukViLMC-M-DSav_gFSXApz9GajD_CDDrbHBYE2nVc8zxhrAUiP4gbgC648oUt7Ad1HzVHJcOjV1M2zTYGtNigH6D1mpDmVV" /></strike></div><strike><br /></strike><ul><li><strike>Now you are ready to begin applying the transform. Click the ‘Start georeferencing’ button.<img src="https://lh6.googleusercontent.com/TWJL6uPS6T3r-kdWJhOjBbVgB6N4-iHHdBbE-Dh0PJG2f184cKAZxp84LIUTWw2l2DMDhmLQjVjFWZ6TIsoMRIzLF0V4XfREgJnzIDuATI-Z7K1mVm2i7NAF" /></strike></li><li><strike>Once the process finishes, you will see your newly georeferenced image loaded in QGIS. If all went well, you will see it nicely overlay the OpenStreetMap layer.<img src="https://lh4.googleusercontent.com/pS-MYBMUpIo49_M7E5kf460QqxKRB7SQkn09zdH-77jWH30WHPZFZrg_iIK9DzFKrglL8q-TtaCdW5hZLv9ypR0TGf4fnfyylEfjs3OGMqywnW_xPSu97fLv" /></strike></li><li><strike>To make our output look nicer, let’s remove the white no-data values. Right click on the image layer and Choose Properties. Switch to the Transparency tab and input 255 as the no-data value, since in our case the unncessary portion of the image is white. Also move the global transparency slider to 25%. Click OK.<img src="https://lh6.googleusercontent.com/htjFkHWKNxmY2clUzRxdN2srY8SYHUUOfzfGccbfG5J5w5wZrCaXDiai-BE1J25LkFmSnJd07akFUf34yYwH8BriwfmOefOSkK35qprEoKpxfbXOWA9nP1KI" /></strike></li><li><strike>There you have it. You have successfully georeferenced a plain JPG image to a GeoTiff image.<img src="https://lh5.googleusercontent.com/22L8hcXgRvrL3mm43cAvwUY79pUjBx3_7WPJh_FC6fNfCaYSRoohet1RP4JUPxWucoJvTTwrxfvYbvvDET8PIrV9GwEh4QLGIxzRzHLKdzDAD2sYWXXPLkva" /></strike></li></ul><strike><br /></strike><br /></div></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com1tag:blogger.com,1999:blog-8478705592464727054.post-52507935283422510692012-12-29T17:51:00.000+05:302014-05-05T12:51:03.081+05:30Tip: Find Neighbor Polygons in a Layer in QGIS<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: medium; line-height: 25.200000762939453px;">Tutorial moved to&nbsp;</span><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: medium; line-height: 25.200000762939453px;"><a href="http://www.qgistutorials.com/en/docs/find_neighbor_polygons.html" style="color: #4d469c;">http://www.qgistutorials.com/en/docs/find_neighbor_polygons.html</a></span><br /><strike><br /></strike><strike>There are some use cases where you want to find all neighboring polygons of each of the polygons in a layer. With a little python script, we can accomplish this and much more in QGIS. Here is an example script you can use to find all polygons that touch each of the polygons in a layer and also add their names to the attribute table. A user also wanted to sum up the values of a given attribute from all the neighboring polygons, so I added that part to the script as well.</strike><br /><strike><br /></strike><a name='more'></a><strike><br /></strike><strike>To demonstrate this, let’s take an example that given a layer of country polygons, you want to find countries that share the border and also what is the total population of the country’s neighbors.<a href="https://draft.blogger.com/blogger.g?blogID=8478705592464727054" name="more"></a></strike><br /><strike><br /></strike><ul><li><strike><a href="https://docs.google.com/open?id=0B0Xc7QoGul60ckVDbzNTY04yWFU">Download the neighbors.py script</a> and save it on your hard drive.&nbsp;</strike></li><li><strike>Load your layer in QGIS. For this example, I am using the admin_0_countries layer from the <a href="http://www.naturalearthdata.com/">Natural Earth </a>dataset.<img src="https://lh3.googleusercontent.com/Lmd_DvPyBMPSagJkT1PEzHmn9fr51VlezbTQ-s7jOROttrOh9J8EvtbL4WZS9KXc3suvCiNjEejy3GnoiXCHB6_5Q7FS7k61_xzFgMBA4ZaGte3a8Vo" /></strike></li><li><strike>The script uses 2 fields to perform the action. a ‘name’ field and a field that you want to sum up. In this case the name field is ‘NAME’ and we want to sum up the population estimates from ‘POP_EST’ field. Open the neighborys.py script in a text editor like Notepad and change the field values from your layer.<img src="https://lh4.googleusercontent.com/ZH6LXalRFiNtupj5vZrghyCVwklFvItObitDhRU9XiVA4gKqEbG1pSG9tm9PH8agPxy-PnfrxjQ49YvTnBfXqY53Hy0SC0QOiLifVAh7ZoNn6aRQLBY" /></strike></li><li><strike>Start the Python Console by going to Plugins → Python Console.<img src="https://lh4.googleusercontent.com/NPIhklGdnk9iPo1tCBIfaYO8aSYDvupkFTb3OzOUeP-gSmUQBHWdEvyHR1IgQwKj4nlh1TXkg0RLLtL0v9AwojOBBvEoY1riI9eQ0zV181NZH_sk5ro" /></strike></li><li><strike>Now make sure you have selected the layer. Then run the script using the command <span style="font-family: Courier New, Courier, monospace;">execfile(“Path to your file”)</span>. I saved my file in D:/Data/scripts/neighbors.py, so I would run a command like <span style="font-family: Courier New, Courier, monospace;">execfile(“D:/Data/scripts/vertex.py”)</span><img src="https://lh3.googleusercontent.com/wZw07__zUYhKfn-I3fnQk7wXB_Q2EQoya9YVNVfPZ_McyFogXX7hJsTDwiRccYL-4NxZsARKafUp4gJ6a1msOR3FicJFn_tMtV7h_5MIrClsUgyFvfA" /></strike></li><li><strike>The script will take some time to run as it is comparing each polygon against ALL of the other polygons. If you get a message like QGIS is not responding, do not worry. Just let the script run and it will finish without problems. One the script finishes, open the attribute table. Voila! You now have 2 extra attribute fields in your table called ‘Neighbors’ and ‘Sum’. <img src="https://lh3.googleusercontent.com/Bo95gXhJ71SqxcSzFBNNPDVng0AOAWVwSlImDNuOykh8dAhFZQHgIiCWjVdIX5c8u-mIymZnZEGXoQBTkD1HqIwZsJVW0AaA9yoHBqllf3ymAJivLw8" /></strike></li></ul><strike><br /></strike><strike>Let me know if you run into problems. You will need the <a href="http://pypi.python.org/pypi/Shapely">shapely python library</a> installed on your system. On windows, it is part of the standard QGIS OsGeo4W installer. On Ubuntu, you can run ‘<span style="font-family: Courier New, Courier, monospace;">sudo apt-get install python-shapely</span>’ to install the library.</strike><br /><strike><br /></strike><strike>The code in neighbors.py is as below. You can modify the code in the script to suit your needs, save it in a file and run it to perform the action. </strike><br /><strike><br /></strike><strike><b id="internal-source-marker_0.5845610362011939" style="font-weight: normal;"><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">from PyQt4.QtCore import *</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">from shapely.wkb import loads</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"># Replace the below value with the field containing name or id of the feature</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"># For example, if your field is called name then change the line below to</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"># name_field = 'name'</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">name_field = 'NAME'</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"># Replace the below value with the field name that you want to sum up</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">sum_field = 'POP_EST'</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">layer = qgis.utils.iface.activeLayer()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">layer.startEditing()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">provider = layer.dataProvider()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"># We add 2 attributes to the current layer</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">provider.addAttributes( [QgsField("Neighbors", QVariant.String),</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QgsField("Sum", QVariant.Int)])</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">neighbor_name_index = provider.fieldNameIndex("Neighbors")</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">neighbor_sum_index = provider.fieldNameIndex("Sum")</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">allAttrs = provider.attributeIndexes()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"># Select all features along with their attributes</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">provider.select(allAttrs)</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">feat = QgsFeature()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">polygon_dict = {}</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"># Loop through all features and store their geometry and relevant attributes in</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"># a dictionary</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">while provider.nextFeature(feat):</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;feature_id = feat.id()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;attrmap = feat.attributeMap()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;name = attrmap[provider.fieldNameIndex(name_field)].toString()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;sum_value = attrmap[provider.fieldNameIndex(sum_field)].toInt()[0]</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;print 'Reading Geometry for %s' % name</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;geom = feat.geometry()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;wkb = geom.asWkb()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;polygon = loads(wkb)</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;polygon_dict[feature_id] = [ polygon, name, sum_value ]</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"># Now one-by-one take a feature and find all other features that touch its</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"># geometry</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">all_polygons = polygon_dict.keys()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">attribute_dict = {}</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">for polygon_id in all_polygons:</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;this_polygon, this_name, this_sum = polygon_dict[polygon_id]</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;neighbor_list = []</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;sum_of_neighbors = 0</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;for polygon_id_compare in all_polygons:</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;compare_polygon, compare_name, compare_sum = polygon_dict[polygon_id_compare]</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;if this_polygon.touches(compare_polygon):</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;neighbor_list.append(unicode(compare_name))</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum_of_neighbors += compare_sum</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;# Make a list of all neighbors' names</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;neighbor_string = ','.join(neighbor_list)</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;attribute_dict[polygon_id] = {neighbor_name_index: QVariant(neighbor_string),</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;neighbor_sum_index: QVariant(sum_of_neighbors)}</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"># Update the attribute table</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">provider.changeAttributeValues(attribute_dict)</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">layer.commitChanges()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">layer.stopEditing()</span></b><span style="font-family: Courier New, Courier, monospace;"><br /></span></strike><br /><strike><br /></strike><br /></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com2tag:blogger.com,1999:blog-8478705592464727054.post-11507557896674020012012-11-06T21:57:00.000+05:302014-04-07T21:11:00.490+05:30Tip: Clip a Raster in an Irregular Shape using QGIS<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc;"><span style="font-size: large;"><span style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;">Tutorial moved to&nbsp;</span><span style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><a href="http://www.qgistutorials.com/en/docs/raster_mosaicing_and_clipping.html">http://www.qgistutorials.com/en/docs/raster_mosaicing_and_clipping.html</a></span></span></span><br /><br /><strike>Sometimes clipping a raster using a rectangle is not sufficient. You might want to clip the raster based on the boundary of your area of interest. In QGIS, there is an option to use a ‘Mask layer’ while clipping a polygon.</strike><br /><strike><a href="https://draft.blogger.com/blogger.g?blogID=8478705592464727054" name="more"></a><br /></strike><a name='more'></a><strike><br /></strike><div><strike>You will need a polygon layer which has the boundary of your area of interest. In this example, I would like to clip my raster using the country boundary for Australia. Load both the raster and the vector polygon layer in QGIS.</strike><br /><div><strike><br /></strike><strike><img src="https://lh6.googleusercontent.com/7Y6vKTkI9e240oQ93UAiJobLH9S7t0Y5XgdKdAcrzTI5CxhnwHotp4bqyUaCNtS5oSOoDtv7SJtGBloceK5F83Y4UHwWJnoKy_5ndTtIDzfkPouJLoU" /></strike><br /><strike><br /></strike><strike>Open ‘Clipper’ tool from Raster → Extraction → Clipper</strike></div><div><strike><br /></strike><strike><img src="https://lh4.googleusercontent.com/ZRbacozvJRIU2hX-udtpeJmxGonGkNZH0T753cDhM9QoCBlhT2BQ9JG-bxqQ6Hnw8zlcOPBXG53OmgdeUpPaEeIjcXKMgPF6p-kzxMmlKr74xfbsUCQ" /></strike><br /><strike><br /></strike><strike>In the Clipper dialog, select the raster as the Input file. Then select the name and path for the output file. In the ‘Clipping mode’ section, select the Mask layer mode. Select the polygon layer as the Mask layer. Make sure the&nbsp;check-boxes&nbsp;for ‘No data value’ and ‘Load into canvas when finished’ are checked on. Click OK.</strike></div><div><strike><br /></strike><strike><img src="https://lh6.googleusercontent.com/aBFIa9LIgLmE7OODJ02Gdv7Xz_exEd873XKi8ge7R39548ezih7-mE9KPHSgDxZtLMQ-ocU2nH1yYZLEY207Fep_xYwX2iF-0cDaQKic3cONARh9sJk" /></strike><br /><strike><br /></strike><strike>Once the process finishes, you will have a new raster which is clipped to the boundary of the polygon layer.&nbsp;</strike></div><div><strike><br /></strike><strike><img src="https://lh6.googleusercontent.com/hCbRc35qPEJpN_duXEZ1jZ5yV5b0XrvrdsMi-ypx6xj_sfLSF3tbPEi5O5UxK2lFuZtbgKXR5HKXvd7x9sQrVfdNoEoXl2oLxC-BaO0u-l3jUKGvj3M" /></strike></div></div></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com1tag:blogger.com,1999:blog-8478705592464727054.post-3817564553609890372012-11-02T13:25:00.000+05:302014-03-28T19:45:12.790+05:30Tip: Count Number of Vertices in a Layer using QGIS<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.200000762939453px;">This tutorial has moved. Please see&nbsp;</span><a href="http://www.qgistutorials.com/en/docs/counting_vertices.html" style="background-color: #f4cccc; color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: x-large; text-decoration: none;" target="_blank">Counting Number of Vertices in a Layer</a><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.200000762939453px;">&nbsp;for an updated version of this tutorial.</span><br /><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.200000762939453px;"><br /></span><strike>QGIS doesn’t have a built-in function to calculate number of vertices for each feature in a layer. You can use Vector → Geometry Tools → Extract Nodes to break the geometry into individual vertices and get a points layer. But there is an easier and better way to do this using python scripting in QGIS. You do not need to know any python for doing this. The below example will help you count the total number vertices in a polygon layer as well as add an attribute named ‘Vertices’ in your attribute table.</strike><br /><strike><a href="https://draft.blogger.com/blogger.g?blogID=8478705592464727054" name="more"></a><br /></strike><a name='more'></a><strike><br /></strike><strike>Open QGIS. Load the polygon layer you want to count vertices. Start the Python Console by going to Plugins → Python Console.</strike><br /><div><strike><br /></strike><strike><img src="https://lh6.googleusercontent.com/xC-kpnOzQfDl4ZR5kFN4Am73PmtFJqyLN9u6rpwTAUhGmerVqaCSN60aTm2USMKpd2pRY3lFbHbz4ijqV3btq8KOIHnEzJW00WtjO88vfo3-vPJ__S0" /></strike><br /><strike><br /></strike><strike>Once in the Python Console. Copy and Paste the following code and press ‘Enter’ twice. Make sure the layer is selected before pasting the code.</strike></div><div><strike><br /></strike><b id="internal-source-marker_0.6037728008814156" style="font-weight: normal;"><strike><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">layer = qgis.utils.iface.activeLayer()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">provider = layer.dataProvider()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">provider.select()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">feat = QgsFeature()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">vertex_count = 0</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">while provider.nextFeature(feat):</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;geom = feat.geometry()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;if geom.type() == QGis.Polygon:</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;layer_vertices = 0</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;if geom.isMultipart():</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;polygons = geom.asMultiPolygon()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;else:</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;polygons = [ geom.asPolygon() ]</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;for polygon in polygons:</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for ring in polygon:</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;layer_vertices += len(ring)</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;print "Feature %d: Vertices %d" % ( feat.id(), layer_vertices)</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;vertex_count += layer_vertices</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;print "Total vertices: %d" % (vertex_count)</span></strike></b></div><div><b style="font-weight: normal;"><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><strike><br /></strike></span></b></div><div><strike><img src="https://lh5.googleusercontent.com/vRLQ5I9Ns8FRkYaxOLxAvudy-31wxYxfDGBfWR9egboXxu0pbJq4iJO5LMRLbrCyvTiVLodKDgvsPZCsnDF0IRpwf076mjk7CU-XTcGsifxURIMdXKk" /></strike><br /><strike><br /></strike><strike>You will see lot of statements printed in the console with the certex count for each layer. You will also see the cumulative ‘Total Vertices’. The last statement for ‘Total Vertices’ is the total number of vertices in the layer.</strike></div><div><strike><br /></strike><strike><img src="https://lh3.googleusercontent.com/5X3XQXQcUbFZlNJbUV3uM76BEAv33QWcQlC6x3EjWbOJrI4MsToOKe4fioKMtf3wzs46c60yVC7Hg9VOvq8taN077ph5wVgnd4-doxS0ysHEtxHY7sQ" /></strike><br /><strike><br /></strike><strike>This is useful, but a more useful approach is to add this information directly to the attribute table of the layer, so you can use it in your analysis. This code is a little more complex and cannot be pasted in the console due to indentations. You can <a href="https://docs.google.com/open?id=0B0Xc7QoGul60ZzRwb3BDLU5WQms">download vertex.py</a> from this location and save it on your system. After that, just run it using the command <span style="font-family: Courier New, Courier, monospace;">execfile(“Path to your file”)</span>. I saved my file in D:/Data/scripts/vertex.py, so I would run a command like <span style="font-family: Courier New, Courier, monospace;">execfile(“D:/Data/scripts/vertex.py”)</span></strike></div><div><strike><br /></strike><strike><img src="https://lh3.googleusercontent.com/kNEMq0NqgipdV0w415wfnfTQyiAeK8eIa-WcumBCvWHFkXP6ZMl6TQZ9Qi_oWurMBPS9B3Zl_aCjFvqOllAK-30DTnY_Xu_mU0Ofs68WY77_bxPt5Uc" /></strike><br /><strike><br /></strike><strike>If the command was successful, you will see an additional column in your Attribute Table named ‘Vertices’.</strike></div><div><strike><br /></strike><strike><img src="https://lh5.googleusercontent.com/q3ACB9pzfjlv_gBGXHjsxXuwQ29Py_yxrXjAkjfad4jg36gFjzQ8bhl02LfXfmWeTSjxeobnCNDuzOdww0DxxJrGkN6mgv8Lm9lxMS3cA1ZYeuIbDbQ" /></strike><br /><strike><br /></strike><strike>The script doesn’t do much error checking or validation. Let me know if you run into problems. The code in scripy.py is as below. You can modify the code in the script to suit your needs, save it in a file and run it to perform the action. </strike><br /><strike><br /></strike><b id="internal-source-marker_0.6037728008814156" style="font-weight: normal;"><strike><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">from PyQt4.QtCore import *</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">layer = qgis.utils.iface.activeLayer()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">layer.startEditing()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">layer.dataProvider().addAttributes( [ QgsField("Vertices", QVariant.Int) ] )</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">provider = layer.dataProvider()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">vertices_field_index = provider.fieldNameIndex("Vertices")</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">provider.select()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">feat = QgsFeature()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">vertex_count = 0</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">attribute_dict = {}</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">while provider.nextFeature(feat):</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;geom = feat.geometry()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;if geom.type() == QGis.Polygon:</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;layer_vertices = 0</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;if geom.isMultipart():</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;polygons = geom.asMultiPolygon()</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;else:</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;polygons = [ geom.asPolygon() ]</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;for polygon in polygons:</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for ring in polygon:</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;layer_vertices += len(ring)</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;print "Feature %d: Vertices %d" % ( feat.id(), layer_vertices)</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;vertex_count += layer_vertices</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> &nbsp;&nbsp;&nbsp;attribute_dict[feat.id()] = { vertices_field_index: QVariant(layer_vertices) }</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">print "Total vertices: %d" % (vertex_count)</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">layer.dataProvider().changeAttributeValues(attribute_dict)</span><br /><span style="font-family: 'Courier New'; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">layer.commitChanges()</span></strike></b><span style="font-family: Courier New, Courier, monospace;"><br /></span></div></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com4tag:blogger.com,1999:blog-8478705592464727054.post-10168903929063430072012-10-22T18:40:00.000+05:302013-02-22T20:48:32.224+05:30Tip: Opening Zip Files Directly in QGIS<div dir="ltr" style="text-align: left;" trbidi="on">Typically GIS datasets are large and often distributed as zip files. Normally, you would unzip them first and then load them up in QGIS. Starting version 1.8, QGIS can load zip files directly. You can save disk space and time by opening zip files directly in QGIS now. <br /><br /><a name='more'></a><br /><a href="" name="more"></a><br /><ul><li>To enable this feature, open QGIS → Settings → Options → General. Scroll down till you find the option named ‘Scan for contents of compressed files in browser dock’. Set the value to ‘Full scan’. Click OK.</li></ul><img src="https://lh5.googleusercontent.com/4g82-9wLtLv0uewx5Lq3gMUgRG1vYkl4w7XdvB9W3Ee4NnJSPEtBAhmeQLTXVq34ubyRZ_Jiw0N1FcxN8AUXvQFh232c67Oj6YlgHqq2eLTdUz9S8yk" /><br /><br /><div><ul><li>Now .zip files become valid files supported by QGIS and you can add them directly via ‘Add Layer’ menu or via the <a href="http://qgis.spatialthoughts.com/2012/10/tutorial-using-quantum-gis-browser.html">QGIS Browser</a>.</li></ul><img src="https://lh4.googleusercontent.com/BZQXvG-YIBhgKWR7DH3f88m3_QJNrsDgjiIUUbdyUILCJhvZcAS-cwQ8XQ8lUBZFMz2adHYvGVoTf1QvpgvTUmTHuGmrLLJhkx1Vp3MQ-M8Cn4uFeEY" /><br /><br /><br /></div></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com0tag:blogger.com,1999:blog-8478705592464727054.post-91921760060508586952012-10-21T15:01:00.000+05:302013-02-22T20:50:19.100+05:30Tip: Identify Across All Layers in QGIS<div dir="ltr" style="text-align: left;" trbidi="on">The default QGIS behavior is to look up attributes of the currently selected layer when you use the ‘Identify’ tool. Sometimes when working with many layers in your QGIS project, you don’t know which layer a particular feature belongs. In such cases, just clicking on a feature and getting to know its attributes - regardless of whether the layer is selected , is really helpful. There is an option to make the Identify tool pull up attributes of all the features from all layers in your project. MapInfo users are used to this feature and if you are missing it, use the following setting to enable it.<br /><br /><a name='more'></a><br /><ul><li>From Settings → Options select the ‘Map tools’ tab. Select the ‘Top down’ option from the drop-down box in the Identify section.</li></ul><img src="https://lh6.googleusercontent.com/Uh0q4hh_fCchHHOLzbRnAxUA8GrXGS3NToymMyODTrRBjcuAAm3jdUahEa69K3VhRfYnP2JOt_kKPu7Q5QGTrSmxQW-L--GElkU8NcJbiJOklQinp1A" /><br /><br /><ul><li>Now use the Identify tool to click anywhere on your map. You can expand each layer to see attributes of features from that layer.</li></ul><div><br /></div><div><img src="https://lh3.googleusercontent.com/IUpOyL2vr78t1PWaNeooT7WSmGM6jkOQEOcB2NoNAlrMhM18v97-J1u6Cx2fl4l74R50FO5jMJHshYfdymDtrM7vKudu1h2pqf5K-fuJp3HzEVIYHZk" /></div></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com0tag:blogger.com,1999:blog-8478705592464727054.post-61723241918230376482012-10-17T10:51:00.001+05:302014-04-07T21:13:18.455+05:30Tutorial: Basic Raster Analysis and Styling in QGIS<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc;"><span style="font-size: large;"><span style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;">Tutorial has moved to&nbsp;</span><span style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><a href="http://www.qgistutorials.com/en/docs/raster_styling_and_analysis.html">http://www.qgistutorials.com/en/docs/raster_styling_and_analysis.html</a></span></span></span><br /><br /><strike>A lot of scientific observations and research produces raster datasets. Rasters are essentially grids of pixels that have a specific value assigned to them. By doing mathematical operations on these values, one can do some interesting analysis. QGIS has some basic analysis capabilities built-in via Raster Calculator. In this tutorial, we will explore basics on using Raster Calculator and options available for styling rasters.</strike><br /><strike><br /></strike><a name='more'></a><strike><br /></strike><strike>For this tutorial, we will use the <a href="http://sedac.ciesin.columbia.edu/data/collection/gpw-v3">Gridded Population of the World (GPW), v3</a> dataset from Columbia University. Specifically, I downloaded the <a href="http://sedac.ciesin.columbia.edu/data/set/gpw-v3-population-density/data-download">Population Density Grid</a> for the entire globe in ASCII format and for the year 1990 and 2000. Our task will be to find and visualize areas of the world that have seen dramatic population density change between year 1990 and 2000.</strike><br /><strike><br /></strike><strike>Open QGIS. Locate the 2 zip files for year 1990 and 2000 in QGIS Browser. <a href="http://qgis.spatialthoughts.com/2012/10/tutorial-using-quantum-gis-browser.html">See this tutorial on using QGIS Browser and opening zip files in QGIS</a>.</strike><br /><div><strike><br /></strike></div><div><strike><img src="https://lh5.googleusercontent.com/lHMpqh04q5Jr8E5msruEO0PimKlloxAKpO7zDR-H_yw0JV7QVQTtiqVEKaK0T794AMjkXBq3VCZlSliyGA6FoeweuRzBzVgZF3q8X6cRT-9lbLt0-8w" /></strike></div><div><strike>There are 2 grid files for each of the years. The ‘a’ in the filename suggests that the population counts were adjusted to match the UN totals. We will use the adjusted grids for this tutorial. Expand and double-click on the glds90ag.asc layer to load it in QGIS. The layer doesn’t have a CRS defined, and since the grids are in lat/long, choose EPSG:4326 as the coordinate reference system.<img src="https://lh6.googleusercontent.com/HvzPFGStkuAW57h8adCb7sPP-r_JqU92LsRF1laPeuupGfVMsnwI-sPBoCqlANeFoZNcK48JTfUiisOchuQ_meqummbrQuN-7uq8FmPnEtRJADzMQI4" /></strike></div><div><strike>Each pixel in the raster has a value assigned. This value is the population density for that grid. Click on ‘Identify Features’ button to select the tool and click anywhere on the raster to see the value of that pixel.<img src="https://lh4.googleusercontent.com/3xTu6MDPiQd7tMZEewOPga3_s0XmjRIxeuJBcHD6DaOzVMSXvPv0kFz_lQpTA77T2J_EHBOEebEyf6KAUNxEUOz0kPIEiuA0zBrlLDTi2IO8CCIVDjQ" /></strike></div><div><strike>You must have noticed that the pixel values differ from place to place, but our raster is just plain grey everywhere. To better visualize the pattern of population density, we would need to style it. Double-click on the layer name in the TOC to bring up the Layer Properties dialog. You could also right-click on the layer name and select Properties. Under the ‘Style’ tab, change the ‘Color map’ to Pseudocolor. Click OK.<img src="https://lh3.googleusercontent.com/mVfQWnH_cEjyyIon3ZWifrPCSZlqkYh4z7kKTfxkQ48TZ3YBaS3ZPG2DaShw72CvBY7aZdeZhrxLyh21FWdhKI8mw0ny0iiKpFCQiKx1ao8izXGp-l8" /></strike></div><div><strike>Now you will see a little more variation on the colors and can see how the population density is distributed.<img src="https://lh6.googleusercontent.com/CKYoTRp192JZl3F4UnpJqd72vMCbI_4teuEzlE5O4nXczgm4wONj2OUEllR8Sj8lmZaq1X31nDkH1kUsSShFDoq2OGEl82tRaRuN1UYdTpxz79AT1do" /></strike></div><div><strike>Now locate and load the year 2000 grid glds90ag.asc by double-clicking or dragging the layer from the browser.<img src="https://lh4.googleusercontent.com/50E7Q-pruHIPwPokePkSJkwnftevU4QcRTCbJaj5XR1ftF2kTlbfqD8IG33uEydFLJHX7NEPWnJLpNCEfcQKKb1I7LMCgmi8omIMR68FsticEokNKcU" /></strike></div><div><strike>You can apply the same Pseudocolor style to this layer as well.<img src="https://lh6.googleusercontent.com/vfL2-ajYM91seWT3a6auwQ2GfXmSBwKQvgijZv0zoBK7060u-fD0aqbeWSX9A2SlqbEv15ahjupUOu0BwnvGwaayA_xhvdbUZ2_IJwoUjwIU0XeSxJw" /></strike></div><div><strike>For our analysis, we would like to find areas with largest population change between 1990 and 2000. The way to accomplish this is by finding the difference between each grid’s pixel value in both the layers. Select Raster → Raster calculator.<img src="https://lh6.googleusercontent.com/A0_D4nAW-58b41xumbNm5STDiGn00kTrnppG44vzldtsQvIqzJXCdhR4SO5yZUwRQwM54V02GGmMnCLEgdy3oGIsbRViixtDe5sO9_lHY-T6hLZ_0wE" /></strike></div><div><strike>In the ‘Raster bands’ section, you can select the layer by double-clicking on them. The bands are named after the raster name followed by @ and band number. Since each of our rasters have only 1 band, you will see only 1 entry per raster. The raster calculator can apply mathematical operations on the raster pixels.In this case we want to enter a simple formula to subtract the 1990 population density from 2000. Enter “glds00ag@1 - glds90ag@1” as the formula. Name your output layer as ‘density_change’ and check the box next to ‘Add result to project’. Click Ok.<img src="https://lh3.googleusercontent.com/yroDouEMbEpsVntLEPa3681c2T1pGuRZ1mVX-wAgiK5MbiIAp2RGcvc-3Bz-LiPZ-F7OmW-TPnnpDXBS670tleWqZKT7TgRti_TQeub3pKDEj8l5cmw" /></strike></div><div><strike>Once the operation is complete, you will see the new layer load in the TOC. <img src="https://lh6.googleusercontent.com/00mG4ovPQ0qHOluDiOf8qzQ2TJwHdY346ouQhm-Uc3fz8JVv8pbm9qMDZfL_2V9MUQb9Iaw8q2Edwnc8mmsNgoLwMFYAdLWg8V36mk6wYJCrwhi7-cA" /></strike></div><div><strike>Right-click on the layer and select ‘Properties’. Under the Style tab, select Custom min/max values. We want to style the layer using the actual min/max values. In the section ‘Load min / max values from band’, select Actual and click Load. Change the ‘Contrast enhancement’ to ‘Stretch to MinMax’. Click Ok.</strike></div><div><strike><br /></strike></div><div><strike><img src="https://lh5.googleusercontent.com/u2Llae1oyGF4In009HUouHg-40qHTJB0Kvbu7MwV8DgYvIzhKiYaueG2QFqbRD8T06y0JoHfCrue99MG-5bYq6TMTNzrNRBvj4t-SYE2o3mZmoYPWoU" /></strike></div><div><strike>Now the layer will be styled so the minimum values are black and the maximum values are white. The values in-between are shades of grey. <img src="https://lh6.googleusercontent.com/R5_zpdqqi8YnDg0NOIWSz_w6gpKpABULUAjv_bFeXPmGzvoM4c2Azz1B-8r-uDx9rYFA-bt_-ODq3VxFTfcfPgJLOSoJmbhVoDC9nM41wYDz-zLPv-w" /></strike></div><div><strike>This visualization is useful, but we can create a much more informative output. Go back to the Properties menu. Choose Colormap as the ‘Color map’ in Single band properties.</strike></div><div><strike><br /></strike></div><div><strike><img src="https://lh6.googleusercontent.com/r6pvetI47hnv7nIoiTb1zNoHwKRf9sV4vTrNTipIhgbRstyW0rcttmR9u-g-6GYVdH9R2FhhaYU3ZwLlIK880fgeTmUtRID99aiem4IQST6oB0IxeWs" /></strike></div><div><strike>We want to style the layer so pixel values in certain ranges get the same color. Before we dive in to that, go to the Metadata tab and look at the properties of the raster. Notice that the No Data value. It is usually a large negative value that is reserved for areas of the raster where the pixels are empty. We want to keep that in mind when styling our layer. Also note the minimum and maximum values of this layer.<img src="https://lh4.googleusercontent.com/_oyprblBeG83ad27_h82cUsr9TTPiIrlqdaG8HwWFOCveKgyHnO6nWXfM_5X1J0fCASb60wBEzK2zeAeNHB7aybenppX5azYliPXm2aw6YyzI0jwLeg" /></strike></div><div><strike>Go to the Colormap tab. Select ‘Color interpolation’ as Discrete. Click the ‘Add entry’ button 4 times to create 4 unique classes. Click on an entry to change the values. The way color map works is that all values lower than the value entered will be given the color of that entry. Since the minmum value in our raster is just above -3600, we choose -3600 as the first entry. This will be for the No Data values. Enter the values and Labels for other entries as below and click OK.</strike></div><div><strike><br /></strike></div><div><strike><img src="https://lh6.googleusercontent.com/WponaSxs72a5TC28W4EqWhSy1kFoAOaYqr4fFAWE8iIEJYd1l44eXhlAgxvP1Fo47UTELs2J4T96qkwMWQgTevZt0pT2A0x-QBVkzRBYccKijjKqAD0" /></strike></div><div><strike>Now you will see a much more powerful visualization where you can see areas which has seen positive and negative population density changes.<img src="https://lh4.googleusercontent.com/MRhJslpeygGbrbTu-fGJGEgWd0Z1nJMpUjPRibOfRFdy89VMJBhloIF3Oz-1CpqQdgO7suDqrONL7li-XK6zRwsYudsnKG0VdxyLPto4K1aBGATtfaY" /></strike></div><div><strike>Now let’s take this analysis one-step further and find areas with only ‘negative’ population density change. Open Raster calculator. Enter the expression as ‘density_change@1 &lt; -10’. What this expression will do is set the value of the pixel to 1 is if matches the expression and 0 if it&nbsp;doesn't.&nbsp; So we will get a raster with pixel value of 1 where there was negative change and 0 where there&nbsp;wasn't&nbsp; Name the Output layer as ‘negative_change’ and check the box next to ‘Add result to project’. Click OK. <img src="https://lh3.googleusercontent.com/xvu9LL2Mt-6InDmIy8wQuAxUcBEkfKOJYOIMeQT1nA_feinzGW0nTlR3eQyQOvMbt3DbCcGmUDzOVjhq6LN_BwrJmNx5a0zIz0ioH_lBbPEurW0Rjlo" /></strike><br /><strike><br /></strike></div><div><strike>Once the layer is loaded, right-click and select Properties.<img src="https://lh6.googleusercontent.com/pmSBR6Kduw6hweiYfycYVweIi2pTuoXz1qdA32ibcgbue65huJuXBxpdbO7PeOgk8PxpNrNcR2r_PPQ91rIlegrKcjQ6xE2Ev8OWmuNRAadBHmK8cAU" /></strike></div><div><strike>Since our layer has only 2 unique pixel values - 0 and 1, we can use Grayscale colormap. Load the min / max values and select ‘Stretch to Min/Max’ as the contrast stretch. Click OK.</strike><br /><strike><br /></strike><strike><img src="https://lh4.googleusercontent.com/TrIcXRplipaseXfr6xErCreeSlUBZpGudPiZlHgFkQFLra4LsBV_dJ3PEXjXOPxdIS4uAGpkV-Yzm36MxHpKz-z8byA0jm4UDqnL1zz9TRPSrrkJFVA" /></strike></div><div><strike>Now you will see the areas of negative population density change in white. <img src="https://lh4.googleusercontent.com/6-h9-EERdiVy4KI4sT5PhIXd-DjOVq_E4vuYg3oxLG2GKQ2-eWQcW1eFR9G3cD4YB5mxBE4w5iTsq4bnXsDlZXrQBk4hW2oglnVJBEidWuf5XGsRtho" /></strike><br /><strike><br /></strike></div><div><strike>Hope this tutorial gave you an insight into how raster analysis works and styling options available in QGIS to display rasters.</strike></div></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com3tag:blogger.com,1999:blog-8478705592464727054.post-54522415646818790272012-10-08T09:21:00.000+05:302014-05-16T12:54:00.248+05:30Tutorial: Using the Quantum GIS Browser<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc;"><span style="font-size: large;">Tutorial updated and moved to</span></span><br /><a href="http://www.qgistutorials.com/en/docs/using_qgis_browser.html" style="background-color: #f4cccc;"><span style="font-size: large;">http://www.qgistutorials.com/en/docs/using_qgis_browser.html</span></a><br /><strike><br /></strike><strike>QGIS 1.8 introduced a new standalone application called ‘Quantum GIS Browser’. This is a useful companion tool to QGIS and helpful in managing GIS datasets. ArcGIS users may think of it as an application similar to ArcCatalog. In this tutorial, I will cover some basic use cases of the QGIS Browser.</strike><br /><a name='more'></a><strike><br /></strike><div><strike>QGIS Browser is part of the standard install of QGIS.</strike><br /><strike><br /></strike><ul><li><strike>On windows, if you install QGIS via OSgeo4W installer, you will see ‘Quantum GIS Browser’ in your start menu.&nbsp;</strike></li><li><strike>On Mac, the application is located at QGIS.app/Contents/MacOS/bin/qbrowser.app . You can create a symlink to this app. Open the Finder icon that shows your computer architecture. Navigate to the Application folder, my location is under the Macintosh HD icon (wherever you installed QGIS). Right click the QGIS icon (this is while you are still using Finder). Click the 'Show Package Contents' button. Click the 'Contents' folder to open it. Click the 'MacOS' folder and open it. Click the 'bin' folder to open it. FInd the 'qbrowser' icon. Now right click the 'qbrowser' icon and choose 'Make Alias' for the list of choices. Drag this new 'qbrowser alias' to the applications folder. You can now access this from the applications folder! (Instructions by<a href="http://www.blogger.com/profile/07325388079679242156" target="_blank"> George L. Humphries</a> )</strike></li><li><strike>On linux, you can launch the browser by the command ‘qbrowser’. It is located in the same directory as the qgis application.</strike></li></ul></div><div><strike><br /></strike></div><div></div><strike><br /></strike><b id="internal-source-marker_0.5669550944585353" style="font-weight: normal;"><strike><img height="507px;" src="https://lh3.googleusercontent.com/t5qPp59vfz_KkzwDIPiYBQKRPFfGtqAT6R7AqDkllwSFdPZCLmk05dh5BareNgIiVbO_Mhrl-IaXBnWV0o9MrNSLfEVyGkVGobpHdIL_1oNRUbV1nQo" width="730px;" /></strike></b><br /><strike>Another convenient way to use QGIS Browser is via the main QGIS Desktop application itself. Open QGIS. Turn on the checkbox from View → Panels → Browser.</strike><br /><div><strike><br /></strike><strike><img height="438" src="https://lh3.googleusercontent.com/cQjNO2ESuk41VzwPN4AYYEQJtMV5CTnrP5CLJK-cTSQUlVL4e-KhEx7IYExUNVaTGT_q0PlIp5T6WxqgpwTi4F6CkqreEFqga5IdLdFf8xbhLy3wBEc" width="640" /></strike></div><div><strike><br /></strike><strike>You will see a new panel within the QGIS window. This is the embedded QGIS Browser with similar functionality as the standalone application.</strike></div><div><strike><br /></strike></div><div><strike><img src="https://lh3.googleusercontent.com/OkIj3_NPWElFRp4RbFr-XnXwAUajmxF5W6tfeN1gI_9nZ77qwfEinfqZ4C52O3cx1LrC7xSKnkUUS14LdfNEX_buObfKxZ_SzwfLumcpGWqKuD-2rLM" /></strike></div><div><strike>You can even drag the panel out of the sidebar so you have more space for your layers in the TOC.</strike></div><div><strike><img src="https://lh6.googleusercontent.com/ez189rCZbuK4_vJ8-xMIgb4Sa9VBYz6gUtkiFf192fGTUr9pEahnupydJ8iWnE469AXlpPVEjr3a8HON-LP2cIHBeeMWXDWsnB6Oh7bqGcOoRlbVu3Q" /></strike><br /><strike>Now let us explore some features of the QGIS Browser. Switch to the standalone QGIS Browser application. Browse to a directory on your system where you have some GIS data. You will immediately notice the advantage of using the Browser. Instead of seeing all support files and non-spatial data, you see only the spatial layers that are supported by QGIS. Click on a layer to select it.<img src="https://lh6.googleusercontent.com/ZwHN1n_XBioL7eGPkExxacK6xtPlaZFtdqtnGkw68fVXE20l4PX-ljL_di5jn50aG0E1I4J0CIRm0_8tHgCniFnZDcyaUlGGGd8H1m8posrQgtq9RlA" /></strike><br /><strike>As you select a layer, you will see the Metadata in the first tab on the right-hand panel. You can quickly gather basic information about the dataset from this panel, such as number of features, projection etc.<img src="https://lh6.googleusercontent.com/MHdi3MvuDdFZEE3FbsEfXVkcPLtibyNW8QdiTSlY-GnTO4dius2o31qYDv5d9FHq6HPMf7wZuhh6LetOpIxxDOgIVbqwBe-ognCH391nWGbit67dwEU" /></strike><br /><strike>If you switch to the Preview tab, you will a preview of the dataset. This is a quick way to determine how the dataset looks before opening it in QGIS.</strike><br /><strike><img src="https://lh5.googleusercontent.com/AH6A3JVOK88Esvn9dzqo-yaiS5DdB2OWqVpAlSHewXWBOrw-Cet7ea2ut5lyz1c1ttxv8tJtb_QNwFcQ_9lxGVwKlRdJAVyvviKIXDEf3oYqbwaP95g" /></strike><br /><strike>The last tab is the Attributes tab. Here you can see the attribute table of the dataset to get an idea of the fields available and their values.<img src="https://lh5.googleusercontent.com/L2fLdOiKNhsKy01PrUhUVgtjIJnBC2LNJE3r08R6F5bU0d2QmZnkOKhhc3RRY55gQx2OeVjx1aj0mzqDVnq6ykap5BGKu5D9BzuDBu84VgbvlsuZfSw" /></strike><br /><strike>The QGIS Browser not only gives you access to vector and imagery layers on your system, but also databases and network resources. If you use any <a href="http://qgis.spatialthoughts.com/2012/05/tutorial-using-online-data-via-wms-in.html">online data via WMS</a>, you can quickly preview it within the browser. Just expand the WMS location and you will see the resources you have setup. Similarly, if you have PostGIS, SpatialLite or MSSQL databases available, you can access those as well.<img src="https://lh3.googleusercontent.com/gDNiaG__pcbiz0WR9Clkspqpkzp4gNWQRdVi3Nb4Hyqx5oBrcaCkaMqJEtfBwwuy9FR2Y7S5Oae38JiIdNdXH6YDf5uR2ZfvlrVDinJ-F0KdcyGP7V8" style="cursor: move;" /></strike><br /><strike><br /></strike><strike>One of my favorite features of the Browser is the ability to browse and open zip files directly. See <a href="http://qgistips.spatialthoughts.com/2012/10/tip-opening-zip-files-directly-in-qgis.html" target="_blank">this tip</a> to enable this feature. Now open QGIS Browser. Navigate to any folder containing zip files. You will see that the zip files appear as a supported dataset now and you can preview it just like any other dataset.&nbsp;Now open QGIS Browser. Navigate to any folder containing zip files. You will see that the zip files appear as a supported dataset now and you can preview it just like any other dataset.<img src="https://lh3.googleusercontent.com/qawCgKCycKOoHMXrRUMPk0pX-8ozRbgjvSLPeSmAw-NrvfMW9JcufqgbUX8ernC9rKukOne3S-3vPlPgiY6go8KCy39GA27N0lGL_gZXLFpomJSifMY" /></strike><br /><strike>Another useful feature is to add certain folders in your system as Favorites. You can right click any folder and select ‘Add as a favorite’. ( Note: this feature currently works only from the Browser panel in QGIS, not the standalone application )<img src="https://lh4.googleusercontent.com/lGmTYGuKoxaePczitwamVyEPvx7xs1tesA0bLX3FharY2lR453tzqZpkoAoJDYmsDY_RRB2qnYH362v-nbOtpDxjFDA8PQKlaX0QuC-eaRMdqbCeTu8" /></strike><br /><strike>Open QGIS and if you expand ‘Favorites’ within the Browser panel, you will see a list of your favorite locations. This can save time by giving you fast access to most commonly used locations.<img src="https://lh6.googleusercontent.com/btt5eLMMgWNKx9DcinAKik1jizIppaiQjduPwI8_UeLjcLj-5XYwX4iuZkpTLDQbQtnv98lzvr4-exNRuHEMdhWEETDL9PJzIEkgG3LeUSlZq7jZAIE" /></strike><br /><strike>From the Browser panel, you can double-click any layer or use drag-and-drop to load that dataset into QGIS.<img src="https://lh6.googleusercontent.com/ljzNFuiGZUq4xPPyTu-2zcTItHo9B7D2QAi4Tabdi0MWlTdfw6IWHHD2dvJYElzi3Eh8WA7lnpEvY-HA3Mj8Dv31y6-3pOBsp21tVRl2Bfw4lH77xk4" /></strike><br /><strike>You can also drag-and-drop the layer from the QGIS Browser standalone application to the QGIS Desktop application.<img src="https://lh5.googleusercontent.com/wwYzsPw2H8rYFaiuIGHICqJpXWOQ4oSKSqghxWbC6Q13Ydog6TYmQU3D37wV_diJX8StCT97s1lmHEHR_2qWK_9YrVZA-IaSXKRW7YKDbDkX-fwBMJI" /></strike><br /><strike>Hope this tutorial gives you an overview of the functionality of the QGIS Browser. Let me know in the comments how you use the Browser to simplify your workflow.</strike></div></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com7tag:blogger.com,1999:blog-8478705592464727054.post-37517021805692296942012-07-14T20:26:00.001+05:302014-04-07T21:15:00.114+05:30Tutorial: Making Heatmaps using QGIS and GRASS<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc;"><span style="font-size: large;"><span style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;">Tutorial has moved to&nbsp;</span><span style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><a href="http://www.qgistutorials.com/en/docs/creating_heatmaps.html">http://www.qgistutorials.com/en/docs/creating_heatmaps.html</a></span></span></span><br /><strike><br /></strike><strike>Heatmaps are one of the best visualization tools for dense point data. Heatmaps are used to easily identify find clusters where there is a high concentration of activity. In this tutorial we will explore two different method of creating heatmaps in QGIS and work with crime related data to find crime hotspots with cluster analysis.</strike><br /><a name='more'></a><strike>QGIS 1.8 introduced a ‘Heatmap’ plugin which allows you to create heatmaps directly from QGIS. Prior to that, one could use variety of GRASS algorithms via the GRASS plugin in QGIS to create the heatmap. We will use both these methods and obtain the heatmap. The data for this tutorial comes from <a href="http://data.london.gov.uk/datastore/package/policeuk-crime-data">London datastore</a> . There is a wealth of open data available and for this tutorial I downloaded the <a href="http://data.london.gov.uk/datafiles/crime-community-safety/police-uk-crime-data-surrey.zip">2011 Crime data for Surrey</a>. </strike><br /><strike><br /></strike><h3><strike>Part 1: Heatmap Plugin</strike></h3><div><i><strike>Note that the plugin method is experimental and can be slow/unstable at times. If you are working with a large dataset or scientific analysis, GRASS method outlined in Part 2 is recommended. But the plugin method is simpler and suited for quick visualiaztions.</strike></i><br /><ul><li><strike><span style="background-color: white;">To start, unzip the data to a folder. The data is in a CSV format. Use the steps outlined in </span><a href="http://qgis.spatialthoughts.com/2012/01/importing-spreadsheets-or-csv-files-to.html" style="background-color: white;">this tutorial</a><span style="background-color: white;"> to import CSV data to QGIS. You have to specify Northing’ as X and ‘Easting’ as Y fields. The CRS for this data is OSGB 1936 British National Grid.</span><img src="https://lh6.googleusercontent.com/ERB2WX_8sMRB4uJWdGkKM_RPWAPj2uTlTyytlAcuqTk_Lcepkl3C60Q5YcNeuiJFNTVmcGQdg6-PVIUUxrQd9-He66-JtwYBR9mJlqxfDnbL7vYe51M" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Save the layer as a shapefile so it is easier to reuse without importing again. Right click on the layer and select ‘Save As’.</span><img src="https://lh3.googleusercontent.com/7dEfSnEpa3a_tJz3h8IDMuQsu4OQ2H2Gpu-F16zguD7CWpCqs2mXywZhr4NYjlXnVmcBX5F1PwQeJrNqiYdWK9w1qC8eC2h2FufRe5_8TGGEBn38LU4" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Name the shapefile as crime.shp. Check the box next to ‘Add saved file to map’ and click OK.</span><img src="https://lh3.googleusercontent.com/1wwd5I9mJYzHzWnvholLUnoHIlTE85veBnCFMe-pm13I2gaStB5k7oVzCZMpPGeBk94M2Vy5Frl64zRV3uB-1aq3aAfSSWFY475cy4JgUYUXSfBFQRA" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">The new vector ;ayer will be added to the table of content. Remove the older imported layer by right clicking and selecting ‘Remove’.</span><img src="https://lh6.googleusercontent.com/oBZKqHSmEhoalKB1P-vh5CZsfQAYL9k8HeQzapvXy1GGEo1TNPNKIUb6xLW31_y4SZDJTPT7FUnj1reMvH3Uw_2U1RH57cxP-9sCp7t9jOt_wPC85LM" style="background-color: white;" /></strike></li><li><span style="background-color: white;"><strike>To use the heapmap plugin, we must enable it first. Click on Plugins → Manage Plugins. Scroll down and make sure the box next to ‘Heatmap’ is checked.&nbsp;</strike></span></li></ul><div><strike><img src="https://lh5.googleusercontent.com/tXi1KEg0xb-FChX7OROx6nZ-JwQ9PrLm3jSD6_TjaDXGqrfQeD4MsnPDpmIZhUdgXXbjuNMGrLUQJUbWJvgtKnst641t5igqZR0p0TjRFgmXX29kdLQ" style="background-color: white;" /></strike></div><ul><li><strike><span style="background-color: white;">Open the Heatmap plugin by going to Raster → Heatmap → Heatmap</span><img src="https://lh4.googleusercontent.com/WCtm_unOe7DWpBpua8O5qHp9Fk6ncu-2LybUfAeEud8kFaCmzOEX9iZZpM4Sq4iHJfbu2yTY0dG0FGfc8zi-Ks36xNFYQZxWLd4wydiwWLHN38Rzyns" style="background-color: white;" /></strike></li><li><span style="background-color: white;"><strike>In the Heatmap plugin dialog the crime layer would be selected as the Input Point Vector. Name the output raster as crime_heatmap. The Radius is the area around each point that will be used to calculate the ‘heat’ a pixel received. The Decay ratio is how far a point will influence other pixels. Clicking on ‘Help’ will bring up a more detailed explanation of the algorithm. For our analysis we would like to have a pixel’s value determined by how many points are within 1 km (1000m) of the location, so we select the radius at 1000 and Decay Ratio as 0. Also set the pixel resolution of the output raster to be 100. Click OK.</strike></span></li></ul><div><strike><img src="https://lh3.googleusercontent.com/i1TED6Sgxlj7NfaT5A6wwkoYmyGuEru8Bqpg1C3pEEHfSgTP-l7-rvnzlOX3mArKvbAQ9PGqnNoKnDvVdeHgajYrq-3Tqu0hvCS1F2D-ofNFWtGU3mk" style="background-color: white;" /></strike></div><ul><li><strike><span style="background-color: white;">We have more than 100,000 points in our layer, so the heatmap processing map take a while. ( In my case about 30 minutes ). Once the heatmap raster is created, you will get a prompt to select the CRS. Select OSGB 1936 British National Grid and click OK.</span><img src="https://lh3.googleusercontent.com/m_g_bOWLMNGe4LAUPJTF-66g2v3u5S1a4p9sV1qTEEQSXiqHhfpGadRHZtL1VJ52CZuaSqV_HtG2aXxWK6LlWiLN6Ja0FLzIEEoTmF62uKl6Q-kkIBQ" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">You will see a gray rectangle covering your layer extents. This is the heatmap raster, but it doesn’t have any styles applied to it.</span><img src="https://lh5.googleusercontent.com/9utIn7MvOAH8X1hYbIf9UTd13aYlRvRosJekiQfkPUBkPFh-xKW7HEk2PFunTol05uZVZx62oYY65FraCTW0XzFdlSDT5GYqqVeISEsPLkdFi-EW2y4" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Right click on the crime_heatmap layer and select Properties.</span><img src="https://lh4.googleusercontent.com/lcMjGvyb4Ge9ySxyPVdSgxApv04DwQZPQhQ_O_02-pS4r9Sy9MjSTLq__nKrJ2bl4cxKY8pZjbfPilrBnDlKpDr6mRBidLmMgDKwNYPHYFpCo3mC_YY" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Under the ‘Style’ tab, select the Pseudocolor as the Color map and click OK.</span><img src="https://lh4.googleusercontent.com/RBcxkHWbRuTUi73_VlfWc6T07jW7Jzsq5HOQ3dBfBY9f1jbhtZkIKEqFm-VlGJ3Tu3g674M0fCGp0DrWy-4FN4GxORS_UZR6CGKDfRjuD4miDi_sQMQ" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Now you will see something resembling a heatmap.</span><img src="https://lh5.googleusercontent.com/tCV_xKxLjshLwzLo61lPKyy-iHW5hYndq4721dyG4kuohLc8F7byIaXsR4cz-xuv23uiuWNJG4Si3WFNB5P_PhDeGCwH5iFeY8vKcNGj_S1cvs7Wckk" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Zoom in closer to the area where the points are. Click on the ‘Identify Features’ to activate the Identify tool. Click anywhere on the raster. You will see the Identify Results dialog pop up with the value of the pixel at that location. This value represents the total number of points in the 1000 pixel radius that we had specified.</span><img src="https://lh5.googleusercontent.com/Fq0kBLetNqVTry4tfRHFPJXhNBAUH5JH2hWJapwt_1KZ3u9TJxOaiaVzur1xpcMUZh4t6BZ4lLQI7Qmqa4wmda6BMKiZmL2R7yYqUD6ZZ2KT_xNq5Gk" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Let’s do some styling adjustments to view our heatmap better. Right click on the crime_heatmap layer and select ‘Properties’. In the ‘Transparency’ tab, move the slider for Global transparency to 20%. We also want to make the pixels with 0 values transperant, so click ‘Add Values Manually’ next to the Transparent pixel list. Add the value 0 to the list. Click OK.</span><img src="https://lh6.googleusercontent.com/f_0DbAC1rpWAoLMCbeHDqG4LMUinXk7gIORHn6CQ8Bszp4MU3RVLyxym_-5IF-iZU3DX59UZfxUNlb8eIvSJ8Qaox_nHslV-DeHaB2UL-n3c-hYbmTI" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">You will now see the underlying points along with the heatmap. </span><img src="https://lh6.googleusercontent.com/iwY_pcLdK1LsGAmUK9GNEozCz9u9I8iGEIfIOMkdo0eBHVhCa1trByaDSkkNJqAK8BEiawOjM9pwoZKtayqZkF9_1UOPqq-BYzmqjRJjtKMapdx7zT8" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Now let’s identify clusters of ‘crime hotspots’. Say you wanted to identify areas with high crime concentration and deploy more patrol there. Or we may want to use these clusters in some further analysis. We will use Raster Calculator to identify these clusters. Click on Raster → Raster calculator.</span><img src="https://lh5.googleusercontent.com/eIsw8S28ybw7zM1KHgN91f4UA0lwqQj1OcLDQq5beSEOukZzjzn9ojeatWA_1ZN5BESy7lxbGObPnR9G3X2l1qvT8rs2KhMk-VcxAhPL8v3NLPTQvJ0" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">You will have to decide on a threshold value. For our example, we will use 100 as a threshold to identify what is a ‘cluster’ and what is not. In Raster calculator dialog, name the output layer as crime_heatmap_100 and check the box next to ‘Add result to project’. Input the expression crime_heatmap@1 &gt;= 100. What this means is that all pixels will values below 100 will be assigned a value of 0 and all other pixels a value of 1. Click OK.</span><img src="https://lh6.googleusercontent.com/Kb6qis3fxov5aL_g4YtwoqboDFrOAJwx9LL0UFm_jfn4EW7Vt2BqFincxjZLF_5sbnX7JpluLMEYBTM76w2Icn4YS024tuUaZFICZ5ZZ71b65EtW4yA" style="background-color: white;" /></strike></li><li><span style="background-color: white;"><strike>You will see a gray raster like earlier. Right click on the new layer and click ‘Properties’. Select ‘Stretch to MinMax under contrast enhancement and click OK.</strike></span></li></ul><div><strike><img src="https://lh5.googleusercontent.com/Xn6JMW-OO_XsokMWsJxAx9gHbiMOuTAdcHKVpcCrIb5SVRXH8yQsS-Gi1tG4L6bw2NQVWEprpGR6dyFycK692M-hkB6NI8IqZSlYddERV7OqgjCO7og" style="background-color: white;" /></strike></div><ul><li><strike><span style="background-color: white;">Now you will be able to see clusters in white pixels. We will convert these to vectors. Click on Raster → Conversion → Polygonize. ( Enable GdalTools plugin if you do not see this menu ).</span><img src="https://lh6.googleusercontent.com/V4UwhOMI4kKZPZoBGmo4AGTDyP0GcpX4L5J_UpxejNXfl11GicKNVENaPLx6EXe1xdTscmhcKDSdT0NqfGAu3opc5AN55GcZUZ8c3eg4J6Mc96d4Ugo" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Select crime_heatmap_100 as the input file. Name the output file as crime_clusters.shp. Check the box next to ‘Load into canvas when finished’ and click OK.</span><img src="https://lh5.googleusercontent.com/axaVFMv2MCYwdDunvtOHc_YzLOn9oayhwMotp_wCtg5pDVLEz-7b8TTWI_MIMh2d67CqiNvhR2W0q9l48e3TjXX8wRRn1FftJVlAp4f243WfBbnQo4o" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">You will see the vector polygons from the crime_clusters layer. You will also notice that this layer contains polygons for 0 value areas also. We will need to remove these to get a layer with our clusters. Right click on the layer and select ‘Open Attribute Table’.</span><img src="https://lh4.googleusercontent.com/coagGQU9VW0K4G6pTGS5skBH8RnSJvn2wLyrG4Dr-5-UAXAqPRVv_CM-1DfhzObiJqvwJlWcBJb98iTt5sVD-u5a6kGGI3HkQtOumZOJHaRAynZLnNw" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Click ‘Advanced Search’ at the bottom of the Attribute Table.</span><img src="https://lh4.googleusercontent.com/twSlpTQuX7qDpLDoBnkHlLj2tMeJGjX74QqTGkjZzlOLeAVsBGRIWFxtIF2thJGqP9hWKCs_qpQ2xWNsx6rFoHUW6TlxBbgbf_H8tR9PNFd_TlOcFK8" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Enter the expression ‘DN = 0’ and click OK.</span><img src="https://lh3.googleusercontent.com/XkPxx5k-32s27wUFH7GDqiuv09PZMmVED-8Efch_j5QYyfoSSfQUd6es9Non-083a1atidGKTtNQUKlYHGtpEMnOQC2DIF8KZDUk8Is7BgpfhWHLAA4" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">You will see the polygons with 0 values will be selected. Click ‘Toggle Editing’ button at the bottom. Once editing is enabled click ‘Delete Selected Features’ button. Click ‘Toggle Editing’ again and Save.</span><img src="https://lh6.googleusercontent.com/HLziZwCgsT2fMomOcv9qnc8BjEUwJKFKdSvOecTC2CCtCbClBHfSaP9L7knI_FCg92LwP8zRs6Exrqjarpn6_0ZYI2D2zp7NN8C3KLeTak8QFiVV14s" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Go back to the main QGIS canvas and you will see the polygon layer for your clusters. You can now use this polygon layer in your further analysis.</span><img src="https://lh5.googleusercontent.com/cdub4WuVFYEQf8ypJpUj9MnQNzQJ4hcajMnP21AN3IjlhRMzmIy_1KUkEUKLQ64-CXIDR6puseTaDafYvNME6y7N0Eyou_DjT0MQJoGPFwx_RiXHhUc" style="background-color: white;" /></strike></li></ul><h3><strike>Part 2: GRASS v.kernel module</strike></h3><ul><li><span style="background-color: white;"><strike>The region setting that we want change is the Resolution. This setting will determine the size and resolution of our heatmap. To match the setting with the previous method, put 100 as the Cell width and height. Click OK.</strike></span></li></ul><div><strike><img src="https://lh4.googleusercontent.com/9UU48aA3a_GMRC8r3LQUIc32qoTMmHZITNYWvDyeLn5tVE9PjDoxa-ZHEGfROV9Ix5j-0tTbxwuL9ahKteMwtRrRjYNESrkPgEEbUypCqicZmx7A66I" style="background-color: white;" /></strike></div><ul><li><strike><span style="background-color: white;">Now let us get to the second method using GRASS. GRASS is another plugin that is built in and has powerful analytical capability. I will quickly go through setting up a location and mapset in GRASS. You can refer to </span><a href="http://qgis.spatialthoughts.com/2012/01/setting-up-working-grass-environment-in.html" style="background-color: white;">this tutorial</a><span style="background-color: white;"> for more details on what they mean. Click on Plugins → GRASS → New mapset.</span></strike></li></ul><div><strike><img src="https://lh6.googleusercontent.com/kOIgxV8jlwIErfMhBK0EC3xF4TDvaDIWH3cH1eji1lECjrfR2G6WjJ0RE-7WXlZ9-vKH7AbpNDjQuD0E3tcQbotBG_j3yRvCoJvYYyRNdBZu33JzieI" style="background-color: white;" /></strike></div><ul><li><span style="background-color: white;"><strike>Select a Database directory and click Next.</strike></span></li></ul><div><strike><img src="https://lh6.googleusercontent.com/REmh1T8EbYQo_-3Q62VaRl96dkaKiU-YOGEatArukfY2a3tAf_XzazRNWNSDwf_YsJKO9feIN8UXMxXno4Sox8WDvmIvO_Qe6WTl_bw4Cpye3_cbA1g" style="background-color: white;" /></strike></div><ul><li><span style="background-color: white;"><strike>Select ‘Create new location’ and name it ‘uk’.</strike></span></li></ul><div><strike><img src="https://lh5.googleusercontent.com/XfnvQcbidojKUWoWVItUPRBWav1Sh5CiqPF0RaTVBDlLKBtHkBEtN4epX-5IiZ4FoajW_V3LOvCXz29-QcoyVKW-h2QgvIWfPDdvW9_aLzcTeqRq6EU" style="background-color: white;" /></strike></div><ul><li><span style="background-color: white;"><strike>Define the projection as OSGB 1936 / British National Grid. Click Next.</strike></span></li></ul><div><strike><img src="https://lh4.googleusercontent.com/wU6N5GKuH4nqNCOfO45-QJ8s8MoJ66YxNPD6iNVV9UAcuVawQHnNGxY93P1A_MQgeywspcSxvhipFizCwjnJxJ20qHuGkoY0JopWtKsEJqPHWzpiReg" style="background-color: white;" /></strike></div><ul><li><span style="background-color: white;"><strike>For&nbsp;Default&nbsp;GRASS Region, click ‘Set current QGIS extent’. Click Next.</strike></span></li></ul><div><strike><img src="https://lh6.googleusercontent.com/JACO-Ood5GiqUsYlnfRJY8A0MLz1IpDcbIohXTRQe4e9E3r8lXSpRRjR64FniAZA2pM3xg5Whju5mqw3LJGFtr6AWv5Fww32Ozjs2TQ6-HhumG8ZoUg" style="background-color: white;" /></strike></div><ul><li><span style="background-color: white;"><strike>Enter the mapset name as ‘crime’. Click Next.</strike></span></li></ul><div><strike><img src="https://lh6.googleusercontent.com/WTgcAv8vaHdns72KqWNo80nk4Uj4D7uFKdLjUkrqEhp-2KMlWDxW05as9TXRGYQE5KzgfguFxIvq3ZY_Frpd_Qdeq0OK8QEl83t293LNo5eXT4z5iQI" style="background-color: white;" /></strike></div><ul><li><span style="background-color: white;"><strike>Now that you set an active mapset, many more GRASS menu items will be enabled. Click Plugins → GRASS → Edit Current Grass Region.&nbsp;</strike></span></li></ul><div><strike><img src="https://lh5.googleusercontent.com/lp10ZnmUdpsuFtzuqa580N-j4LkFl1TY1mU17iqnb6JUjO-d9su3IR5x_jdC-MFBrvjZqBYKH8n6Y89HgMiwNRK_tddgf_0dZPyv26BgVT27qgAXyC8" style="background-color: white;" /></strike></div><ul><li><strike><span style="background-color: white;">Now click on Plugins → GRASS → Open GRASS tools.</span><img src="https://lh6.googleusercontent.com/ZsVczj5Q-qN10tYV8l2q-7_7_3UIRt2FOs-zCQ0LtLMTvL_innlTuyXdxZMkt7Zvw_j62lXOfS21rmTjSK2QD9Y23-Z97G5a_Qqj2U_N_nKydzi9OZ8" style="background-color: white;" /></strike></li><li><span style="background-color: white;"><strike>There are hundreds of analytical modules in GRASS. They are organized in different sections. Click on the ‘Modules Tree’ tab and find the v.in.ogr.qgis module.</strike></span></li></ul><div><strike><img src="https://lh5.googleusercontent.com/KCoNBmpr2KdjrNzymsdhQECKgvIdfYgj56DSeyAtA2dnBmuzvxY2Gk8mH4BZ0z66yt35uNkeJSQXFaSnuYX_QasvA4cANxTqkrBwl_tK6ryrEvktKv8" style="background-color: white;" /></strike></div><ul><li><span style="background-color: white;"><strike>Select the ‘crime’ points layer as input and name the GRASS vector as ’crime’. Click Run. Once the import is finished, click ‘View Output’ to load the layer in QGIS canvas.</strike></span></li></ul><div><strike><img src="https://lh6.googleusercontent.com/VanjedX7sjKmhFBQUb48RP_h1vUd4MuZunYnnqsB_Sd-PLRxWVcB7OhsIupmsodmtjgjhJd1BxDlJyLLjm52pJPNJwfrm-jA42mYmiFx2uC0PYni8Hg" style="background-color: white;" /></strike></div><ul><li><span style="background-color: white;"><strike>Open the GRASS tools again and find the module v.kernel.</strike></span></li></ul><div><strike><img src="https://lh3.googleusercontent.com/uJjmzC92Wxwvm6uUH23PrDzsc2Ug_w6rip6imEuYqlvrBARbZTRYgElWPLxuo9sMD-ewfM6FUIN0g2ENOU9hCR4j5yLsmY0ktiP5qvstv-Goc0o6TOo" style="background-color: white;" /></strike></div><ul><li><span style="background-color: white;"><strike>Select the crime layer as input vector and enter 1000 as the Standard deviation. Name the output raster map as crime_heatmap_grass. Click Run. ( A bug in QGIS 1.8 prevents this module from running correctly. This will be fixed in later versions, but if you encounter an error, follow the alternate method below )</strike></span></li></ul><div><strike><img src="https://lh3.googleusercontent.com/mrW_3jkxejxxBKUS1dAyigDBPAWWc2jF3W1-EcIFO-mT10CFt-t6pHNHE6fRLFGKxDEJTzByKSoOhU9ugdaLJULvpwqMWDOQpcjY55oCq77IliSEzSI" style="background-color: white;" /></strike></div><ul><li><strike><span style="background-color: white;">From the GRASS tools, select shell from the top.</span><img src="https://lh5.googleusercontent.com/qK51cuvRizhP3Uj7Ye8kwYmnaAmpt0BSyiCSi05ivY3NtZvcwwGnXOlaiNNSoZLVJAmtP__ZiMmDlZXV3bIC9Y0XoYqZFueFwg4rijfrSbt1evH27Fw" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">This will open a windows commandline interface with relevant variables already set. Type v.kernel and press Enter. This will launch the native GRASS interface for the module.</span><img src="https://lh5.googleusercontent.com/FictMaNNYui-uSxS7awtlw3ouub1kymCDYNozrDPy1zYcgV8BnHEpUaZZ2fiFpqhZNGKiZYtMcQG6LvEqOabBagwmMgQlsUwPgp1DEwF1kZWZ6yfLvM" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Enter the same values and click Run.</span><img src="https://lh4.googleusercontent.com/52RllSxEhUN2nD0lFruB0TBKHma7SwbcT5f0e25mnbdACs17gBfHTosd3NcgsWFcEsqVDuh0Jw95st-DDnOglyvPAPAR6q_MTY2q8VLNWyKTeOWDuCo" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Once the processing is finished, click Plugins → GRASS → Add GRASS raster layer.</span><img src="https://lh5.googleusercontent.com/ufND3wlquJ0JqpX4BQKIrlyxvmzPtBQVyp7rhHnDIfCigZqLPW-jboDtBL833KY5GAADKntMryuIP---5yMT-SuE6lpXPVlkQPX4oIqnL7vHlb2xxB8" style="background-color: white;" /></strike></li><li><span style="background-color: white;"><strike>Select the crime_heatmap_grass layer and click OK.</strike></span></li></ul><div><strike><img src="https://lh6.googleusercontent.com/Fc06ITxNjJy18UcxB78fCUjAwTsv9MyLlwUG0yucXV_ITc3XQogS0ltAlrms-MSLxBUg-pXKC-mjFjiWDvrTQl-dtOBH1a7AJ3hT2Pe_mSgIboGzmnU" /></strike></div><ul><li><strike><span style="background-color: white;">You will see a grayscale heatmap. Right click and select ‘Properties’.</span><img src="https://lh5.googleusercontent.com/2bl_U7r2lmrIwOGVwyzFfXjIF4HRY9uMJ1DXpdhGwzIPhqlNS-gXl4KTEqb9JSVDvgluHDcZml3JexxulSzOKNtU3pTgqi0y7KBMSBlFcBdRC7TPgf0" style="background-color: white;" /></strike></li><li><strike><span style="background-color: white;">Select ‘Pseudocolor’ as the Colormap and click OK. Now the raster will be styled in a familiar heatmap style. You can export this raster from GRASS to any format you like and use it further in your analysis.</span><img src="https://lh3.googleusercontent.com/yeTeB3U2IF8j3r6ZXygfCmh4xGB0NTjFVrPBSiZZdo2S-BHb1yHxVOK4dNNVCUjYnYjYJuofQvCkPibxaCi99kd0-VngGAZvY-_Uc6PQM3Rjy1qH9cA" style="background-color: white;" /></strike></li></ul></div></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com20tag:blogger.com,1999:blog-8478705592464727054.post-75166350496714341432012-06-20T09:30:00.000+05:302014-04-07T21:12:10.862+05:30Tutorial: Making Maps for Print Using QGIS<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc;"><span style="font-size: large;">Tutorial has moved to&nbsp;</span><span style="font-size: large;"><a href="http://www.qgistutorials.com/en/docs/making_a_map.html">http://www.qgistutorials.com/en/docs/making_a_map.html</a></span></span><br /><strike><br /></strike><strike>Often one needs to create a map that can be printed or published. QGIS has a powerful tool called Print Composer that allows you to take your GIS layers and package them to create maps. Print Composer is quite feature rich, but can be un-intuitive at times. In this tutorial, we will go over various options within Print Composers that allow you to create informative maps with elements like north arrow, scale bar, legend and labels.</strike><br /><a name='more'></a><strike>In this tutorial, we will use the <a href="http://www.naturalearthdata.com/">Natural Earth</a> dataset - specifically the <a href="http://www.naturalearthdata.com/downloads/">Natural Earth Quick Start Kit</a> that comes with beautifully styled global layers that can be loaded directly to QGIS.</strike><br /><strike><br /></strike><ul style="text-align: left;"><li><strike><span style="background-color: white;">Download and extract the Natural Earth Quick Start Kit data. Open QGIS. Click on File → Open Project.</span><img src="https://lh4.googleusercontent.com/0P04rkjNqeD-W6mLUCa1z_545IUmUEvZIxkX6ETOML9ouVXDADlLbraf0Rg090Zvn35DS77qGXIdGcBsJ1KI5irN-_Gz7GSxSUBEKW3w5vrX65C6Tlg" /></strike></li><li><strike><span style="background-color: white;">Browse to the directory when you had extracted the natural earth data. You should see a file named Natural_Earth_quick_start_for_QGIS.qgs . This is the project file that contains styled layers in QGIS Document format. Click Open.</span><img src="https://lh4.googleusercontent.com/eiol089OaUiXOVshaushxtbTWlHHzP98j7sEYZwLrDaIpRatYOCxYyuwtD4qCSe277JraTRfxFSsJ5a7nAuj-L6_lMM4VB7NXS9Hskqcl_y35m4C87k" /></strike></li><li><strike><span style="background-color: white;">You would see a lot of layers in the table of content and a styled world map in the QGIS canvas.</span><img src="https://lh6.googleusercontent.com/ZZ_Th6BXs2CtThZfYEzbcBttCdanv4ra_mxG-2yVQRR0gvHnon93L1oe-rgJsDn5CMxhvUxDzZILdo4SK93JDZBYmzbCa8Uzz3js1Ia6lAJmPUhyMCQ" /></strike></li><li><strike><span style="background-color: white;">In this tutorial, we will make a map of Japan. Click the Zoom In button and zoom to the area around Japan. Once you are centered around the area of interest, click on the ‘New Print Composer’ button. It is also accessible by File → New Print Composer.</span><img src="https://lh3.googleusercontent.com/rsn6GX-uBfHqdqY3XjVJkN0XujrMgxRtH2r6j7wsqApmWYvsXJhIJHgKcZ-aq7dISMA1WM9KoDt92G_CvO0hRUNoyydyoR-zUMCccxCaVgtejEsHNGo" /></strike></li><li><strike><span style="background-color: white;">A new Print Composer window will open. The Print Composer tool contains three main parts. A menu and toolbar on top which gives you access to various map elements and controls. The main area has a blank canvas where you would be composing the map. On the right side, there is a panel with two tabs: Composition and Item Properties. </span><img src="https://lh6.googleusercontent.com/ScM1JV6MfD2nOg19l1b7f9G0JftzV5mK0ssWXw-U6eoW7nnHlRFRjEs_he3IMe0qLrWgEfDo7GNn2AOQHN32QsPA7Bfuw7reqfT2XreAhNvIqPqfRrA" /></strike></li><li><strike><span style="background-color: white;">In the Composition tab on the right-hand panel, you will see the Paper and Snapping options. Leave those to default for now. Click on the ‘Add new map’ button.</span><img src="https://lh5.googleusercontent.com/BGRHXMSd_JqrloB3bbfnAq222Bd_VuE_crLSDs22cWg804HfednpuQ_HQoj-hmt_e_ebOiCNcvsQ4_2XTkEhQAQZeaRnxbKYXq4pUSN0ZpEGgJ8z-4Q" /></strike></li><li><strike><span style="background-color: white;">Hold the left mouse button and drag a rectangle where you want to insert the map. </span><img src="https://lh6.googleusercontent.com/VsM2c8JZ-PoD0sLzZcFl5FsmpbSufcpXeyo6Z8KqFoYbhojcvW11SK04_jjSla5SiC0OzBhKkB3tF9UOci7PV8ZfF9dZHnuMV4a9qI_VaQtuZ01pwXk" /></strike></li><li><strike><span style="background-color: white;">You will see that the rectangle window will be rendered with the map from the main QGIS canvas. Since we want our map to be covering the full extent of the paper, drag the corners of the rectangle to the edges of the paper.</span><img src="https://lh4.googleusercontent.com/cdhfFyFo0RwzHPznNQO0cvkszElXC7F1SQ1UACJmc09mbcHZg6iUoowFyfLoJERx8UNeTDTUpIAttTXnW12bVReFXXIUsEsb5DtFlSdUJwli1FxqQLw" /></strike></li><li><strike><span style="background-color: white;">Now let’s adjust the zoom level and center the map. Click on Layout → Move Content. Click inside the box and drag the map till it is centered.</span><img src="https://lh5.googleusercontent.com/yaztWgUyO-s81RdW7Hbe4tSOilhKp9p4Kwo-GfHRoWVN3bC87jaK9Y9nWb0OCpVwAtsrdKkF-xZhu-4bTFNNRgnsR_VYXDOi7nUUrn8bFLz3O1GcS6Q" /></strike></li><li><strike><span style="background-color: white;">To zoom in, you can use the mouse scroll-wheel. If you do not have a mouse or want more control, click on the Item Properties tab and adjust the Scale value.</span><img src="https://lh3.googleusercontent.com/R8H7kAHlgY8t69JGZmVI5_KOd2sWNlbMOVPczASxqzNQGLLZ-8fXIE1VCwMappFmrlKnNodHNnfrr4GHwgy2oaLJ0urZoleAQnqmZbaD523Ao7Bke_k" /></strike></li><li><strike><span style="background-color: white;">Now we will add a North Arrow to the map. Print Composer comes with a nice collection of map-related images - including many types of North Arrows. Click Layout → Add Image.</span><img src="https://lh4.googleusercontent.com/zFOSD7zo3sMvkEWPZLd1-NWnygxCuK7tV0a5VRnLnPZp0yR8akiD9-oNMxmDbCrbquzrLsQj45Y7B6fQi6wa7Kp7-Ghw-camzkQe97qhDNMLO8-kOTw" /></strike></li><li><strike><span style="background-color: white;">Holding your left mouse button, draw a rectangle on the top-right corner of the map canvas. Click on the Item Properties tab and select the North Arrow image of your liking. Next, click on the ‘General Options’ tab at the bottom.</span><img src="https://lh4.googleusercontent.com/UMymgNB3tHNZ7XFQ4pZNtLFij7sLnsiYBok6XzQiGx-q6LMdutfg51bM-hZSPCD3XIaWOBcP-J2-OpA-g_IekucjtdUH6bVNmWK0tzwA6OzwYG9apbk" /></strike></li><li><strike><span style="background-color: white;">The ‘General Options’ tab has options for controlling the color, size etc. Move the Opacity slider all the way to the left to make our image transparent. Also uncheck the ‘Show frame’ label to remove the border.</span><img src="https://lh5.googleusercontent.com/8rWQMJPCtrKL2ABWTYRB0maAIDRgpkkIMgMFO5uUEwAY2fbFxAht_fqtPWGDopKrKRtxBKiWw5JbZt_UMHhd4jp9dGIy8R7YQT6FsrmrsbZa9rfDWoo" /></strike></li><li><strike><span style="background-color: white;">Now we will add a scale bar. Click on Layout → Add Scalebar.</span><img src="https://lh6.googleusercontent.com/ujgCrDucrED63qcCDvBudSwxLUFH1hwbpEjLy6lFuWZ0QPNI56b8IoklhaBFqST3Q2hlf85qTf2XZpRQdGkPuHG38LmJQtazLpIaEyqGEibyPJc9lJ0" /></strike></li><li><strike><span style="background-color: white;">From the Item Properties tab, choose the Style that fit your requirement. You should also set the transparency via General Options like in the previous step.</span><img src="https://lh5.googleusercontent.com/-tV9SX9Y6KAcIiotAWzi9ru1dKtnAc7mo1QFTSizKQoJKuu_5VfZ17DbSf_txGjBFqkCQVnKuk2fp28OsuXid4gGYvjFD4v2i27yZDIDECkHZgxUHX4" /></strike></li><li><strike><span style="background-color: white;">Now we will add a legend to the map. Click on Layout → Add Legend.</span><img src="https://lh6.googleusercontent.com/io95g7CWkai_znLf3hCIP2GLcWr2s4imXovcbTV5UXcMqGciwK2pzcvz5JaOKdGDfNnMGVqFcAn4P3RQdLd3Nk2qKvzkrox1ZB-ro0W4yfhaHESX2QM" /></strike></li><li><strike><span style="background-color: white;">Since our layer list is huge, you will see a big box with all the layers appear.</span><img src="https://lh3.googleusercontent.com/Q9VYJ3PWx9zt6E3BwTn6pSn_kq7o5cjDYOEJqCmei0NQBXOP0FUqCS53t0UVjLqxG8IbY1ws_WopdVdpFMptVD962lzsmc7i9-yAdkulfKinbz_RNFg" /></strike></li><li><strike><span style="background-color: white;">Click on the Item Properties tab and select the layers which we do not want in the legend. Click the ‘-’ button to remove it from the legend.</span><img src="https://lh3.googleusercontent.com/lC5LwmjSSOiPJWifcMI32wCCqaEbDgFnR-EwsBz7ZX5buRIOoMChkswPUBYGKiW1TwcJxEgafFr1niuPio_SvVe3_8rI5mFkE7ifEG65X9jo4Jgv258" /></strike></li><li><strike><span style="background-color: white;">For the purpose of this map, we will keep legend information only for the five layers as seen below. Also adjust the transparency and font options from the General Options tab like before.</span><img src="https://lh5.googleusercontent.com/C2EcqnegmzR_uLJFHiH7GuIWRrxRFTia0xPUyYPZhxYwSYgPF3Pme2XLrRkhMQeZ7tJOw8VwvOiCkJJ7VR3jcKXw5fUigbxnXGLIudRk9_CPR1t5iug" /></strike></li><li><strike><span style="background-color: white;">Now time to label our map. Click on Layout → Add Label.</span><img src="https://lh5.googleusercontent.com/_ZRoLrE90QL_EQ0tI8DQDeExhVpbi0AeA8bYuiYWylNPzWrMNSCd1BoLYutrfSeKzzXDslVh_ryGmmy3GMDO9z30lEcfqpY-XK9RA6e_GsVyl4aLt0s" /></strike></li><li><strike><span style="background-color: white;">Click on the map and draw a box where the label should be. In the Item Properties tab, enter the text. Click on the Font button to make the size larger.</span><img src="https://lh3.googleusercontent.com/o5wJb5lo0rrSn4xPY5X7I4bxR4P3OBxjwIsS3VUd073TfSBEIjpdaIEg0NojLbXtmLq-xvqNs_MgR-hsu3jNxF76t_8KWGjWN0_Flu7kmk_KUHdUGeY" /></strike></li><li><strike><span style="background-color: white;">Once you are satisfied with the map, you can export it as Image, PDF or SVG. For this tutorial, let’s export it as a PNG image.</span><img src="https://lh6.googleusercontent.com/PYMenqR-VQR-7eAhd0kc_FkYhj5H9JbSFywfyLXv9CaPx9s5AUCZc5C0wIuxC_ujBeZ_RP9_RXgZ26uaRaQIkxLCqampWSG-dZi5eCaGspAAoSYkOjQ" /></strike></li><li><strike><span style="background-color: white;">Below is the exported PNG image.</span><img height="452" src="https://lh3.googleusercontent.com/xFd0XjaSRDwJ09s91c0wkwZ9o4XBW5JKmcK_QgxEmTiOKCdWnanr9BGtjGAQFCTsfrDUODAdPk7dQ548On256dhSr16iWc9llWkf_HHk8WrxmUOfC-Q" width="640" /></strike></li></ul><strike><br /></strike><strike>Hope this tutorial helps you create beautiful and interesting maps in QGIS. If you have tips or suggestion that will help other users use this tool better, please leave a comment and share it.</strike></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com25tag:blogger.com,1999:blog-8478705592464727054.post-26641435724425979232012-05-15T19:19:00.000+05:302014-04-07T22:16:10.192+05:30Tutorial: Using Online Data via WMS in Quantum GIS<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc;"><span style="font-size: large;">Tutorial moved to&nbsp;</span><span style="color: #0000ee; font-size: large;"><u>http://www.qgistutorials.com/en/docs/working_with_wms.html</u></span></span><br /><br /><strike>Often you need reference data layers for your basemap or to display your results in the context of other datasets. Many organizations publish datasets online that can be readily used in GIS. A popular standard for publishing maps online is called WMS (Web Map Service). This is a better choice for using reference layers as you get access to rich datasets in your GIS without the hassle of downloading or styling the data.</strike><br /><a name='more'></a><strike>In this tutorial, we will load layers of <a href="http://mrdata.usgs.gov/wms.html">Mineral Resources</a> published by USGS and overlay the 10m_urban_areas vector layer from the <a href="http://www.naturalearthdata.com/">Natural Earth</a> dataset.</strike><br /><strike><br /></strike><ul style="text-align: left;"><li><strike>Open QGIS and click on Layer → Add WMS Layer...<img src="https://lh3.googleusercontent.com/4ioKP22DnueC0YT5lBhHxiR24igEfNLf20wHxas190m0Lw63hZYk4PAl0U1XTosRj7QymwgoZnLra1OgSqID36c64kZgIy2_PN3jVv2FU9ZWkmRD1cA" /></strike></li></ul><ul style="text-align: left;"><li><strike>In the Layers tab, click on New.<img src="https://lh3.googleusercontent.com/IWLefDeY8AKfsd8i8J-a1KF8i9-OUfdYU-GPEonC6q7rp-s8hfOI1DovQcYrw3AY8Xf2Wpj_mDTut_Uhtj29rXT4rIrg8Sy2pyBbjL7CUNFv7LAAQNs" /></strike></li></ul><ul style="text-align: left;"><li><strike>Name your connection. This is not the name of the layer but the name of service which is offering the WMS layer. A single service usually offers multiple layers that can be added to your project. The URL that you need to access a WMS layer is called GetCapabilities. When you access a WMS server with this parameter in the URL, it returns a list of layers available along with various metadata. In this case, name the connection as ‘MRDATA USGS’ and the GetCapabilities URL as <a href="http://mrdata.usgs.gov/services/ca?request=getcapabilities&amp;service=WMS&amp;version=1.1.1&amp;">http://mrdata.usgs.gov/services/ca?request=getcapabilities&amp;service=WMS&amp;version=1.1.1&amp;</a> . Click OK.<img src="https://lh4.googleusercontent.com/PmbTJ6YPivl3n00rERJeJIcMxg2AkonkV7IEvZpa0_l10alJ7u36lSKl6IrRq46yLS92z-uLqtD33qVXIwh9xAHWKYbaD1nzsR03FOkfOAnYKkaKKtc" /></strike></li></ul><ul style="text-align: left;"><li><strike>Next, click on the Connect button to fetch the list of layers available. You will notice different IDs listed next to the layers. ID 0 means you get a map of all the layers. If you do not want all the layers, you can expand the list by clicking on + icon and selecting the layer of interest. Selet the layer 0 for this tutorial. In the next section, you have to choose the Image encoding. Image formats matter a great deal and which one you choose depends on your use case. Here are some pointers</strike></li></ul><ul style="text-align: left;"><ul><li><strike><i>Quality</i> : PNG is a lossless compressed image format. JPEG is lossy compressed format. TIFF can be either. That means the quality of PNG images will be better compared to JPEG. if your main purpose is to print a map, use PNG</strike></li><li><strike><i>Speed</i>: Since PNG images are uncompressed and thus larger in size, they will take longer to load. If you are using the layer in your project as a reference layer and need to zoom/pan a lot, use JPEG.</strike></li><li><strike><i>Client Support</i>: QGIS supports most of the formats, but if you are developing web applications, browsers usually do not support TIFF,&nbsp; so you should choose another format.</strike></li><li><strike><i>Type of data</i>: If your layers are primarily vector, PNG will give better results. For imagery layers, JPEG is usually a better choice.</strike></li></ul></ul><ul style="text-align: left;"><li><strike>For this tutorial, choose JPEG as the format. Change the Layer name if you wish and click Add.<img src="https://lh6.googleusercontent.com/z-5It2ol5hvcdXsQxheKxrfHgdIfXqwBZ4ggKKUEn763BC8EOor57yeH698K8H4kTeRICqIQMBpoliSBLhdgTHF2NjfGA9Nst-2nJl9fwlE9s6Udhuo" /></strike></li></ul><ul style="text-align: left;"><li><strike>You will see the layer loaded in the QGIS canvas. You can zoom/pan around just like any other layer. The way WMS service works is that every time you zoom/pan, it sends your viewport coordinates to the server and the server creates an image for that viewport and return it to the client. So there will be some delay before you see the image for the area after you have zoomed in. Also, since the data you see is an image, there is no way to query for attributes like in a regular vector/imagery layer. Right click on the layer name and select Properties.<img src="https://lh4.googleusercontent.com/TmtwySZybqvRE7nPsKiZcbPEwThuZbmF_wGrH6WQ-IoojwYoRnLYUb7NUqQYyRSzsXjAbTPQF0yp7tMR6BUI2SMAdJso2XSwDDAt4zh8s7bfXCVlxSE" /></strike></li></ul><ul style="text-align: left;"><li><strike>You will notice that the Properties dialog looks different and has fewer tabs. Go to the Metadata tab to learn more about the WMS service and the layers.<img src="https://lh6.googleusercontent.com/HV9ywUWFb_lrk61Pqr6KNi376Imr9nQleKj6yUygOl4an2RpoYrGXeXbU-HmQB7VuOkbJUXDeSJJstIcCZ1CQinpZpl9W0q1aJh9eBzdrX738SOvOi0" /></strike></li></ul><ul style="text-align: left;"><li><strike>Now let us add a regular vector layer to our map. Click on Layer → Add Vector Layer.<img src="https://lh5.googleusercontent.com/qZSFrIASpZnO0oKmzx9_1rdb5eiToGbYDT-V1dUekAxhY-2_NnsFNbJM2GbzZBV7Rzz1EgbZUk0CXZBP0L3XMOZvssXHvgV6V6WFLc_OjU56Ql2fgKU" /></strike></li></ul><ul style="text-align: left;"><li><strike>Browse to the directory containing the Natural Earth data and load the 10m_urban_areas.shp. Click Open.</strike></li></ul><strike><img src="https://lh5.googleusercontent.com/5KfY04YFeuK05S16Ecr1vYuoTE6ZxkqOuHdEwMZ9dbozmU4py60MQzkTaw7xSrGShyC7xBWHhYdZ1EkHlURAwI4cRvgESRNv1LwXIIr3qJ3EQUhQuEE" /> </strike><br /><ul style="text-align: left;"><li><strike>You will now see the polygons from our vector layer overlaid on top of the WMS layer. This gives a better context for our vector layer and can help you create a better and more useful map. <img src="https://lh4.googleusercontent.com/tNdAoTWPKBYRgI5QVI1GLINi0W_DS-FhiZME2FouvufrEF4Wq1jz8iMdax0F5PZLGW9-c8-xLsWtW5hHjLv3RKiP3-nXcpyo6SW-S4d20exlsg3C8O0" /></strike></li></ul><strike>Have you used any WMS layer in your GIS project? What are your favorite WMS layers? Let me know in the comments.</strike></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com7tag:blogger.com,1999:blog-8478705592464727054.post-89450116243512367662012-04-27T18:49:00.000+05:302015-11-04T15:12:03.324+05:30Tutorial: Working with Projections in QGIS<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc;"><span style="font-size: large;"><span style="color: #444444; font-family: &quot;arial&quot; , &quot;tahoma&quot; , &quot;helvetica&quot; , &quot;freesans&quot; , sans-serif;">Tutorial moved to &nbsp;</span><span style="color: #444444; font-family: &quot;arial&quot; , &quot;tahoma&quot; , &quot;helvetica&quot; , &quot;freesans&quot; , sans-serif;"><a href="http://www.qgistutorials.com/en/docs/working_with_projections.html">http://www.qgistutorials.com/en/docs/working_with_projections.html</a></span></span></span><br /><br /><strike>Map projections often cause a lot of frustration when working with GIS data. But proper understanding of the concepts and access to the right tools will make it much easier to deal with projections. In this tutorial, we will explore how projections work in QGIS and learn about tools available for vector and rasters - particularly reprojecting vector and raster data, enabling on-the-fly reprojection and assigning projection to data without projection.</strike><br /><a name='more'></a><strike>We will use <a href="http://www.naturalearthdata.com/">Natural Earth</a> vector data for this tutorial, particularly 10m_admin0_map_units layer. We will also use some raster data for the UK. I downloaded MiniScale raster layer from UK’s <a href="https://www.ordnancesurvey.co.uk/opendatadownload/products.html">OS Open Data</a> initiative. </strike><br /><span style="text-align: left;"><strike><br /></strike></span><br /><div><span style="text-align: left;"><strike>Let’s get familiar with basics of how projection is handled in QGIS. Projection is referred as Coordinate Reference System (CRS) or Spatial Reference System (SRS) within QGIS. Coordinate systems are categorized in 2 types: Geographic Coordinate Systems and Projected Coordinate Systems. Geographic Coordinate Systems use Latitude and Longitude as coordinates and use different ellipsoids. Projected Coordinate Systems project the ellipsoid to a surface and use various linear schemes to assign coordinates.&nbsp;</strike></span><br /><strike><br /></strike><br /><div><ul style="text-align: left;"><li><strike>Load the 10m_admin0_map_units.shp layer in QGIS via Layer → Add Vector Layer. At the bottom of QGIS window, you will notice the label “Coordinate”. As you move your cursor over the map, it will show you the X,Y coordinates at that location. At the bottom-right corner you will see EPSG:4326 . This is the code for the current ‘Project CRS’. <img src="https://lh3.googleusercontent.com/9bBIcsg5bFs66QHE4PWmmM7yJC9tKVeUPDOwEdY2Wn2QW6-KNgE1RaUgigLmkb1mV2rL-DWAaYx5Lypj-5c5BolytbstpLZig-xbRkVFKHnN8uqK19M" /></strike></li><li><strike>To determine a layer’s projection, right click on it and select Properties.<img src="https://lh3.googleusercontent.com/No2_QMyB0BfXNrwBwTsPeadNe5RXX-41fR5dKXD22aaBVpaf0SUPHhUur0kZ08j84fCMSumCcbEKCn1S1bFO2mU_N9dJkL82gvGmDuRVhPIA-ynHZFM" /></strike></li><li><strike>In the Properties dialog, click on the Metadata tab. You will see the projection definition of the layer under ‘Layer Spatial Reference System’. <img src="https://lh6.googleusercontent.com/8ybCsqesKRrcngup8TeZVqdOPLjKufDNfN1jo1Ei_NpCu5SJvCLFhlTnqMVjnCHfF_dqB3g3X4MYD6mbGOuxvNDwBSDLz-zO0Qs248mHmtkMQg1VH9U" /></strike></li><li><strike>Let’s say we want to reproject the layer to a different projection. Right click on the layer and select ‘Save as...’<img src="https://lh4.googleusercontent.com/3vg_loofLaQmpK0bV9_XElN7mz4ZRXtXgSRlRBOQyLK680hlyiqWBu68l-yXLirwi3LPrDmFFJeslMfS1mjgYx-PTZIqKPKVwW8isV3LFJLVvkJEsV0" /></strike></li><li><strike>In the Save vector dialog, first click on ‘Browse’ next to Save As label and name your output file admin_0_reprojected.shp. Next, click on the Browse button next to CRS label.</strike></li></ul><div style="text-align: left;"><strike><img src="https://lh4.googleusercontent.com/Tuj4iTzSmV44phaYCgiTnZguChFQaf2yfnVrh_a_w2dhAriqbp8TsMs8Xbxy0EakZrHTjpWGH_9PSSlY1zsd5Q7uIFIO48czS8-ltMR0fMRmA5LswIM" /></strike></div><ul style="text-align: left;"><li><strike>Since this is a global layer, let us choose the ‘World Mercator’ projection. Click OK.<img src="https://lh5.googleusercontent.com/pvhRK4quoscbCaNwfKbJsOwkLxRV2dNGZzTHAMoIJkiS-UJ8dfN_RyOFxilqzwcRKNxMeBAjvSqFEs_eg3f07amifcUfAL6IpNwT1gRsLsYXhK1t3JY" /></strike></li><li><strike>Click OK on the ‘Save vector layer as...’ dialog as well.</strike></li></ul><div style="text-align: left;"><strike><img src="https://lh3.googleusercontent.com/YLp8oITSemUuv48rHe8xfEUBV-Gx9_cLjLrSgTl3jVhF-QOnjgTdI7Bs8B4HXjY-8XcZHhAB46bdpyBKcvpbt26oIzRvH5CQEZ5Ycdt2b878gZ9b1G4" /></strike></div><ul style="text-align: left;"><li><strike>The layer is now saved at the path you had selcted. Load the layer to QGIS canvas by going to Layer → Add Vector Layer. <img src="https://lh6.googleusercontent.com/lydnWryiEukKJ1_IFmJd4IMkyBjKunBCLgjl15ECk9y4L5OVZ5Gf0t4NPMYmRXsBiynXcB1m3oAsgAXEU1xJ_lZ1od4pat_2aYgBwweFQI9wJPpzDUs" /></strike></li><li><strike>Once the layer is loaded, you will see it on the table of contents. But you don’t see it on the canvas. This is because you are in the latitude/longitude coordinate space from the previous layer. The new layer has a different coordinate space, so it will be located somewhere off the current view. To see it, right click and click on ‘Zoom to layer extent’.<img src="https://lh6.googleusercontent.com/EaKBz8flVZsi_63XmX9NM7QTdtdnkwGcGV231KGlNK_B3TnzMoQ3CZMKvdPDezuZ1bwifjt1S8xleKhgK9ahloXjqerqXBUSfh7M8ev2HlvkbcqKa3E" /></strike></li><li><strike>Now you will see the newly reprojected layer. But you do not see the previous layer. This is a common problem when working with data of different projection. Ideally you would like to see the layers overlaid on top of each other in the same coordinate-space regardless of their projection. There is an option called ‘on-the-fly reprojection’ to enable just that.<img src="https://lh4.googleusercontent.com/MaS8FWqnDFgj6JEz7wctt6R0EgWwKf0tppl8RArlMeANUY_QP0UMzSPAwWTk0V1TcLbearHppZO2zg1n7b2byJKk2jl3N4iLORJp5PazFZBR-_N6oSg" /></strike></li><li><strike>Click on Settings → Project Properties.<img src="https://lh3.googleusercontent.com/5vpGcqoo9Ow4l3ffuqijKjLC0G58ZiyIBDHaoRjlivECceV5fvuJnN0LeBZbc5Hn0DHmyofFvjcUrou6gKPyQP7anceJBIHVKgz0k6gltJcflYEl_jI" /></strike></li><li><strike>Check the box next to ‘Enable ‘on the fly’ CRS transformation’. Next select the ‘common’ projection that all the current and subsequent layers would be automatically reprojected to. We would keep that as WGS84. Click OK.<img src="https://lh4.googleusercontent.com/BTQpIBeuGSG01RNyPU2inPBb9QEEhDQHkpUN8Bd5cPDZAAXtoDFNtssZgh8mh2BZtvRtG7FKyPx_f3aFA-ZRVqb2eUPZrNYv-xFhf0LWZRp4JkNq_gU" /></strike></li><li><strike>In the QGIS table of contents. Right click on any layer and select ‘Zoom to layer extent’.<img src="https://lh6.googleusercontent.com/Cnkn-d1TMZAgfUTS4weNBkhSfIMxQPB1gLnJFivPT5GFgr5Lo9W9mlm8SSAvS0Vuk34UPSr1QbqM6yvUiNdmE6KfV-mF5Yj3EJdXo8Zcr8Fto1IxOX0" /></strike></li><li><strike>Now you will see both of the layers overlaid on top of each other and in the space lat/long coordinate space.<img src="https://lh5.googleusercontent.com/i9tdvBncMNsVKfsleHuwAtN6Zn-GhJhCcHD45QgoOh8pA6-ktqT3zwHIKHiPDi6FIWaNi4804heyYAzEZSxRuw9yLCLCRyC4YGl9PE964icwOqImLoQ" /></strike></li><li><strike>Now let’s switch gears and add a raster layer to our project. You have to download the Miniscale layer, extract the zip file to a directory and locate RGB_TIF_COMPRESSED folder containing tif files. You will notice that the .tif image files are plain TIF files, not GeoTIFF files. That means they do not have any projection information associated with that. To use any image in a GIS, you need 2 types of information - image extents and projection. Typically, the extents are stored in a file known as ‘World file’ and they have extensions like tfw or jgw. The projection information is stored as a ‘PRJ file’ and they have extension of .prj. Most GIS software, including QGIS would be able to use information stored in the world files and projection files as long as they are stored in the same directory as the original image and has the same name. So if your file is called foo.tif, your world file and projection file should be called foo.tfw and foo.prj. In the Miniscale layer, we have been supplied with the World files in a separate layer.<img src="https://lh3.googleusercontent.com/ByRNyVLxCBimFtTgF8UySOkVwwQUwiBfekp23AgkqwinMmI_hHKSEMs_EJaN-vmvGwzD05jUBDBUmaW6x3kl2c1jT4f0ENFNUO2oVREyfMV5_Uv8xPo" /></strike></li><li><strike>Copy the tfw files from the ESRI_TFW_Files folder and copy it alongside the tif files.<img src="https://lh4.googleusercontent.com/pacMnzqzRvYR-ZCbilnuLxUkW1zwy2yDkS7OV60BKqGmDv6aCV9IyrOTNX_wVeNqLr2cE_m_LLva4azYZcuKPcjcMy9wvuOjaoOuVfuUV3HRvQRQ_6c" /></strike></li><li><strike>Now we are ready to open the file in QGIS.<img src="https://lh4.googleusercontent.com/GNu-M8LxuibDsCUmgkHRe_LpRKKvueGUSg9vnKYoY-xtdyi3JHGClBNZvHEQPkKHTaKh_PLJpLtfkVfF_dZu18AJajsja6_NdP4tM6BG_J8xb6QkCUo" /></strike></li><li><strike>Click on Layer → Add Raster Layer. <img src="https://lh5.googleusercontent.com/G9xG8YaTgxCFeOh5Mo5vro3dJzENhh2UlbUi8N-EXmElbQr6YCfAMjgrS1d_EquXMp6qqs_UPXNj_vgYuha2IO8s0j4bv10FX0vRzQg0gQU5oG8mQaM" /></strike></li><li><strike>Select MiniScale_(no_grid).tif file. and click Open<img src="https://lh4.googleusercontent.com/AV-D7vfqvdsd0rkz_eg6-lbSJdsuZ1jc46N86KMS-dkg1n-75ds2w66IB0VgwQyZKQ_IFsJyTuQkFpc-6HWpbHEUwxV0y154OLWfY5h5tW21Imco_RY" /></strike></li><li><strike>You will get a pop-up box to define the layer’s projection. You can look at the <a href="http://www.ordnancesurvey.co.uk/oswebsite/docs/user-guides/os-opendata-getting-started-guides.pdf">data documentation</a> (PDF) and determine that this image is georeferenced in the British National Grid projection. Locate it from the list and click OK.<img src="https://lh3.googleusercontent.com/oq_clsIy5G2aQ8JnW_odh7uLaDdjTB45MV5lnj_kOYUSJ3wI_pz0ZOYPOu8j6qHY9ErKJ22S_UfgOrbzcAAjkkveV9lEs7Sj4ENfaJmqab_-FZULKsw" /></strike></li><li><strike>Once the layer is loaded, right click on select ‘Zoom to layer extent’.<img src="https://lh3.googleusercontent.com/z9I120Vc1uuhFvvueRZ2k8XYn4SRmgq4Yc8et3VNtEiAQgCidRxyu_4GdS_yi30XJWF4OVb-LetCUOFD6hockk4GRDrwvJm16YQqeAykEGYUq-CV8LQ" /></strike></li><li><strike>You will now see the newly added raster layer perfectly overlaid with our vector data. Remember that all these three layers are in a different projection and hence a different coordinate space, but because we have enabled ‘on the fly’ transformation, they are converted to a common coordinate space in real time.<img src="https://lh5.googleusercontent.com/TFNcOAXE1UfCBhlQDpeMuD3W0ltWkL70G16gnvdWknDu8VxDr3EIvKKzIsYCTCPN_GSH_i2CCShIMBDHqAVj0IjzW9bpEv5WrCgpWdOc67jJtwoeSbE" /></strike></li><li><strike>If you want to permanently assign the projection to the raster layer, use Raster → Assign projection tool. It will create a GeoTiff file from the original TIF file that will be self-contained with the extent and projection information.<img src="https://lh6.googleusercontent.com/-jKzVtivN_ujXlb7ugKWARgIoJbUT0aM_xOX3lR1plnJG3Cgm44xnt5imRF2eyPGU6LJAaGW2BgUR1kDm_slJggXP1KpMUdbcayOnQY2qDD2AEKK3xM" /></strike></li></ul><strike>Hope you have learnt the basics of CRS and how QGIS handles it. Do let me know how you deal with projections in your project.</strike></div></div></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com15tag:blogger.com,1999:blog-8478705592464727054.post-86929400874936821982012-03-31T14:29:00.000+05:302014-04-07T22:17:16.628+05:30Tutorial: Working with Terrain Data in QGIS<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc;"><span style="font-size: large;"><span style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;">Tutorial moved to &nbsp;</span><span style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><a href="http://www.qgistutorials.com/en/docs/working_with_terrain.html">http://www.qgistutorials.com/en/docs/working_with_terrain.html</a></span></span></span><br /><strike><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: medium;"><br /></span>Terrain or elevation data is useful for many GIS Analysis and it is often used in maps. QGIS has good terrain processing capabilities built-in. In this tutorial, we will work through the steps to generate various products from elevation data such as contours, hillshade etc. The Raster menu comes from the GdalTools plugin. If you do not see the options under Raster menu, please follow <a href="http://qgis.spatialthoughts.com/2010/10/using-plugins-in-quantum-gis_05.html">this tutorial</a> to find and enable the plugin.</strike><br /><a name='more'></a><strike>The task is to create contours and hillshade map for area around Mt. Everest. We will be working with GMTED2010 dataset from USGS. This data can be downloaded from the <a href="http://earthexplorer.usgs.gov/">USGS Earthexplorer</a> site. <a href="http://eros.usgs.gov/#/Find_Data/Products_and_Data_Available/GMTED2010">GMTED </a>(Global Multi-resolution Terrain Elevation Data) is a global terrain dataset that is the newer version of GTOPO30 dataset. For this tutorial, I downloaded a 7.5 arc” subset covering the Himalayas. <img src="https://lh3.googleusercontent.com/9C0LGf-IURe8yETTifEy4H3GuntsrQfv_Fbm6DtwyzcoTYPQNwzKJ3_leHVa0WjNCVozNcHSaRZG-FNct1Esh9LSxKz9tkWmtZCiqTpLG0Yx3Z6r428" /></strike><br /><strike><br /></strike><ul style="text-align: left;"><li><strike>Once you have downloaded the data, extract it to a directory. Elevation data is distributed in various raster formats such as ASC, BIL, GeoTiff etc. QGIS supports a wide variety of <a href="http://www.gdal.org/formats_list.html">raster formats</a> via the GDAL library. The GMTED data comes as GeoTiff files. There are many different GeoTiff generated from different algorithms. For this tutorial, we will use the file named 10n060e_20101117_gmted_mea075.tif. Load the raster file in QGIS canvas by going to Layer → Add Raster Layer.<img src="https://lh5.googleusercontent.com/rTPsdeUjWXvQ2jGqU5pqGUCtDuLOPlJc0tq5lFuJoLuapO0QXfzOPNEdj-gUj0rz9nFNFlNeYnrxmVaqgQW_AM8nHFM7elGa9Zt6vZFB9r4hNT4uZ28" /></strike></li><li><strike>Find the area of interest. From Wikipedia, we find the coordinates for the area of interest. Mt. Everest is located at the coordinates 27.9881° N, 86.9253° E. Note that QGIS uses the coordinates in (X,Y) format , so you must use the coordinates as (Longitude, Latitude). Paste “86.9253,27.9881” these at the bottom of QGIS window where it says Coordinate and press Enter. The viewport will be centered at this coordinate. To zoom in, Enter 1:100000 in the Scale field and Press Enter.<img src="https://lh6.googleusercontent.com/41cWBNu20AzA8qRVR6m7J8tJ6928ioyKkuc9xhTNLYcLCbJQ9Q4m3ok-pJgOT4NZUkOrh59vcj6YOBNStRWozQcc79vU9iSrlYVllkYKo7Af_bTXdzM" /></strike></li><li><strike>We will now crop the raster to this area of interest. Select the Clipper tool from Raster → Extraction → Clipper.<img src="https://lh5.googleusercontent.com/CCOts8q2uPR6eP7sc-rsIPpVZSl00wEfsFrr6YjsK9y0zRnlprJh6wEYjac3s6diTkvK2MX1xpqaWaBVLg6eCUl3opK9lpggqc96fBvLzgoMnE1AuOE" /></strike></li><li><strike>In the Clipper tool window, name your Output file as ‘himalayas.tif’. Then set the Clipping mode to Extent. Switch back to QGIS canvas, hold down the left mouse button and select a rectangle covering your viewport. The extent coordinates should be automatically populated. Check the box that says ‘Load into canvas when finished’. Click OK.<img src="https://lh3.googleusercontent.com/xaJl3wTPmc-hlDfeWbbX9jnCih81YkDlSmvV0OZMMeDRaaT0aGyfb7EWUFDShKKXAcuUytl3ri2kvISyzE3ZlyBcZsLYWr5x8nlktnvWaA-01LVue9Q" /></strike></li><li><strike>Once the processing in complete, you will get a new layer in your Table of Contents. Right click on the original raster and click ‘remove’. <img src="https://lh3.googleusercontent.com/7weC3VAgoMwQ7m1BKhK6I-gGiV4jYtljMb0Kfw7BUULbSEyr1-4erCIA7hnrDQqPucBxDgHsfNWRZpov41yUjrnnvMAaBFGngcRCf_bCpmfGWV4UpSY" /></strike></li><li><strike>Now we are ready to generate contours. Select the contour tool from Raster → Extraction → Contour<img src="https://lh5.googleusercontent.com/geGZR6xdWfP_olDVpTrfnB8B07qGrNaclLGi8NCoNkZMVxlsz9k2EvavYlXdqrbW_0URzW4nosZA5GyC13uc9aycyDPiDMQbwxDFW78oA2r7qdsLLf8" /></strike></li><li><strike>In the Contour tool, name your output file as contours.shp. We will generate contour lines for 100m intervals, so put 100 as the Interval between contour lines. Check the boxes next to Attribute name and Load into canvas when finished. Click OK.<img src="https://lh4.googleusercontent.com/gN-GuPjgRpkFr2g5Fw-rcqcjbAFzjlMkVAwF2-FnxN5QIpBdAa3-qUumKw6zc30LwMokGKeCnIG6NHKqZj9bPibGmtV4oA35_AZr96LmCn-qE2SaoMU" /></strike></li><li><strike>Once the processing is complete, you will see contour lines loaded into the canvas. Each line in this layer represents a particular elevation. All points along a countour line in the underlying raster would be at the same elevation. The closer the lines, the steeper the slope.<img src="https://lh5.googleusercontent.com/J6c72x_R4h19CZor_jiMmdrFllI2pkG4NUmkHFBiemg5_nbE2lqbuCCF7H0FNjE29tqUCrAyPPDzKnAIfP4WpG5OGt9rw2gZAY0Bd3HkR_Ko5v_lxyY" /></strike></li><li><strike>Let’s inspect the contours a bit more. Right click on the contours layer and click Open Attribute Table. You will see that each line feature as an attribute named ELEV. This is the height in metres that each line represents. Click on the column header a couple of times to sort the values in descending order. Here you will find the line representing the highest elevation in our data, i.e. Mt. Everest.<img src="https://lh3.googleusercontent.com/4H9LZyHaazaDBx50sBabLuIeKAfd9_dKNBV8-CiAWsFfN-R3Yun2U38pA7FEH-d0Cak9_ThuYMUJe1rZvGkd9Njy6QDD0ATYHr4PodU373FJo5laliw" /></strike></li><li><strike>You can visualize these contours and verify your analysis by exporting the contours layer as KML and viewing it in Google Earth. Right click on the contours layer, select ‘Save as..’. Select Keyhole Markup Language (KML) as output format and name your output file himalayas.kml. Browse to the output file and double-click on it to open Google Earth.<img height="377" src="https://lh6.googleusercontent.com/DQ17ltDG4nw2MyKLaWzfC9K9-bjX4KeB1lsohSfceWGCAUDbu7pavQ03vZt5I6ZRCVnN-3s9OCtbDbe2vvQ7_h5cbEE9YgE60kVeOdaUGsnQRkWfy9o" width="640" /></strike></li><li><strike>Now let us create a hillshade map from the raster. Select Raster → Analysis → DEM (Terrain Models).<img src="https://lh5.googleusercontent.com/A1S-PLGxyOFR7n2ecIqRHua6XSPRI3CsxnbB4OOQB9ZdhB-3vni2gUyx-GUBHjdWRVZsiXTB0YrmlWEgwEIGx3d4SKXFGE8nsbF-gr8nG2DrfbGcNJE" /></strike></li><li><strike>In the hillshade dialog box, name your output file as hillshade.tif. Select ‘Hillshade’ as the Mode. Check the box next to Load into canvas when finished. Click OK.<img src="https://lh6.googleusercontent.com/jj7l6qGNQ4h5Wac5fHocTevPkz9_gfJzz6UdH4vsFk5t8xuOnt_G1zLz_fY5KifYsaFKNBBkPW7L4jawxkc6ltWYalr_LvznYqC1WVFA6zwJMoulsNs" /></strike></li></ul><strike>There are many other terrain related options available under the Raster menu. We will explore those in a later tutorial.</strike><br /><strike><br /></strike><strike>Pro Tip: If you are working with large amount of raster or terrain data, it would be worthwhile to learn about the GDAL utilities. If you noticed, the clipper, contour and hillshade tools all used GDAL commands in the background to create the rasters. The gdal commands are displayed in the tool window as you select various options. Learning the command-line options for these utilities will help you automate or batch process large amount of data. Learn more at <a href="http://www.gdal.org/gdal_utilities.html">GDAL Utilities</a> page.</strike></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com17tag:blogger.com,1999:blog-8478705592464727054.post-58070258500604344122012-03-26T21:02:00.001+05:302014-04-14T18:02:12.242+05:30Tutorial: Using Tabular Data in QGIS<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc;"><span style="font-size: large;"><span style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;">Tutorial moved to &nbsp;</span><a href="http://www.qgistutorials.com/en/docs/performing_table_joins.html">http://www.qgistutorials.com/en/docs/performing_table_joins.html</a></span></span><br /><strike><br /></strike><strike>Not every dataset you want to use comes as a shapefile, or in a spatial format. Often the data would come as a table or a spreadsheet and you would need to link it with your existing spatial data for use in your analysis. For example, you may be working with census data for a country where the data is in a table, csv, excel file, access database table or any other non-spatial format. To map this data, you have to merge this with a shapefile containing boundaries of census tracts. This operation is known as ‘Table Join’ and this tutorial will cover how to carry out table joins in QGIS.</strike><br /><a name='more'></a><strike>For this tutorial, we will use country polygons layer 10m_admin_0_map_units from the <a href="http://www.naturalearthdata.com/">Natural Earth</a> dataset and merge attributes from a table from World Bank database to create a ‘wealth distribution map’. I downloaded the 2008, 2009 and 2010 data for <a href="http://data.worldbank.org/indicator/NY.GNP.PCAP.CD/countries?display=default">Gross National Income (GNI) per Capita</a> from the World Bank’s <a href="http://data.worldbank.org/indicator">Indicator</a> website. (Click on Databank, and follow the wizard to export the data) This data is offered in several tabular formats, and I chose CSV as the output format.</strike><br /><ul style="text-align: left;"><li><strike>Examine the tabular data. You can open the CSV file in a text editor, or use any spreadsheet program such as <a href="http://openoffice.org/">Open Office</a>. You will notice that there is a header row with name of the column, such as, ‘Indicator Name’. The GNI data that we want to map is contained in the columns - 2008,2009 and 2010. Also there is a 3-letter ‘Country Code’ column which assigns a unique 3 digit identifier to each country.<img src="https://lh3.googleusercontent.com/R8WsNAx2t6IqI145_HFYR5AdyHf6wfjvgUwjWZvNGhA8qTRiZOnjcjoyNIaeT69FQm9HVzONtaR-KDDUlXtRo-LQspjJIU2OTOgYY0Dtv9h_Qbze9KA" /></strike></li></ul><ul style="text-align: left;"><li><strike>Open QGIS and load the 10m_admin_0_map_units layer via Layer → Add Vector Layer. This layer contains polygons representing countries. <img src="https://lh5.googleusercontent.com/nhOx4vhaAgK7zr8pnZf0fQ8TxQByKkBSDC67DEIjx5CUaYWZnR37Ew_AyC5Z1MAxx2oNq9krs3NL1IvQjpbd7FTxrk0CTrLwEjQVpuTgRvuKSnY0PUA" /></strike></li><li><strike>Open the attribute table of the vector layer by right clicking on the layer and choosing ‘Open Attribute Table’. You will notice that the attribute table also contains a 3-letter country code. We can use this unique identifier to join the GNI data to this vector layer. You can use any common field between the two layers to perform the Table Join.<img src="https://lh3.googleusercontent.com/Ml3ech-fVplL3O5u033iXmWQVExso75AZ7VsdsLhjB1oM0Jc_BO37PJfA7C8x7caYzTxoVC-YjwEtqJCGhX_FjJRUJuhWHnbZC1qKiYJ_BVgk-iI77I" /></strike></li><li><strike>Before we go ahead and join these table, you will need to be aware of some limitations of importing tabular data to QGIS. These limitations are mostly due to the <a href="http://www.gdal.org/ogr/drv_csv.html">OGR’s CSV driver</a>. I encourage you to refer to this if your import does not work as expected. I have outlined some common limitations and workarounds.&nbsp;</strike></li><ul><li><strike><i>Compatible formats</i>: The tabular data must be in CSV format. Most spreadsheet programs or databases will allow you to export the data as ‘Comma Separated Values(CSV)’ file. Make sure your CSV format is compatible with OGR’s <a href="http://www.gdal.org/ogr/drv_csv.html">CSV Format</a>. In our example, we downloaded the data from the website is a compatible csv format, so we need not make any changes.</strike></li><li><strike><i>Header rows</i>: You must have noticed that our data had a header row which specifies the title of the data column. These are useful in identifying the columns. The OGR driver recognizes header rows, but if your header row contains any number, such as “2008”, it will treat the row as ‘data’ and not as ‘header’. To prevent this, you must put number-only headers in double quotes “”. Open the CSV file in a text editor and add the quotes as follows. <img src="https://lh6.googleusercontent.com/YrDMSBwDWRCcOKgZ3tmkZgzmIStm8uo6RyV4__gnko3MOrJetjkj1pJSZeXl-FCZukhKi0_TVu6DVPWBYk0cLVik7yQ296sohjrj00CbbfRriqo1ELk" /></strike></li><li><strike><i>Numbers</i>: By default, OGR driver treats all data in CSV file as Text. If your data contains numbers it will be treated as text and it will be useless for analysis or mapping. To overcome this, you will need to create a ‘CSVT’ file. See <a href="http://underdark.wordpress.com/2011/03/07/how-to-specify-data-types-of-csv-columns-for-use-in-qgis/">this post</a> for more details on using CSVT files. Essentially, you will have to create a text file specifying what is the data type for each column. For the above dataset the CSVT file will look as follows. Remember to name the csv file the same way as the original CSV. So if our data is in gni.csv, the CSVT file should be named gni.csvt<img src="https://lh4.googleusercontent.com/L0Z6XATOBi3qC3jCDAx0VNgMzrFinCCD_-JR-WxaS0AmvVeq0TYt-lvItixRJzVELnvR7lgb5krjtlF9iNcZJgemipeO5ZvB_Ro_p-S799YU5LvJ7C0" /></strike></li></ul></ul><ul style="text-align: left;"><li><strike>Now we are ready to add this data to QGIS. It’s a bit odd, but CSV data tables can be imported via the ‘Add Vector Layer’ menu item. Go to Layers → Add Vector Layer. Select your CSV file and click Open.<img src="https://lh3.googleusercontent.com/ud6tnH1GfOH6roQWzONcG3jr6gCCDdA2nxjMc2syttgy9z7ytiDGwc9cUbjpPf4Zog3ygrismctc_BOQ2f4F7o_5lI6URAMTNtwtrxW2v4VM41Q8W7Y" /></strike></li><li><strike>The table will appear as a layer in QGIS Table of Contents.<img src="https://lh4.googleusercontent.com/q-BMgSaXbqCVmC5TaTeTWXtpMOQwzws9KBOYBsAASKe6qFBV53xbshoBrGLxbo8F0tOi--xPX6oZ91yzYqBe15D2WlId4szdSM4dj-Zn7a_BxxNB53U" /></strike></li><li><strike>Right click on the gni layer and select Open Attribute Table. Make sure all the columns in the CSV files are correctly imported.<img src="https://lh6.googleusercontent.com/7I3Qj3iu6gQlkhacnTCTrya2zvAAJQah0Oe3NJqUxl4-d0DFb0z0QWaWJcibElDQPG8DffoqADOECYyzwoVG5ZwPpAPooL9Y_iUJHMQRyKJK6-D90l4" /></strike></li><li><strike>Now we will join this table layer with the spatial layer. Double-click on the 10m_admin_0_map_units layer to open Properties dialog. Go to the ‘Joins’ tab.<img src="https://lh3.googleusercontent.com/VwtXap9z-_LZq3YCg79fSUZx9wHY82ie9QoRuVoTBLztPpYvEHj17txUt8wPmZ0rxV1AcsQrbzhTlJBz5r6vorf3HJwmx4q64_-G1kLdASSPVYTXymk" /></strike></li><li><strike>Click on the ‘+’ to create a new join. The ‘Join field’ will be the unique identifier from the tabular data. The target field will be the unique identifier that will link the tabular data to the polygon data. Click OK. Once the join is created, click OK and return to the QGIS canvas.<img src="https://lh3.googleusercontent.com/X47trjcUlNdUk9rMAlQkGEt5EfBtqEU47pVc0wwdjWia2DdgBjvw1Xwg_keoQ6JD6NgzUDfJuVkci_uTPNnQ7Ga5MIeIVlQ_g51g4JbozoIP1Kz2zcc" /></strike></li><li><strike>Open the attribute table for the 10m_admin_0_map_units layer. You will notice that the table now contains additional fields from the CSV file. <img src="https://lh6.googleusercontent.com/i8nxHsyJUVftwll8-8yIfE8ODGnTPfrg1RwEQVgIZ2WYN0PneQVT5U1oWAfabd1-152QSW943RXTIftClw9lrXzHUjLQhDgFtJAlIRSdosNfqKMsweI" /></strike></li><li><strike>Remember that this ‘join’ is temporary. It is not part of the attribute table for the 10m_admin_0_map_units layer, but just linked dynamically to the CSV layer. If you want to permanently join the attributes, you must save it as a new layer. Right click on the 10m_admin_0_map_units layer, select “Save As ...”. Name the new layer ‘gni_ne.shp’<img src="https://lh3.googleusercontent.com/7RZzp-wbnjILDEg_wd_ZNPg099VC1pAF5DmLd4rqpD1QFR_3TAvVVgC_lnDtO5ZHvVAviYltAOMwccRSmefiuMOjfVVIuyl9pABhbbIaTJOXZZx-nfQ" /></strike></li><li><strike>Add the new layer to QGIS. Now you can style this layer to create a map showing the wealth distribution in the world. Use the technique in <a href="http://qgis.spatialthoughts.com/2012/02/tutorial-styling-vector-data-in-qgis.html">this tutorial</a> for instructions on selecting appropriate styling method.<img src="https://lh3.googleusercontent.com/QknVrE6vUb6piYKA1Z-vJ2vLgO1lGB3BaMDyttmKY0UbbZHOAAKCmLHy4QSt2y8NtRa-p9wqRqZgi0j3_ldTILFL04Fq1XTsI5U9nP7GGmndB_L6ZA8" /></strike></li></ul><strike>Hope this tutorial helps you in working with new and interesting datasets for your project. Let me know in the comments what obstacles you faced in importing tabular data and how you solved them.</strike></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com22tag:blogger.com,1999:blog-8478705592464727054.post-32454633053568186982012-02-22T20:35:00.000+05:302012-02-22T20:36:14.496+05:30Tutorial: Styling Vector Data in QGIS Using Size-Scale Field<div dir="ltr" style="text-align: left;" trbidi="on">As you saw in this previous tutorial, there are many options available to style vector data in QGIS. But you may have noticed that all the basic method of styling vector layers uses only a single attribute or a single column from the attribute table. Usually GIS data is pretty rich in information and you have more than one useful attribute in your data layer. Presenting two or more of the attributes together can create a very useful map or communicate a powerful story. In this tutorial, we will explore using ‘size-scale field’ option to draw symbols whose area is proportional to an attribute. <br /><a name='more'></a>We will use NOAA’s Significant Earthquake Database and <a href="http://qgis.spatialthoughts.com/2012/01/importing-spreadsheets-or-csv-files-to.html">import the CSV file as a points layer as described in this tutorial</a>. We would like to create a map that shows both the intensity of the earthquake as well as number of deaths caused by it. <br /><br /><ul style="text-align: left;"><li>Load the earthquakes layer in QGIS. To visualize the points better, I also added 10m_admin_0_countries shapefile layer from the <a href="http://naturalearthdata.com/">Natural Earth</a> dataset.<img src="https://lh6.googleusercontent.com/8eYXoQW7wn_9klk2DgJtbu5BlNTr5E4HOjX36-cvWYfMEn2BilyTpGh1GjtfAEb4hem6iGC6DznUGO86KlcG6I1x2QbA1SEK-cs3caXWxy7LD82bUHE" /></li><li>We are interested in mapping 2 attributes - intensity and number of deaths. Select the earthquakes layer and open the attribute table by right clicking on the layer name and selecting ‘Attribute Table’. Look through the identify the relevant field names. The field names are INTENSITY and DEATH as shown.<img src="https://lh5.googleusercontent.com/ouiud4Hkr-xwTmEQBwsSrIoC81edjOV0-WKYU3Qr5YDc-hGVsuikUXVjMbMQQKvZP0NQcxC-L7ya5qa5LsasV3o6ciW7-pdn3PbTHE7dQXHqpnj1Ssk" /></li><li>You will see that there are several points which have either of the field values as 0. These will not be useful in mapping, so let’s select only those features that have non-zerovalues. Click on Advanced Search at the bottom of Attribute Table window and type in the query ‘INTENSITY != 0 AND DEATHS != 0’. Click OK.<img src="https://lh3.googleusercontent.com/EiwpryLRIA8UiG5C9C7mHYP_7g_-3AzgYXBA6xIi71nn9BRp-xN3ylglrZKa7L2SZ5i28lCvuTHyFkY8QGxbRrs_Xw-b7AojCxXP4Z8W7bW8ut1RIEA" /></li><li>Once you have a selection, switch to the QGIS canvas. Right click on the earthquake layer and select ‘Save selection as’. Name your output file ‘earthquakes_filtered.shp’. <img src="https://lh4.googleusercontent.com/WoTwBRTzgIBcnnD4psDmDCgqYqLZtyT38Rwbsknn8jaB33qV3R_jLhARRr9pl8cJ71drc-0SUffyM_vRqm61HKwzn4mN1RUyfCKxKpVjyeS4WyuHuaI" /></li><li>Right click on the earthquakes layer and choose ‘Remove’. From Layers → Add Vector Layer, browse to the earthquakes_filtered.shp that we created in the last step and add it to the TOC.<img src="https://lh3.googleusercontent.com/YuOLkh861sCLJtBNKB6Y7x5Qvl3bWTTdilxL-z9QTWHD46EVBDonZ-pefd3q-Prv6ZtoBKXisQ-pc3NjHNYcCwRDX6Yk91EtdlP8M8z5pZBcQHvPRfQ" /></li><li>Let us zoom into a country and try to style this layer. Use the Zoom In button to draw a rectangle around China and zoom to that region.<img src="https://lh6.googleusercontent.com/ZwVljg3cAldEmOOY6iGeOIngY4YMDb-CUrAkp5oMBbJBdPR41R_XLunesJqksJASK5eol3HZn18TTqLg391SzTdOtnJ4kTS6pqFhe5Z8Va3K8jpNZXc" /></li><li>Right click on the earthquaked_filtered layer and select Properties. Tip: You can also double-click on the layer name to open the Properties dialog. In the Style tab, choose Graduated from the drop-down menu.<img src="https://lh3.googleusercontent.com/XSZa3Vhi-Wjp01TDKvFQ9NEvRM3q8FZWeq3sMsmVzgqPj0zrUwF3EnHwf-CSZ3qU6bVFyYrmclsfxj-mtaGlSFBUjbBGN99Hs1FE_LnTzk0h7Sv-Ax0" /></li><li>In the ‘Column’ field, choose the field ‘DEATHS’. This will be the first attribute we want to map. Choose ‘Oranges’ as the color ramp. We will use the Natural Breaks (Jenks) mode for classifying and use 5 classes. Once the options are set, click Classify. Click Apply and look at the QGIS canvas - you will see the points rendered in varying shades of orange depending on number of deaths caused. <img src="https://lh4.googleusercontent.com/gzycH_2kLOqsCH1Co27f8e5guj-UKKTnPJm5SdssjqJY40GtiNI-4_tKCuIJc7yecV-xn-_mYheyDq6doopZZkbVVkVpHq1v3G1OibA9scqZCx07szI" /></li><li>Switch back to the Style tab. Now it is time to map our second attribute. Click Advanced at the bottom right of the window and hover your mouse over Size Scale Field. Once the menu pops-out, click on the checkbox next to the field ‘INTENSITY’. (This is a bit tricky and you can easily miss the correct menu.Take your time and verify you have selected the right field.)<img src="https://lh5.googleusercontent.com/l0PTyx2ep4GxclSDjCn7j2B7r--0--sQjkIawX7O3Ohxx_74vSbayCr59ZbJh9Bwt8xt_4G7rGxBh4_6v65OYMIX0-SzU8XXsZCJHYr1hp-skQoy0Ow" /></li><li>Click OK and look at your canvas. You will see different sized circles in shades of orange. The size of the circle is determined by the INTENSITY field. You will notice that the circles are quite large and clutter our map. Let us reduce the size of the symbols.<img src="https://lh6.googleusercontent.com/Ie2zJVMDIVnrbAiH-Jyjk1lJjfGpe28LpeXoC-yEsaY11h4DEHM5VdZHfspjqGIy-qB-pMzvtsttwI-HaUXUBKGE8a6Cre0LqSZTxwMRwlnzlzyRqac" /></li><li>Go back to the Properties dialog. In the Style dialog, click on ‘change’ button next to Symbol. In the Symbol selector, change the size to 1. Click OK. ( You have to use trial-and-error to judge what size would work best for your map.<img src="https://lh5.googleusercontent.com/HAe2GCEHP1ETF5rRR39MTmgHLAZRPeQ3m6AHcWUP-lETqQL8ykAsgdSW-1v0_zhVcciX8D_ycqa9Vc5mbj1oljJtwG7rKSf6-_ENEbKLvQbBTcTy91g" /></li><li>Remember to click ‘classify’ once again after changing the symbol. Click OK and switch to the canvas to see the updated map. ( Note: I had to do this a couple of time before the change took place. Could be a bug )<img src="https://lh4.googleusercontent.com/CVHKU9cisIOOmLGK0nUdLGuzkqWcuvXkwdPnPwZ_bqOe5UfG4guPTcD9lJVj6TUEmQzGAQuaeCE7c5g3I-WSNepjjBxsZxmqjalsM0TP9yOR4V2DpEM" /></li><li>We aren’t done just yet. You will notice that some lighter circles overlap and obscure the darker ones. Let’s fix that. Go back to the properties dialog and click on the symbols next to the classes. <img src="https://lh4.googleusercontent.com/dOSkazMcNUzjOjA_Gin22uM4_YTPXQ5CxuJt3BSBIR11qDMIF5Z7fbblSE7rELtulyGy29qsSFDHqAygVP9H9WQy1k0Frvevo13ESWjdJU6qxwirgMM" /></li><li>In the Symbol selector, slide the transparency slider to about 75%. Do the same for first 3 classes. Leave the last 2 classes representing higher number of deaths to 0% transparency. Click OK.<img src="https://lh6.googleusercontent.com/j9FhTxFTziQREfC2YoPML-D9yVSToURCGB6AV5MmBNT8VvzlpdZtLJzC01qo-jCM_hH0ZgokgWec0yiV7OiNg35W-mDILfCT2DCTiW3KGur8B5IeT8k" /></li><li>Click OK on the Properties dialog and switch to the QGIS canvas. You now see 2 separate attributes mapped together on a single map. The map clearly shows where the worst earthquakes have hit and their relative intensity. <img src="https://lh3.googleusercontent.com/eGB4Bm3WQ1Ol5ZLf5lI_Auahe-ckMt8vtPC2OdcrzkPERGVonVR1YbAhqsvby3sAQtVnmmyqwFknB9t2eNOtgNiUJqcEVidjxQ-IeTJiTo2dvcaJ0qc" /></li></ul>In case you were puzzled by the number of deaths for some points - you can check your attribute table and note that these happened a long time ago and hence the large number of estimated casualties. <br /><br />Hope you learnt a new method of styling and it will give you ideas to present your GIS data in a new light. </div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com6tag:blogger.com,1999:blog-8478705592464727054.post-10233084642197519622012-02-20T19:35:00.001+05:302014-01-03T18:05:03.669+05:30Tutorial: Styling Vector Data in QGIS - Basics<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: medium;">Please see&nbsp;</span><a href="http://www.qgistutorials.com/en/docs/basic_vector_styling.html" style="background-color: #f4cccc; color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: x-large; text-decoration: none;" target="_blank">Basic Vector Styling</a><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: medium;">&nbsp;for an updated version of this tutorial.</span><br /><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: medium;"><br /></span>To create a map, one has to style the GIS data and present it in a form that is visually informative. There are a large number of options available in QGIS to apply different types of symbology to the underlying data. In this tutorial, we will explore some basics of styling.<br /><a name='more'></a>The data we will use is from <a href="http://www.sage.wisc.edu/atlas/maps.php">Center for Sustainability and the Global Environment (SAGE)</a> at the University of Wisconsin-Madison. I downloaded the <a href="http://www.sage.wisc.edu/atlas/maps.php?datasetid=12&amp;includerelatedlinks=1&amp;dataset=12">Life Expectancy GIS Grid data</a> from the human impact dataset. The task is to create a map showing life expectancy in different countries of the world.<br /><ul style="text-align: left;"><li>Open the shapefile in QGIS using Layer → Add Vector Layer. When prompted to choose a CRS, choose WGS84 from the list.<img src="https://lh6.googleusercontent.com/fzhGC-h3vh8RRPsQJFzaOZhM0xYwBDaVQQ2JHCU3MD5tkj4xg2fqlIOdt-K7CRBc2no8gkTt9tQQ7rA-LxLPk3SWekEwuxXuduwgKM4Eiq216UYaAMo" /></li><li>Right click on the layer name and click ‘Open Attribute Table’.<img src="https://lh3.googleusercontent.com/jwPsueouIyCuI0pQpbqvaZYoRuF3VNmFN5mmN3HnqFCkmhQYov1S4k8sKrhkXnX-RfhDsXy5upc2fRzNgM_dPRYbc47g1FBsq-r-EqqpWRc7H2rH2fw" /></li><li>Explore the different attributes. To style a layer, we must pick an ‘attribute’ or a ‘column’ that would represent the map we are trying to create. Since we want to create a map showing life expectancy, i.e. the average age till a person lives in a country, the field LIFEXPCT is the attribute we want to use in styling.<img src="https://lh4.googleusercontent.com/MYFZlaCufsMeVBqyOda9FcmRgkU5xX1X-9-kY_drTzBRlPrkMgMRJSB_si7Sg12TWfzNKWmwS_Y89cPwxdikpE4tlabAzZygeuzobOZWdCaKioA9Ol4" /></li><li>Close the attribute table. Right click on the layer again and choose ‘Properties’.<img src="https://lh5.googleusercontent.com/bX0SIo5adpP4kyH02UStE8Qng_058eS43XdXChjNxJv3b84ZOQ2GF7Y5ZK71tekhXJgCoQz7XS3sMvQY0s9NbHKYJu5KY6-vmtpVinwhP4IrSiHs_mo" /></li><li>The various styling options are located in the ‘Style’ tab of the Properties dialog.<img src="https://lh6.googleusercontent.com/ZYxj8IhTNcg1oXxAea-R-ItMlGQdvOuTVOF7pcBy1UmbkhUFECGWPVBEg_nw87Xutgvk8NB7j20siooSzR1lZYJtRJbuxxgj0_bQXICNgpdBJb0qQBI" /></li><li>Clicking on the drop-down button inthe Style dialiog, you will see there are four options available. Single Symbol, Categorized, Graduated and Rule Based. Let’s explore each of these.<img src="https://lh6.googleusercontent.com/8f_CP2sSBUhxzm4bX2KL-5rvqqhOd_vsZcdkVakA36DjdiBHv6768kupDVFhRVdmjXWJXkQHJIJmMvJhDXHGG8yQVwnj2IbH6gcwQBeURIaz0hRNM1I" /></li><li>Select Single Symbol. Single Symbol means all the features in the layer will be styled the same way. You can choose which color or type of outline to draw the features with. Click on Change button in the Style dialog to see these options.<img src="https://lh5.googleusercontent.com/qqjuoMYQ60EARBH8hpPb0OFvwg4-Er1idylHBlcuEU6-wFs0bSzNBGQgW9uoF1_NE38v0mYMDLuqJFaQvY1-jSRUMI0vnPpGsvpqfqWKpkp11EzF3fQ" /></li><li>Since this is a polygon dataset, you have two basic choices. You can ‘fill’ the polygon, or you can style with only ‘outline’. Among fill options, a useful feature is ‘SVG fill’ - where you can use a graphic symbol to fill your features. We will explore this in subsequent tutorials. For this exercise, you can choose ‘Simple fill’ and select a color, fill style, border color and border style. Click OK.<img src="https://lh5.googleusercontent.com/sVwSllKAEZX0n3lTRAft4GkibvGLF7LYIltgam17JlYVDQFZhE3xBHalpIEMZ_rVV8EkDB8-_jXGKBiVrA6hZ6ysTlgYgllkYq4bp2emCtrO1X2tCPA" /></li><li>Click Apply in the Style dialog, and switch to the main QGIS window. you will see this style applied to your layer. <img src="https://lh6.googleusercontent.com/4MLQhMfeZltIUsIj0DcAll8AXAUo2Yut1uSmDvMqEY8i9TocnxKhq3vx2gEjDfkv9ScyDkMj0Ps-FFpsbfKdQmcCOceR8sTA9o9diIEra9GhdRfzOa8" /></li><li>You will see that this Single Symbol style isn’t useful in communicating the life expectancy data we are trying to map. Let us explore another styling option. Choose ‘Categorized’ from the Style tab.<img src="https://lh3.googleusercontent.com/ebOTBNerAVqxWmISNiai3sx4orH3KAPy9j3ukCvtbbCw4pErrUuI1ThRwAELNfUpdP5hw1tXTF4haj15L64RX7CGGsc5xTX0jWysZmsmtNyOj42gz_s" /></li><li>Categorized means the features in the layer will be shown in different shades of a color based on unique values in an attribute field. Choose ‘LIFEXPCT’ value as the Column and click ‘Classify’ at the bottom. <img src="https://lh6.googleusercontent.com/sZTwx68hOnK7s8TdCg-yxVfDAHLBmgouY2Op29l6VFM20qG_9Ig6zR4IdZeFxDYgbzfj-ETtOpGqN9mmsXFc8Dxco2-9yBdalRduOdFsbx-Py_8fqq4" /></li><li>Click Apply and switch to the main QGIS window. You will see different countries appearing in shades of blue. Lighter shades meaning lower life expectancy and darker shades meaning higher life expectancy. This representation of the data is more useful and clearly show how life expectancy in developed countries vs. developing countries. This would be thetype of map we set out to create.<img src="https://lh5.googleusercontent.com/lr7_MX2s1v2OQQ_PQr0ZD2uqEvZFvTBaolDvoknAAn9bYcd2WibnW7v0Zv6-0lazixa70nNRcUdJ0_3Usl8xQewm6rAZvMBMnTT1Tvpc5e5R-5SPM7g" /></li><li>Let us explore the ‘Graduated’ symbology type in the Style dialog now. Graduated symbology type allows you to break down the data in a column in unique ‘classes’ and choose a different style for each of the classes. We can think of classifying our life expectancy data into 3 classes, ‘LOW’, ‘MEDIUM’ and ‘HIGH’. Choose ‘LIFEXPCT’ as the column and choose 3 as the classes. you will see there are many ‘Mode’ available. Let us see the logic behind each of these modes. There are 5 modes available. Equal Interval, Quantile, Natural Breaks (Jenks), Standard Deviation and Pretty Breaks. These modes use different statistical algorithms to break down the data into separate classes. Read <a href="http://www.carsonfarmer.com/?p=761">this post</a> from the author of these algorithms for more details.</li><ul><li>Equal Interval - As the name suggests, this method will will create classes which are at the same size. If our data ranges from 0-100 and we want 10 classes, this method would create a class from 0-10, 10-20, 20-30 and so on - keeping each class the same size of 10 units.</li><li>Quantile - This method will decide the classes such that number of values in each class are the same. If there are 100 values and we want 4 classes, quantile method will decide the classes such that each class will have 25 values.&nbsp;</li><li>Natural Breaks (Jenks) - This algorithm tries to find natural groupings of data to create classes. The resulting classes will be such that there will be maximum variance between individual classes and least variance within each class.</li><li>Standard Deviation - This method will calculate the mean of the data, and create classes based on standard eviation from the mean.</li><li>Pretty Breaks - This is based on the statistical package R’s pretty algorithm. It is a bit complex, but the ‘pretty’ in the name means it creates class boundaries that are round numbers.<img src="https://lh6.googleusercontent.com/lENrccBtlOlDWoWPBlM4X34BFEf_CJspq4lT74KQNy-uhWX9Df3jLS4IIX_OCop4Gwko309UHyolTpJBjEBDIt0X00BtB9qJ9W8Pr-tSBCaQDIkVXXc" /></li></ul><li>To keep things simple, let’s use the Quantile method. Click Classify at the bottom and you will see 3 classes show up with their corresponding values. <img src="https://lh5.googleusercontent.com/-Dm--0qiTK4f1DtTr_NOuzECg24dGruzNTV2cEP7q65bUhSePgrUN9lTa4u-jl4GjHnYy8nhrV52vGBh_Ninq7i7YuGoxoN7eyyMw5bZTECSbrY7Cdk" /></li><li>Click OK and switch to the main QGIS window. You will see a map showing countries in either of 3 colors representing average life expectancy in the country.<img src="https://lh6.googleusercontent.com/b0LxgEDHSZ-8_eC_KkOwdY2OGMWael533bMHAT_xgeYLPeS8AJT1mLYlaOIvqYpQMEez7V7-efVj0Ab30qOSRl0aMIhQ-lWa4S3auIWGiTsT2TP504M" /></li><li>If you read the description of the Quantile method, you will expect that the number of features in each of these classes will be the same. As always, I would encourage you to verify if the algorithm gave you the results you expect. To verify this, open the Attribute Table for the layer. You will see there are 165 features in the layer. Since we chose 3 classes, we expect each class to have roughly 165/3 = 55 features. You can note the class value of the first class -99.000 - 55.6677. Now sort the attribute table by column ‘LIFEXPCT’ and go to feature number 55. You will see that there are 54 features which have the value less than 55.6677. So that matches our expectations.<img src="https://lh4.googleusercontent.com/a8Nems6qGsXH6D9gJltQ0-03y7SKAUeAKKaIzdJWaDWNpZSn49NKfBH0NFgPF5-7zeIXyxZyznTfUwdoJJHzKYZ-h6T0fcRtsg9jipaB8ICXbpXitJY" /></li><li>Now go back to the Style dialog by right clicking the layer and choosing Properties. There are some more styling options available. You can click on the Symbol for each of the classes and choose a different style. We can choose Red, Yellow and Green fill colors to indicate low, medium and high life expectancy. Similarly click on the Range values to manually modify the upper and lower bounds. We can choose nice round values for our classes. Lastly, click on Label values to give a understandable &nbsp;label such as ‘LOW’, ‘MEDIUM’ and ‘HIGH’ to each class. <img src="https://lh6.googleusercontent.com/BVIe-JzVse9fV2nZ8CrzxJWIACoCjQ-XmfIbi3wGfpM_ITcONwrdjRpi53RveS25nk0wMZgcbF74nhnb3K7BRVmVGzt-G5drKkhruVRXxvIkzIpwbGk" /></li><li>Click OK and see the map in the main QGIS window. This map definitely conveys a lot more useful map than the previous two attempts. There are clearly marked class names and colors to represent our interpretation of the life expectancy values.<img src="https://lh3.googleusercontent.com/f3wqd7zqrtOiJIqZKcA7W1isWNp9-rlQbL1KUxQg-qjOU2PiDVwzl_UzkleKBvuKPMju0JEsyi31atnjus45kPm7FI8_L8F6dNbMKRTKgeeDtmoPhr4" /></li></ul>We will explore many more options and the Rule-based styling method in a subsequent tutorial. Hope to learn about your experience with styling in QGIS in the comments.</div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com8tag:blogger.com,1999:blog-8478705592464727054.post-85921267995013230412012-02-12T17:54:00.000+05:302014-04-14T17:58:01.697+05:30Tutorial: Working with Rasters in QGIS - Mosaicing and Subseting<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc;"><span style="font-size: large;"><span style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;">Tutorial moved to &nbsp;</span><a href="http://www.qgistutorials.com/en/docs/raster_mosaicing_and_clipping.html">http://www.qgistutorials.com/en/docs/raster_mosaicing_and_clipping.html</a></span></span><br /><div><span style="background-color: #f4cccc;"><br /></span></div><div><span style="background-color: #f4cccc;"><br /></span></div><strike>QGIS has basic raster functionality via the GdalTools plugin. This plugin is on by default and available via with ‘Raster’ menu. If you do not see the options under Raster menu, please follow <a href="http://qgis.spatialthoughts.com/2010/10/using-plugins-in-quantum-gis_05.html" target="_blank">this tutorial</a> to find and enable the plugin.&nbsp; In this tutorial, I will explain some basics of rasters captured by satellite sensors and show you how to mosaic and subset imagery within Quantum GIS.</strike><br /><a name='more'></a><strike>The data we will be using is from NASA public domain <a href="http://lance.nasa.gov/imagery/rapid-response/subsets/">NASA/GSFC, Rapid Response</a> imagery. This satellite imagery is from the Moderate-resolution Imaging Spectroradiometer (MODIS) sensor onboard the Terra satellite. I downloaded several FAS 2km subset geotiffs in southern Africa and saved in on my hard drive.</strike><br /><ul style="text-align: left;"><li><strike>Load these images in QGIS. Click on Layers → Add Raster Layer.<img src="https://lh3.googleusercontent.com/t7nxvuMT49JUVhZ5unTev9ZmFkUosik_-HH0pyTfDY6aiK1B8-H424lcx8eJmap7LGqFo4usCxWXjKYQBTVYBDRdOCMZH-wYx4SqnhWfIeGBnOtrKgI" /></strike></li><li><strike>Browse to the directory with the individual images. Hold down the ‘SHIFT’ key and click on the image files to make a multiple selection. Click ‘Open’. You will see the images load up in the Table of Content on the left panel.<img src="https://lh6.googleusercontent.com/exxwNcAI97yVb3IU9Pc_mzzn_DAVaRchAvWaNHiHAz3adsxxdnjx4IRWz7R89-95noX92ow_U9eQEqTaBq0pyYhsq_3X20HdpT5gP6FX_p9hcyRshr4" /></strike></li><li><strike>You will see there are 5 individual satellite images. Right click on any one of the images and click Properties.<img src="https://lh5.googleusercontent.com/dEzDGT4pb8uCeDLS6StogZzb1ySOxhKxn3wL7J_Aq-faoj99U5xvY6gTGx0c7Q7AtkyMzwr2wBBRbTPZb4jS0M_4fx2LGP4ebABdRAduuYwUE0t9ySs" /></strike></li><li><strike>In the Properties dialog, you can examine the details about the image in the General and Metadata tabs. Each raster can be displayed using upto 3 bands - one for each of Red, Green and Blue (RGB) channels. This particular image is a 3-6-7 band combination of the MODIS sensor. This means that the Band 3 is displayed in Red channel, Band 6 is displayed in Green channel and Band 7 is displayed in Blue channel. Since the bands 3-6-7 do not represent the real R G and B sensors, this image is called a False Color Composite (FCC). There is also a True Color version of these images available to download as well.<img src="https://lh6.googleusercontent.com/hk_jBXyt8IyexvhuK9jRXcgUEJFDfll9ggdxcaM_5SFF80BA4v_hsoYZM0Q7hdPie-cCZeVs7hjSkCaXhJ8yoXJOY8xrSnKS9Ylb6pO20a3Hb0MHzMc" /></strike></li><li><strike>Click OK and return to the main QGIS window. Now let us create a single ‘Mosaic’ image from all these individual images. Click on Raster → Miscellaneous → Merge. This menu option uses a GDAL utility in the backend called ‘<a href="http://www.gdal.org/gdal_merge.html">gdal_merge</a>’. <img src="https://lh5.googleusercontent.com/70WikaA_QbvLNIMOwCp-vZlSRd4gPMMgBi2dD0aP40LSR0oy0tRQuz_CrvGgtbNz_Ec-H0QXQU2Q2buyz5UkN4rEioJaYIpNHe8YKkLU1GxNZHoQ9Io" /></strike></li><li><strike>Click Select next to Input files and browse to the directory containing all the individual geotiffs. Keep holding ‘SHIFT’ key and select all of them. Click OK. Next, click ‘Select’ next to Output file and name the output file as ‘mosaic.tif’. At the bottom, check the box next to ‘Load into canvas when finished’. Click OK. You will get a pop-up message saying ‘Processing complete’, once the mosaic is created and loaded to the Canvas. Click ‘Close’.<img src="https://lh4.googleusercontent.com/wdkOob48sJhinJbkF6K2W7eePhvWn2W86IdlXaK0R1WxY1zrm8HKYc9LAEVU_r10Azlkmkx6whbyE_jPJ-qCmCbZKty_e3ieEAbR4-H6S9iKwC8JOx8" /></strike></li><li><strike>You will see that the individual images and now combined and mosaiced into a single mosaic.tif<img src="https://lh6.googleusercontent.com/AOlWg4uyYQxURSAXbCj5xOIlMqiV8mN2v5l47Uiu4zIXlwXFx9scRh-dif9ehI4b3_kidZnZcGLm1ODAdkcSWhtDRbrAJpkV_wgSdl_oyGDGjTxpsvk" /></strike></li><li><strike>Another Raster operation you can do is to subset or ‘crop’ an image. Let us create a subset of this mosaic. Click on Raster → Extraction → Clipper. <img src="https://lh5.googleusercontent.com/qkUm0arjFQUeFCDp9Vwa6UQUOlf_VZe8HqMU6Y7rCvGbSYS5IfeUoJujBYlWI2e29Rszm84e3glujOGG9hdAG8ulXbRYV_5paRDSLUfDvste5gNea5A" /></strike></li><li><strike>In the Clipper dialog, choose the ‘mosaic’ as the input file from the dropdown box. In the Output file, click Select and name the output file as ‘subset.tif’. Now we have to choose the exxtent of our subset by draing a selection in the canvas window.<img src="https://lh5.googleusercontent.com/-4cdSGTfNHWAUGONNULXxazJQvrc7lEOELSmYg_9UfwSRAVLY6PuWPgAh-I37Z0zOF0X1j9Ow68_CVJYKd6n_RlFrGlgyzHz7y5ilIsPHJzEsdAxKDI" /></strike></li><li><strike>Switch to the Canvas window and draw a rectangle selection in the image.<img src="https://lh3.googleusercontent.com/r_0c0unKFKOtKPuPX4GHX4AwSZHLStMXFXLm-gyNqNOH4u__ygJN8x5rwwf-zemzbd2RtqPv4KOyrPRhCxRwYjIuVL0gK6sElXKbnkVDo_MOeoX1RXA" /></strike></li><li><strike>Now switch back to the Clipper dialog and you will see that the coordinate fields are populated based on your selection. If you need to subset using have specific bounding box, you can also manually enter the coordinates here. At the bottom, check the box next to ‘Load into canvas when finished’. Click OK.</strike></li></ul><div style="text-align: left;"><strike><b id="internal-source-marker_0.8376001662109047" style="text-align: -webkit-auto;"><img height="482px;" src="https://lh6.googleusercontent.com/b2vbgXtdjYSlmko02jPeJTqHx3qoEV9coEsLFGw7n1p_CLrzHm6HcATMchBbKP3jc3FQs6k82i0MVCjEnIAy6kPbMNO60VOLVfm_T5dLTB4Wo6Xem44" width="476px;" /></b></strike></div><ul style="text-align: left;"><li><strike>Once the processing is complete, you will see a new layer named ‘subset’ loaded in the canvas. This is your subset image created in the last step.<img src="https://lh5.googleusercontent.com/hqId0_NRG0K4ya7acfWH7i5iII2Ynu3AmYmm5ySelXti2dGlo1ti_OrDDC2wD1H03E1V76tIW_54oK7NfyCOJSSGkSlwEzyq-CBotKO-nlSMzMDellQ" /></strike></li></ul><ul style="text-align: left;"><li><strike>Pro Tip: The Clipper process uses <a href="http://www.gdal.org/gdal_translate.html">gdal_translate</a> utility at the backend to carry out the subsetting task. If you look at the documentation of gdal_translate, there are lots of advanced options. If you wish to use any of these option in the above task, you can click ‘Edit’ button at the bottom of the Clipper window and enter the desired option by typing in. This will be useful if you want to have access to some advanced gdal_translate functionality.</strike></li></ul><div style="text-align: left;"><strike><img src="https://lh6.googleusercontent.com/b_xPyowYXN_bO5DDzTVj0tvh7LcEcdbwtrNSdz4gjZWfJVew-ORbIk9IbSBkwYqeZFAxyypig8wG2wj_0IUI0R95GNbgFOK085sTGnYNKa1gBN9rSIM" /></strike></div></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com25tag:blogger.com,1999:blog-8478705592464727054.post-35516386345563857922012-02-06T20:57:00.000+05:302014-04-14T17:58:46.602+05:30Tutorial: Spatial Analysis - Points in Polygon<div dir="ltr" style="text-align: left;" trbidi="on"><span style="font-size: large;"><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; line-height: 18px;">Tutorial Moved to &nbsp;</span><a href="http://www.qgistutorials.com/en/docs/points_in_polygon.html" style="background-color: #f4cccc; color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;" target="_blank">http://www.qgistutorials.com/en/docs/points_in_polygon.html</a><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; line-height: 18px;">&nbsp;</span></span><br /><strike><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;"><br /></span>The power of GIS lies in analysing multiple data sources together. Often the answer you are seeking lies in many different layers and you need to do some analysis to extract and compile this information.</strike><br /><strike><br /></strike><strike>One such type of analysis is Points-in-Polygon. When you have a polygon layer and a point layer - and want to know how many or which of the points fall within the bounds of which polygons, you can use this method of analysis. For this tutorial, the question we want to answer is ‘Which country in the world has had the most number of major earthquakes?’</strike><br /><strike><br /></strike><br /><a name='more'></a><strike><br /></strike><strike>We will be using 2 data sources. For the points layer, we will use NOAAS’s Significant Earthquake Database and <a href="http://qgis.spatialthoughts.com/2012/01/importing-spreadsheets-or-csv-files-to.html">import the CSV file as a points layer as described in this tutorial</a>. The countries shapefile will be from the <a href="http://www.naturalearthdata.com/">Natural Earth</a> dataset.</strike><br /><strike><br /></strike><br /><ul style="text-align: left;"><li><strike>Load both the 10m_admin_0_countries and earthquake layers in QGIS.The countries layer is a polygon layer and the earthquake layer is the point layer.<img src="https://lh4.googleusercontent.com/B9BkPIz6aAKWahEMHtwpObe9mbPRQ6oa2E1cOIK7E04I29zHZzw730MBrpWtOvER-92yUxbcOfSzV5bWQzzpbm_tPMdvrQ5Xuenpd0fSUp0V-78PkqQ" /></strike></li><li><strike>Click on Vector → Analysis Tools → Point in Polygon<img src="https://lh3.googleusercontent.com/Ho8MypEmL-V1hwDL726s_RlmJuWw-uWa6cl2sit76qeiHcIHPq3eicT_m8zxgHLXE5uYyv51A_7sd0T6ajkwZzsqXU7RwrHoobXHYk0tLQrUMgswh1I" /></strike></li><li><strike>In th pop-up window, select the polygon layer and point layer respectively. Browse to a path in your hard drive and name the output layer as earthquake_per_coutry.Click OK. ( Be patient after clicking OK, QGIS may take upto 10 minutes to calculate the results ). When asked whether you want to add the layer to TOC, click ‘Yes’.</strike></li></ul><div style="text-align: left;"><strike><img src="https://lh6.googleusercontent.com/4J9VzSOB2HhCNDOoW5vK7Yq2-5RFKUozlLiTzsagQZP5vMb1z9XkLJ_USPwuzZ4SQvL7dKlqxglw4CtuKLFdpYfxfro8Gqs5U6ZGz45w74n7XDBU9KA" /></strike></div><ul style="text-align: left;"><li><strike>You will see a new layer is added to the table of content. Open the attribute table by clicking on ‘Attribute Table’ icon as shown.<img src="https://lh3.googleusercontent.com/pHWjpIcU0cOePp2bYX-ARBCMOaEiA20hz7UPz76K_8xT1xVuNCKZC_HdWENbpbxEFOEKw-L2RH3eWCHlpg-_Og9UO50hmeTYdYSi8NsfkkbzCcRIh4k" /></strike></li><li><strike>In the attribute table, you will notice a new field named ‘PNTCNT’. This is the count of number of points from the earthquakes layer that fall within each polygon. <img src="https://lh3.googleusercontent.com/PsS9Rqwln8E9L3PIGlVDgfYwXyRIuiGrMrm8oyWb5mBVnGaHsF_ZAOr9l5vLBQTjvUHo3AF001mtX-hb7ZunmWTteEJBED92WlOWuqLHMt0mlFWbX9I" /></strike></li><li><strike>To get our answer, we can simply sort the table by PNTCNT field and the country with highest count will be our answer. Click 2-times on the PNTCNT columnto get it sorted in descending order.<img src="https://lh5.googleusercontent.com/mk2ihTaTtDbbUVVMovx6ZkhluOsHCeqtQ3jriAUaCrc0ZhUzoqzsWtLfkdilcxDE88XqunHxA0w2hzlo7NIymVVTDy5B0v1H77CwmdDkH03FGBdzg7Y" />So we have determined from the simple analysis of 2 datasets that China has had the highest number of major earthquakes. You may refine this analysis further by taking into consideration the population as well as the size of the country and determine which is the most adversely affected country by major earthquakes.</strike></li></ul></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com22tag:blogger.com,1999:blog-8478705592464727054.post-18278969962264749702012-02-03T17:26:00.000+05:302014-04-14T17:59:36.694+05:30Tutorial: Georeferencing Topo Sheets, Topo Maps, Satellite Image or Scanned Maps in QGIS<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: medium;">Tutorial moved to &nbsp;</span><a href="http://www.qgistutorials.com/en/docs/georeferencing_basics.html" style="background-color: #f4cccc; color: #4d469c; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: x-large;" target="_blank">http://www.qgistutorials.com/en/docs/georeferencing_basics.html</a><br /><div><span style="background-color: #f4cccc; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: medium;"><strike><br /></strike></span></div><strike><br /></strike><strike>Most GIS projects require georeferencing some raster data. In this tutorial I will discuss the concepts, strategies and tools within QGIS to achieve a high accuracy georeferencing. </strike><br /><strike><br /></strike><a name='more'></a><strike><br /></strike><strike>Georeferencing is the process of assigning real-world coordinates to each pixel of the raster. Many times these coordinates are obtained by doing field surveys - collecting coordinates with a GPS device for few easily identifiable features in the image or map. In some cases, where you are looking to digitize scanned maps, you can obtain the coordinates from the markings on the map image itself. Using these sample coordinates or GCPs ( Ground Control Points ), the image is warped and made to fit within the chosen coordinate system. For advanced georeferencing using another georeferenced image or OpenStreetMap data, see <a href="http://qgis.spatialthoughts.com/2013/02/tutorial-advanced-georeferencing-in.html" target="_blank">this tutorial</a>.</strike><br /><strike><br /></strike><strike>The data we will use for this tutorial comes from the excellent <a href="http://www.hipkiss.org/data/maps.html">Hipkiss’s Scanned Old Maps</a>. There is a vast collection of out-of-copyright scanned maps that one can use for research. For this tutorial, we will use a <a href="http://www.hipkiss.org/data/maps/william-mackenzie_gallery-of-geography_1870_southern-india_3975_3071_600.jpg">1870 map of southen India</a> and geo-reference it using Quantum GIS. Download this JPG image and save it on your hard-drive.</strike><br /><ul style="text-align: left;"><li><strike>Georeferencing in QGIS is done via the ‘Georeferencer’ plugin. If you do not already have it, see <a href="http://qgis.spatialthoughts.com/2010/10/using-plugins-in-quantum-gis_05.html">this tutorial </a>for finding and loading plugins in QGIS.<img src="https://lh6.googleusercontent.com/b_UglS0jjY5Js5lAWKu6KcxkO5t8gssSZXQ9gVg8x44Yftju3xFJYMmMhPSA3PGVwkrT63-MGK6wcZuFDAlsHqBtOTcsxcWJZ6IfqQA1TeqOxGTl73w" /></strike></li><li><strike>Open the plugin from Plugins → Georeferencer → Georeferencer. A new plugin window like below will pop-up. The plugin window is divided into 2 sections. The top section where the raster will be displayed and the bottom section where a table showing your GCPs will appear. If you wish, you may drag the GCP window and separate it from the top section. Now click on the ‘Open Raster’ button on top-left corner.<img src="https://lh4.googleusercontent.com/58598pOTxQp55n623Xd-sqcQWydQ-qgUhzhGqeEAF5jfdUGrcSiJR1WbbJXvl7KMnK8I2-9j7SageboFaRNPbZK7H4fKyHo2UwgaTZH0JpaxwQwycxE" /></strike></li><li><strike>Browse to the JPG image of the scanned map and click Open. In the next screen, you will asked to choose the raster’s coordinate reference system (CRS). This is the projection of your control points. If you have collected the data using a GPS device, you would have the WGS84 CRS. If you are geo-referencing a scanned map like this, you can obtain the CRS information from the map itself. <img src="https://lh5.googleusercontent.com/iN9UPe4DpxWRIv17q_wB0rlswtmZTc4dWzK62-vOmCNA7ybU1ljB5YOPAAPnJ5O9-e0FD6BbEBcrHqK1eenrf7S_fI9O-UmfuJYwmWsywhs96CCQ3e8" /></strike></li><li><strike>Looking at our map image, the coordinates are in Lat/Long. There is no datum information given, so we have to assume an appropriate one. Since it is India and the map is quite old, we can bet the Everest 1830 datum would give us good results. Click OK.<img src="https://lh6.googleusercontent.com/DvYC2ogqJtPcnxCpNJqM8fQDaGrSc4K95hqscJlNOwMlQWwqHwR2cbF_tUl98g-C7pkfEGYkNg7_YbaNyBH1qfss2Xlwuwlb7NLKKxsp6oT63izIWzQ" /></strike></li><li><strike>You will see the image will be loaded on the top section. You can use the zoom/pan controls in the toolbar to learn more about the map. <img src="https://lh6.googleusercontent.com/zTrQjim8OT3euilirxtg5fUuvi3Cz0Q5yjWMNXyQ4kwZLKTSQt7G_6hxLlvIC2uniITIpYQgrNZ9bbC8T1ZDWw3R4rxCONuqMR4YtmnJIlYireQadUQ" /></strike></li><strike><br /></strike><li><strike>To assign coordinates, we need to use the map grid on the image. If you zoom to bottom-left corner, you will see markings for 70° longitude and 5° latitude. So we can determine that the real-world coordinate at the intersection of these grid lines will be (70,5). Remember that X=longitude and Y=latitude. Now click on ‘Add Point’ button to add these coordinates. Once selected, click at the intersection of the 70° and 5° grid line.</strike></li></ul><strike><img src="https://lh4.googleusercontent.com/ZGAjy1P4oSV-nu9FnTtdd4CgBdf6YmMzUAKBQIMzK-5--ms0WySVf25kdpMpDhd7TREyQbovQUIj9it8khIDsibu2XfxXvwtOdT07hdgnT0-OvcwmVc" style="text-align: left;" /></strike><br /><div class="separator" style="clear: both; text-align: center;"></div><div style="text-align: left;"><ul style="text-align: left;"><li><strike>In the pop-up window, enter the coordinates. Click OK.</strike></li></ul><div><strike><img src="https://lh6.googleusercontent.com/EwyjWggSVWduuKu-iAIwZ64IAOUfBZYgvt8ieOwtyNFo6hrIi5DZv8-i-x6wLmle4k7PtOo_iBCY4KP2wraG6InJTjj3GjXrn_JfCOvUDbOdDDhoqvg" /></strike></div></div><strike><br /></strike><ul style="text-align: left;"><li><strike><span style="text-align: center;">You will notice the GCP table now has </span>a row with details of your first GCP.<img src="https://lh5.googleusercontent.com/bu_Fh7jBIAHqi3fqKGtXds1aFB9elJgaQVTizFhwqcahHVx42dEei-C2yHaqw1GrRTF0B8L4nao3k1oeu8jB-BKR3i8ZaB604LTXq4Vd0Q46UKBCzuY" /></strike></li><strike><br /></strike><li><strike>Similarly, take GCPs at all 4 corners of the image where you have grid intersections. The more GCPs you have the better. Once you are done, click on Settings → Transformation Settings.<img src="https://lh4.googleusercontent.com/u5PLMpwMsej1ERKF2bWZqBht78XemCilk5lou0KSBDHXlpprzxH27UWX9eUkbyBLP1NDAojBuJvCdISCK1axel1kVY52RnqrcJK1VtorBQmTmdMUxVQ" /></strike></li><ul style="text-align: left;"><strike><br /></strike></ul><li><strike>In the Transformation settings dialog, you will have to choose multiple parameters. To keep things simple, choose following parameters. We are setting out ‘Target SRS’ as WGS84, so the resulting geotiff file will have a CRS of WGS84. Make sure you check the ‘Load in QGIS when done’ button at the bottom. Click OK.</strike></li><strike><img src="https://lh6.googleusercontent.com/-XLRUpQ-e4vyfqRIq1jb8bZdlUsm-k61bw_6z7aroiizrNLlAjYs0rtacJpkicJh7smteOuTQIrWN18C8JDpj946vI1Onlo-bZJiBhkCEewOV5AU5Gg" /> <br /><br /></strike><li><strike>Now click the ‘Start georeferencing’ button from the toolbar. <img src="https://lh4.googleusercontent.com/9771tOPoHc9QW_qq69y5BH5949cUM57qvnk0dkTA64_iw3mNOMEwDubfSR7rd-NsYeJKcHTUotVKMUKmcoyj8-Dinr0ZF8siqSa9TiahhV1ljnZ39GI" /></strike></li><ul style="text-align: left;"><strike><br /></strike></ul><li><strike>Once the process is complete, you will see the georeferenced geotiff image loaded in your QGIS canvas.<img src="https://lh5.googleusercontent.com/SDmproNWkOrwHxi_EYPCU-uq4drdLQ9Xd_IcOeD5fLj6W5v-MbnRQbFtvJdx4UTrY4hFfylYDvXnlX8FNQ36g-_HdmBJocUlF30xM5rTII8jw23QMz4" /></strike></li><ul style="text-align: left;"><strike><br /></strike></ul><li><strike>The georeferencing is now complete. But as always, I encourage you to always verify your work. How do we check if our georeferencing is accurate? In this case, load the country boundaries shapefile from the <a href="http://naturalearthdata.com/">Natural Earth</a> dataset and compare them. You will notice they match up pretty nicely. There is some error and it can be further imprived by taking more control points, changing transformation parameters and trying a different datum.<img src="https://lh6.googleusercontent.com/8wbMGe6PoRggUEecySHTUd0askGXq6XAaTxDxqXi0jKDvOcXPbKyLFV68zHP3sWxIsqITvhwEAtmmB4Ia_4hbid-MY578AS_a7ipJfAMcdt4JKQDfUk" />Hope you are able to learn this and achieve a good georeferencing with your own data. Let me know in the comments how did it go.. Check out the new tutorial <a href="http://qgis.spatialthoughts.com/2013/02/tutorial-advanced-georeferencing-in.html" target="_blank">Advanced Georeferencing in QGIS using a Reference Layer</a></strike></li></ul></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com28tag:blogger.com,1999:blog-8478705592464727054.post-54130474111315017232012-02-01T19:26:00.002+05:302012-02-01T19:26:56.101+05:30Tutorial: Selecting Multiple Features in QGIS<div dir="ltr" style="text-align: left;" trbidi="on">When working with GIS data, you might want to delete certain features or run your query on a subset of features from a layer. There are many methods available that can help you save time and select a large number of features easily. I will cover some of these in this tutorial.<div><a name='more'></a><br /><ul style="text-align: left;"><li>The dataset I am using is the 10m_admin_0_countries shapefile from the <a href="http://www.naturalearthdata.com/">Natural Earth</a> dataset. To get started, load the shapefile in QGIS.<img src="https://lh6.googleusercontent.com/otxuLx0v_98-a5j0rzaxMPSIRA2Gzwnsfsc0GkidcHQPkd_IiVOgLjqEwQGpPDZTvsjtZesDafRCeYREH1Zf8Cx6n_VxFn9PwcWIjuTvWoBxgPQ-vcY" /></li><li>Make sure you enable the ‘Attributes’ toolbar for easy access to some of the selection tools. Right click on any empty space on the toolbar area and turn on the checkbox.<img src="https://lh5.googleusercontent.com/J8Q_OXG_2cWf8-QKX2uYih7LsgpZ5ZEzFRdezVgGbGCUbyM4hE6ejvxpSfT8lvoeKadzep5ZDkF4BewsRk3naGcsveE1bL5uulfZ-IeaoFl9Oj_BmdI" /></li><li>A lot of selection tools are available under the Selection menu. You can access this via the toolbar as shown below or by going to View → Select.&nbsp;<img src="https://lh3.googleusercontent.com/sTY74yu-ORKcPHrtXR0AJ3TJq6q5l2BUC8C164uH3gT46h41XYWgRSduNavaTFsmcc-a2qFdV2nnba0wHx4-go41BV7N6nmieuonbAufh26gs6M7T-Q" /></li><li>There are multiple options, <i>Select single feature, select features by rectangle, select features by polygon, select features by freehand </i>and <i>select features by radius.</i> You can choose any one of them and click on the canvas to draw a shape and select features that intersect the shape. Most of these are obvious, but we can try ‘select features by freehand’ for an example. Select it and draw a shape while holding your left mouse button. Release the button when you are done and you will see a selection appear on screen.<img src="https://lh3.googleusercontent.com/GTUG3D0zeZ8DkvXQB0ik-SEhC0T_seRXynaIwV4vzPX11_IHV1F2pcTXJMpFAqkZUG_9zQcYUGcKe06axl8RMMWfrRDronffcnFCVxMXh6S8rCEiuUU" /><img src="https://lh6.googleusercontent.com/uFZQIPnIQmAkkD9MAzJya5Uwn7Ehzes95wkH1mnRgUy9YjsnTVf5Dl0QsOAZttPEw7uoVlKK5LMZgkJiX_l1cMG6tKR2Fb_zfE7CgUHTYS4fwNGNczk" /></li><li>Another way to make multiple selection is holding down the Ctrl key and making the selection. You can use any selection method for this. Let’s use the ‘select single feature’ method. Choose that and click on other features that you want to select while holding down the Ctrl key. This will add these features to your selection.<img src="https://lh4.googleusercontent.com/lyPIZ_fgdmeWQWyCqv03MWyV0x0hb8Ehq9sPcoqqSnebFN8lz37gcOpYrSYz8EDtZWjRrgxHY2xUwcok-j5H5Mt50FSyYqgzBgPVZSB-TowGwxkTrEw" /></li><li>If your selection method is not spatial, but more attribute based, you can use SQL queries to make your selection. (See <a href="http://qgis.spatialthoughts.com/2010/10/working-with-attribute-table-basic.html">this previous tutorial</a> for a detailed step-by-step guide on attribute table.) For example, if you wanted to select all countries in the world which started with the letter ‘A’ or ‘B’. This can be easily accomplished by using the Query Builder. Open the Attribute Table for the layer by going to Layer → Open Attribute Table.<img src="https://lh6.googleusercontent.com/1Hp8KnNXjkxaZqNmn-W7eFjdEsnu6HhVqYceNsS2_rzkaqGMoEETmmF11v26DVxljP02CwajtBdIvlzZBXlLMMjOELBFySs1Ftvzm0UvDAUc7sJsBBw" /></li><li>Open the Query Builder by clicking ‘Advanced’ at the bottom.<img src="https://lh4.googleusercontent.com/5zwqY-SseAomYfKx9Fnp07Fx0cLkc-JWQotsr8s4Sb1Y1p1_5XCKDGP6nix3Cd87UGOS9JRL45RNpNVs1gIk8872FoF0MyWDurN-13KAbkwh73jjMCI" /></li><li>Formulate your query. We can use the % wildcard along with LIKE operator to specify our query. Enter the query and click OK.<img src="https://lh6.googleusercontent.com/XuRlnypT9DQV6AXKVAHwn1Ibyek5wTeHvKTXyhSBZR03qP9dWZoUu-hkKNigmTz0ztVbhLGYmDBfsN9_-j93OskhArswP9aGezgCTJCFJK6LwbHzP_U" /></li><li>You will see a selection appear on the canvas highlighting all countries whose name start with A or B.<img src="https://lh6.googleusercontent.com/aAs8Huugpt1h6LthZWoVVo4ZWEpJnn4rI71UCG0k-3Dw0jaLMxFJHdmg7UTqmjHayDWoLcSMSiPqbV_JVLe0NNYrCWyq4QhQWD9HQIvd5TlphlGTUVw" /></li><li>These were some of the ways of selecting multiple features in QGIS. If you are working with multiple layers, you can also use Spatial Queries to make selection based on features in another layer. <a href="http://qgis.spatialthoughts.com/2011/12/tutorial-performing-spatial-queries-in.html">See this tutorial</a> for a run through of this process.</li></ul><br />Do leave your comments and share your favorite tricks for making selection easier in QGIS.</div></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com2tag:blogger.com,1999:blog-8478705592464727054.post-54487241864241006872012-01-20T11:50:00.000+05:302012-01-20T11:58:19.864+05:30Tutorial: Setting Up A Working GRASS Environment in QGIS<div dir="ltr" style="text-align: left;" trbidi="on">GRASS is a popular open source GIS toolkit and has a large number of useful raster, vector and terrain tools for GIS analysis. You can use these toolswithin Quantum GIS with the GRASS plugin. Unfortunately, GRASS is fairly unintuitive for beginner GIS users and it can be daunting to use these tools. In this tutorial I will show you how to setup a simple and generalized working environment that will enable GRASS tools to be used within QGIS. <br /><a name='more'></a><br />I will not go in-depth in the concept of a GRASS database, mapset and location. These concepts are useful when setting up a multi-user environment in a project setting, but for most beginners and single-person setups need not worry about learning the nuances of these concepts.<br /><ul style="text-align: left;"><li>First make sure the GRASS plugin is loaded and enabled. If you do not see GRASS under plugins, please follow <a href="http://qgis.spatialthoughts.com/2010/10/using-plugins-in-quantum-gis_05.html">this tutorial</a> to find and enable the plugin. Once enabled, go to Plugins → GRASS → New mapset<img src="https://lh3.googleusercontent.com/7deyZHusjeDdBX4MRVj1uPIpFMzAfkh8XT-XEfJ1-Sd6zcXwZOv6OtBd9x2yIkxhsTInfcgZgBSHIx8Z--Ehi34Wf1YNIGRxH2fFi8D7fWJonnc05q0" /></li><li>In the pop up window, click on Browse and go to a directory where the GRASS data would be stored. This is called a ‘Database’ in GRASS lingo and contain all settings and layers for a particular project. Click Next.<img src="https://lh4.googleusercontent.com/Y4N9owTA8ovutWb4FJ2d-vK6_3cQZYm_2FbIZqiXt-bk4l2ZkGxs8nWmX1pbKuS0iSA1CsuoaJOaY88p8nqxoQJPk9h05xdMNjk2WtFARhkM0J8LegY" /></li><li>In the next window, you will be asked to create a new location. Since we are creating a generalized workspace, you can name it ‘World’. Click Next.<br /><br /><img src="https://lh4.googleusercontent.com/v-VdPNz5MrFR3dZWh9dAJ60Cm7qGv51VhOCFRDR4y1hOEX4fo9dZiVHQDiGtAQO3mEDeqsXRkgxqJ4109wd1hQxtf_opUAc-mAxjWYe5sbR9CTuq3GU" /><br /></li><li>Next, you will be asked to define a projection. This is very different from traditional GIS systems where you can work with data in different projections simultaneously. In GRASS, the projection of your project needs to be defined upfront and all data that you import to GRASS would be re-projeccted to this projection. If you have a specific projection for your project, you may choose it here. For most beginners a WGS84 CRS would be sufficient.</li></ul><img src="https://lh5.googleusercontent.com/YwiK4knSSla2pQ4Dl7XPYcLDD3VNEVfLO4t0LEMN3mmJSwfh00wdBXI3f6tohI3YoIBlWBrZ8djcp_9CBSTYlLgE24e4mFx4ROHtpFJvk9PLh6a1H1k" /> <br /><ul style="text-align: left;"><li>In the next screen, you will be asked to select a GRASS region. Again this is not how most GIS systems work. In GRASS, you have to pre-define the extent of the geographic area for your project. Any layer with data outside this region cannot be imported to GRASS. Unless you have a specific reason, you should leave the region to the default global extents. Click Next.<img src="https://lh5.googleusercontent.com/UHVUUMWC6nwI-Me0oGOxxS3TMesai-xibGE-zRpEMN5D05SYgNXPikMgJAexX3GAgdhuZLA-PqFB4bY8abnDOr1GPh_vkZVadV45-2wEhwp6CrWUzkU" /></li><li>Now you will have to name a mapset. For single users using GRASS for simple analysis, this should not matter. You can simply name it ‘World’ and click Next.<br /><img src="https://lh5.googleusercontent.com/PuWI4eUIjKJFrovuYJ48x-wXtntkB2gUwPFAoWmBshCni8hakWfliAC6k5w-zXG_OCiS0u4w3oYcYarf7LUu8Yx8AMstpLBi5Wz6BD0933SPMHeHpKw" /> <br /></li><li>Click Finish in the next screen and you will get a confirmation message that saying your new mapset has been created.<img src="https://lh6.googleusercontent.com/uRRxQSpMUWYaOL32jVqwO10E2fiSZCS_48o2Lbecvd4HOt39RHa5l3Ljgpj8nfymLZxE2NHilRvfgYnlg2omR9Woj_OyxqRjzAVIlALk9SMTWCGdIXs" /><img src="https://lh4.googleusercontent.com/3l4nfaS5c15Hdo2gqvX4lbD-334mmpX8_48LoiQ-WUyY8RzAD8P8UHTeQ_v2AsnZqh4oxiD_bdqMVwxb5BcP-l6gZQg3CeUSskzAlKegkN2Ygc8p7WU" /></li><li>Now if you go to Plugins → GRASS , you will see that a lot more options are now enabled. Before we can start using the tools, click on ‘Edit Current GRASS Region’ option.<img src="https://lh6.googleusercontent.com/932J5DYTBzrA0PJ-YrkaQRTIjEZQoPtTd9PqOsQuK8kqc3jg9vR7PTjB31xAeFvJsocTui0aLlF8X_6QQa92GaHZS8VwGKsRXlnxNKobqwipZX_qFeY" /></li><li>You will remember that we had an option to set the project extents when setting up the new mapset. But you will notice some more option in this screen. There is an option of setting the ‘Resolution’. This is important when working with Rasters. If you create rasters in your GRASS project, the resulting resolution will be determined by this setting. For this project let’s set the X and Y resolution to be 0.1.<img src="https://lh3.googleusercontent.com/WIngqsAC6JQVrKBevVbCi_2yRvR7xzStIwGd1H_-dlrErHDELqZ_glvfL4UKH_kjrUUC4olNgtJc41xj102YXlhexSCGmeZ2Sc2fk3liDZKlLOmEeIU" /></li><li>Now you are all set with yourr GRASS environment. You can explore the GRASS Toolbox under Plugins → GRASS → Open GRASS Tools. These contain rich set of tools that can tackle even the most complexx GIS Analysis. This is akin to the Arc Toolbox you may have used in ArcGIS. I will show you how to use some of these tools in subsequent tutorials.<img src="https://lh4.googleusercontent.com/QoH9lt071qAG3EFIiDh7x_3__ISiicblfjb-fil3tcQefEhPECVuogzMqfI3cnburBQlnZu2mm-3ZjF1LoOzfLv2ONK82Gm9n46rFJT4lMqxwwC7Plo" /></li></ul></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com9tag:blogger.com,1999:blog-8478705592464727054.post-87030522817104031642012-01-11T21:00:00.002+05:302014-05-22T13:02:24.988+05:30Tutorial: Importing Spreadsheets or CSV files to QGIS<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #ea9999; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: large;">Tutorial is updated and <a href="http://www.qgistutorials.com/en/docs/importing_spreadsheets_csv.html" target="_blank">moved to a new location.</a></span><br /><div><ul></ul></div></div>Ujaval Gandhihttps://plus.google.com/116912222767108657277noreply@blogger.com28