Masthead

Assignment: Fixing Files

1. Fixing 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.

First, you'll want to find a file that needs to be converted. You can use one from your own project if you have one and want to, otherwise, you can use the Avian Knowledge Network (AVN). Download the file locally and store it somewhere Python can access it. Then, start writing a program that will reformat the file to be they way you want. I recommend starting by reading the file and writing out the first few lines. Take a look at the lines and make sure you know the values are in the file that you want to access. Then, modify your code to convert the file line, by line, to the new format. Start with just a few lines and load them into ArcGIS to make sure they work correctly. Then, add a conversion to one of the values. Finally, add an "if" statement to only write out a portion of the file that you are interested in.

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 subset of the values in the columns
    2. A subset of the rows of the files
    3. At least one data conversion
  3. The final output file

2. Writing Functions for Conversions

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.
  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.

© Copyright 2018 HSU - All rights reserved.