Masthead

Assignment: Formatting Files

Reformatting Files

Date Conversion Function

First, create a Python script with a function that converts a US formatted date (MM/DD/YYYY) into a nice, human-readable, form like: 31st of October, 2011. Call the function with at least 3 dates and print them out to make sure it works. Put this function at just below the file header in your file before any other code that might call it.

Tip: A pre-defined list is an easy and fast method for finding the text string that matches a given month's name (i.e. matching "1" to January).

U.S. Board on Geographic Names

One of the most common tasks that programmers will be asked to tackle is to take an existing file and either reformat it, fix a problem in it, or convert the values in it to another format. This assignment will give you the chance to do this for yourself and put together a number of concepts you've learned so far.

The U.S. Board on Geographic Names contains a very large database of the names of cities, streams, valleys, and other physical features on the earth. You've been asked to create a file that can be loaded into ArcGIS. The data in the columns of the table should contain values that are nicely readable so we can use them as symbology in ArcGIS.

Converting Text Files

Download one of the files from their website (feel free to use California if desired) and convert it into a text file that has the following columns (in any order).

You can filter the contents of the files to just output one feature class if desired.

To complete this task, you'll want to first read in the file on line at a time. Then, check the "delimiter" for the text in each line. Use the delimiter to "split" up the line into "tokens". Then, select the tokens you want to include in your output file. Write out the file based on the columns above. Finally, call any required format conversion functions for those columns.

The overall structure of a file of this complexity is important for readability. Your file should have the following sections:

Remember to add a header for each function and other appropriate comments.

Turn In:

  1. The input file you used or, if the file is huge, the download location (URL) for the file.
  2. The Python program you created to convert the file. The program should include:
    1. A function to convert a date string to a nice human-readable string
  3. The final output file. Please make sure you can load the file into ArcGIS. This is both important for grading and to make sure your file is usable. Remember that ArcGIS is very limited on what it will accept as a header for tabular data. Only used the underscore ("_") for punctuation and keep the column names to 10 characters or less. Also, you'll need to write out the file as a ".csv" (comma separated value) and then add it by selecting "File -> Add Data -> Add X,Y Data".
  4. Place all files into a folder and "zip" them together. Name the file with your first and last name (e.g. "First_Last.zip") an upload it to Moodle.

Extra Credit 1:

Add the following attributes to the file:

Note: ArcGIS cannot display the degree symbol and is not happy with the double quote symbol either. What would be a good approach to format geographic coordinates as attributes?

Extra Credit 2:

Convert the DMS coordinates from the GNIS data and compare the values with the DD coordinates in the same row to see how close they are. Add the difference as a column to the file.

© Copyright 2018 HSU - All rights reserved.