Sunday, January 17, 2016

Learning QGIS - a simple tutorial

One of my goals for early 2016 is to learn how to use QGIS, a freely available open source Geographic Information System.

I have been an ArcGIS user for years, and consider myself fairly proficient. If you're a student and your university has a site license for ArcGIS, you can actually get a free personal license, good for one year from the date of install. The ability to have ArcGIS installed on my personal machine, and not having to rely on remote desktop connections, really helped facilitate my research during the last couple years. I have an Apple laptop, but I found that if I allocate sufficient memory (4 GB) and hard disk space to my Windows virtual machine, I can run ArcGIS quite happily. ArcGIS is extremely powerful, but it is also prohibitively expensive for many individuals and for small organizations, and is also Windows-only at this time. I am not sure where I will end up working at this time, and I certainly cannot assume I will have access to ArcGIS when I get there. As such, I feel that it behooves me to learn alternative solutions for any GIS needs I have.

QGIS provides many of the same powerful analysis tools as ArcGIS, thanks to its integration with other open source GIS tools, such GDALGRASS GISPostGIS, and MapServer.

GDAL is a translator library for raster and vector data, allowing you to transform your data into a number of different projections (coordinate reference frames) and data formats. It can generate hillshade, compute statistics on a grid file, etc.

GRASS GIS provides a lot of the analytical, modeling, and image processing tools found in QGIS. The difference between GRASS GIS and QGIS can be confusing as GRASS GIS can be also used as a standalone GIS. Earlier versions of GRASS did not include a GUI; commands were run via a command shell and results were displayed using the X11 windowing system. QGIS interfaces directly with GRASS to provide a nice user-interface, that folks already familiar with ArcGIS might be more comfortable with. Also, to my knowledge GRASS does not integrate directly with MapServer. Early versions of QGIS did not integrate with GRASS. Those early versions of QGIS could still handle a lot of GIS needs, but it did not have a lot of the analytical tools that GRASS did.

PostGIS brings geospatial capabilities to PostgreSQL databases, allowing you to run queries and perform database operations based off geometries, locations, etc. This tool is what provides QGIS with its database capabilities.

MapServer allows for the publishing of geospatial data on the web, and provides a suite of interactive mapping tools. QGIS uses MapServer to allow you to publish your maps to web.

The most recent version of QGIS (v. 2.12) brings together these individual tools, along with a number of others, in a nicely packaged open source software that is a serious competitor to ArcGIS.

My first project:

For my first project, I decided to create a map of the Discovery Transform Fault.

