Walkthrough: Clipping and projecting vector data with QGIS and OGR | GEOG 585: Web Mapping
This walkthrough will first give you some experience using the GUI environment of QGIS to clip and project some vector data. Then, you’ll learn how to do the same thing using the OGR command line utilities. The advantage of the command line utility is that you can easily run it in a loop to process an entire folder of data. This project introduces some data for Philadelphia, Pennsylvania that we’re going to use throughout the next few lessons. Most of these are simple basemap layers that I downloaded and extracted from OpenStreetMap, however the city boundary is an official file from the City of Philadelphia that I downloaded from PASDA (link is external). That was easy enough, but it would be tedious, time-consuming, and possibly error prone if you had to do it for more than a few datasets at a time. Let’s see how you could use the OGR command line utilities to do this in an automated fashion. Remember that OGR is the subset of the GDAL library that is concerned with vector data. When you install QGIS, you also get some executable programs that can run GDAL and OGR functions from the command line. The easiest way to get started with these is to use the OSGeo4W shortcut that appeared on your desktop after you installed QGIS. If you know that you’ll be doing the same series of commands in the future, you can place the commands in a batch file. This is just a basic text file containing a list of commands. On Windows, you just save it with the extension .bat, and then the operating system understands that it should invoke the commands sequentially when you execute the file. Notice that these are just the same commands you were running before, with the addition of a few lines at the beginning to change the working directory and set the path of the ogr2ogr utility. Batch files can use variables just like you use in other programming languages. You set a variable using the setkeyword, then refer to the variable using % signs on either side of its name (for example, %ogr2ogrPath%). Variables created inline with loops are represented in a batch file using %% (for example, %%X), a slight difference from the syntax you use when typing the commands in the command line window. You will use this data in future lessons. Therefore, do the following to preserve it in an easy-to-use fashion: This courseware module is part of Penn State’s College of Earth and Mineral Sciences’ OER Initiative (link is external). Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License (link is external). The College of Earth and Mineral Sciences is committed to making its websites accessible to all users, and welcomes comments or suggestions on access improvements. Please send comments or suggestions on accessibility to the site editor (link sends e-mail). The site editor may also be contacted with questions or comments about this Open Educational Resource. The John A. Dutton e-Education Institute is the learning design unit of the College of Earth and Mineral Sciences (link is external) at The Pennsylvania State University (link is external). 2217 Earth and Engineering Sciences Building, University Park, Pennsylvania 16802 (link is external) 877-778-4471 | Contact Us Privacy & Legal Statements (link is external) | Copyright Information (link is external) The Pennsylvania State University © 2014 Source.