Masthead

Assignment: Formatting Files

1. A Function to Convert between DMS and DD

Write a function to convert coordinate values from degrees, minutes, and seconds (DMS) to decimal degrees (DD). You can use the code on this website for the contents of the function. Then, create a series of coordinates in DMS and use the function to convert them to decimal degrees.

Write another function to convert coordinate values from DD to DMS. Call the number with a series of coordinates and make sure they appear correctly.

A clever way to test the functions would be to call the function to convert the values from DMS to DD and then call the function to convert from DD to DMS with the new DD values. The string output from the DMS function match the original strings almost exactly.

Note: The strings may not match exactly because computers to not use base 10 to represent numbers. When they convert from base 10 to binary the original value is lost. When you convert back again there may be "rounding errors" causing the final value to be slightly different. Think about how to use "format()" to make the values appear the way they should.

 

Turn in:

  1. A Python file that uses a function you've cretaed to print out at least 4 decimal degree coordinates from coordinates formated as degrees, minutes, and seconds. There should be at least one for each quarter-sphere of the earth.
  2. Another Python file that prints out at least 4 coordinates in degrees, minutes, and seconds (including degree symbols and E/W, N/S characters) from decimal degree coordinates. There should be at least one for each quarter-sphere.

2. A Function to Convert Dates to Nice Human-Readable Forms

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.

Turn in:

  1. A Python script containing a function to convert dates to a nice format and code calling the function to print out at least 3 dates.

3. Reformatting Files

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. Download one of the files from their website (feel free to use California if desired) and produce 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.

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

Turn In:

  1. The input file you used or, if the file is huge, the download location for the file.
  2. The Python program you created to convert the file. The program should include:
    1. A function to convert Latitudes and longitudes from DD to DMS (you can use the one from the previous assignment)
    2. 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 puncutation and keep the column names to 10 characters or less.

 

© Copyright 2018 HSU - All rights reserved.