Saturday, March 9, 2013

Clipping shapefiles in QGIS


This next assignment focuses on using QGIS to clip one shapefile with the selection of another, and also to join a shapefile with a .csv data file in QGIS.

Goal: To make a make a map in QGIS that shows ACS data for a zip codes within a particular county. It's fairly complicated, but here are the overall steps:
  • Download shapefiles for the county and the zip codes.
  • Clip the zip codes file to include only those for the county you care about.
  • Download the ACS data and clean it up for your purposes, then save it as a csv file.
  • Create a csvt file to define the columns so QGIS understands them.
  • Join the ACS data to the modified shapefile.
  • Style the map so you can see the variance in desired data.
Now for some detail:

THE SHAPEFILES

  • Work on the shapefiles first. Download the shapefile for ZIP Code Tabulation Areas for your state. (2010 data is fine). Same for County (and equivalent). You can find them at the Census Bureau's Tiger/Line site.:
  • Open the Counties file and then the Zip Code file. Move the Zips on top so and change the properties of the layer so it is transparent and you can see the counties underneath.
  • Open the Attribute Table for the Counties file and use the search to find your county. (You might want to click the “Show selected Only” box.) Close that attribute window
  • Now your county is selected. You can go to Vector > Geoprocessing Tools > Clip. Remember to cut up, so the Zips are on top. Use only the “selected feature” from the county layer. You’ll need to browse to where you want the file and name it. Do it. Go ahead and add the layer to your workbook.
  • Now you have zip codes for only your county! You can remove the other layers.

THE DATA

  • Go to the American Factfinder.
  • Go to the advanced search. Set your geography to 5-digit Zip code Tabulation area in Texas.
  • Find a table you are interested in. You might stick with ACS-5-year data to have good ZIP code data. I’d allow 2010 Census if you desire. (Geographic mobility is one worth looking at.) Look at the detail page to make sure it has data you are interested in, but ...
  • Download the table from the search results page. It is important to do it there instead of in the detail page.
  • Open up the.metadata.csv file and look at the description of the data. Take note of the column names of the data you want. You’ll want both the EST (Estimate) fields and the MOE (Margin of Error) fields.
  • Open up your “with_ann.csv” file and delete the columns you don’t need.
  • Open up TextEdit and create a text file that describes what each kind of column is in your date. (Refer to this post for more details on CSVT: ). A couple of notes: The ZIP code, GEOid and any other column you will JOIN on need to be “String”. Number columns you want to act on with shading need to be “Integer” or “Real”. Name this file the same as your data, except “.txt”.
  • Find the file on your desktop and right-click on it and do Get Info. Under "Name and Extension" change the file name from .txt to .csvt. When you close it, the computer will ask you if you want to keep .txt or use .csvt. Tell it to use .csvt.

THE JOIN

  • Add the CSV file to your QGIS document using Add Vector Layer. Open the properties of the shapefile and use the Join tab to match your fields.
  • Now change the Style of your shapefile to show your colors.
You are done! At least with analysis.

To publish online, you want to do a Save As on the layer and save it as KML to upload to fusion tables.

To print requires a whole different lesson believe it or not.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.