To create this image:
  1. I brought in an ASCII Grid file (.asc) of the bathymetry data, using Layer --> Add Layer --> Add Raster Layer. This brings the grid file in as a grayscale image.

  2. To change the color, double-click on the layer, then go Style --> Render Type --> singleband pseudocolor. Now you can select your colormap, choose between continuous and discrete modes, create classes, and adjust your bounds just as you can in ArcGIS.

  3. You can create the hillshade effect by going to Raster --> Analysis --> DEM. Under mode you will find options for computing slope, aspect, hillshade, etc. 

  4. Once your hillshade layer is created, move it down below your grid layer in the layers panel. Then, go to Layer Properties for your grid, and set a transparency so you can see the hillshade through the data. 

  5. The plate boundary line that you see on the map was brought in as a geotiff. To make the white background transparent, you go to Layer Properties --> Transparency and set the RGB values to 255.

  6. Next I added the earthquake data, the purple circles that are sized by magnitude. The earthquake data was in a comma-separated file (.csv) so I went to Layers -->Add Layer --> Add Delimited Text Layer.

    QGIS does a great job of reading the file and determining that the first row of data is actually the header row. I simply selected which columns represented the X field and Y field and clicked OK. It then asks you to choose a Coordinate Reference System (CRS) for the data. Select the appropriate projection, hit OK, and the data should show up on your map.

    To size the points by magnitude (you can also color by attribute as well), double-click the layer to bring up Layer Properties --> Style and change Single Symbol to Graduated. Under Method, select size, and for Column, select the attribute (in my case "Mw") that you want to size by. Now you can choose what mode to break by (equal interval, natural breaks, pretty breaks, etc.).

    As with any context menu, you can hit "apply" before you hit "OK" to see how the data will look before you completely exit the menu. 

  7. Now that we have all the data in QGIS, it's time to make the actual map. First, hit the New Print Composer icon (white rectangle w/ yellow asterisk) or go to Project --> New Print Composer.

  8. Select Layout --> Add Map, and then drag using your mouse or trackpad to draw a box where you want the map to appear. Once you let go on the mouse or trackpad, your data will pop into view. You can adjust the visible bounds of your data under Item Properties.

  9. Under Item Properties for the Map object, you will also find options for adding a geographic grid, or graticule, as I did above.

  10. The Add Scalebar and Add Legend options are tucked away under Layout. Each time you choose to add an item under Layout, you'll need to draw a box on your map so the composer knows where to place it. You can always move these items after the fact.

  11. If you do not want all your layers to show up in the legend, simply uncheck Auto Update under Item Properties and the select the layer you wish to remove and hit the minus icon. The icon of the pencil on the paper allows you to edit the names of the visible layers.  The legend item has a "columns" option under Item Properties. This will enable you to have your layers added side-by-side, versus stacked vertically. The icon that looks like a funnel with filter the legend by map content. For my map, this meant that for certain sized earthquakes not visible in my map extents, the corresponding legend entry was removed.

  12. before filtering legend for map content

    after filtering legend for map content

  13. Once you have your map the way you want it, you can easily export it as an image, PDF, or SVG file.

One thing I noticed was that even though I used a continuous colormap for the bathymetry data, the legend shows the colorbar as discrete color blocks. It would be better show a gradual change in color from blue to red. When you first set the colorbar for the layer, the icon for the spectral colormap does show this gradation of colors, so this should be something QGIS can do. I haven't looked into this too much yet, but if I find a solution, I'll post about it.

For a lot of helpful QGIS tutorials, complete with downloadable datasets so you can easily follow along, check out They start out with tutorials on basic map-making and go all the way through advanced statistical analyses of your data. It's a tremendously useful site if you really want to learn QGIS.

Thursday, January 7, 2016

AGU and Post Docs

Well, my re-dedication to my blog hit a brief snafu as AGU ended up being crazy as usual and last minute postdoc applications (*fingers crossed*) took up the rest of my time.

AGU was fun, as always, and completely crazy due to the sheer number of talks and posters, as usual. It was great to meet up with friends, catch up with colleagues, and, of course, catch some great talks and posters.

I presented a poster on my global characterization of mid-ocean ridge transform fault structure and the relationship between fault segmentation and the underlying fault thermal structure, which controls the width of the seismogenic zone. You can view and download a high-res PNG version of my poster here: AGU poster.

Below is a low-res screen grab:

It is stuff I have presented before as preliminary results, but the work is now finalized. I have been working on my global characterization of fault structure for a few years now, updating it as new versions of global bathymetric grids become available. My committee and I decided to hold off on publishing it until we finalize the scaling relation work, as combining the two makes for a much stronger paper. Of course, all of this is now published in my dissertation. Writing this all up for publication in a journal will be one of my top goals over the next couple of months.

Speaking of my dissertation, a link to the PDF document be found here: Dissertation. ProQuest has the final version, and once it is officially published online, I'll write a new post and include the direct link.

Oh, due to said postdoc applications, my AGU poster ended up being put together much later than anticipated. I ended up using AGU's own poster printing services provided by Copy Central. For $119, I received a high-res full color 3' x 5' poster printed on heavyweight paper. It looked amazing, and for the convenience of picking it up at the conference the morning of my presentation, it was worth every penny. I highly recommend their services.