''' Purpose: determine a rough estimate of the geocenter of the continental USA ''' # get access to web-based data support import url # specify dataset web location CSV_WEB_FOLDER = 'http://www.cs.virginia.edu/~cs1112/datasets/csv/' USA_DATASET = CSV_WEB_FOLDER + 'continental-usa.csv' # Where our dataset is # get the dataset of interest dataset = url.get_csv_dataset( USA_DATASET ) # Will turn into a dataset. All items are strings. # determine webfile header and location data # determine geocenter lats = [] # list for our latitudes longs = [] # list for our longitudes for row in dataset: # This line gets each row element in our dataset from above # Pick off the latitude and longitude zip_code, city, state, latitude, longitude = row # row has 5 elements, so they will each go to a variable # Alternatively row[3] is the latitude & row[4] is the longitude # Convert to floats latitude = float( latitude ) longitude = float( longitude ) # Add to our lists lats.append( latitude ) longs.append( longitude ) # Get min latitude and min longitude min_lat = min( lats ) # gets the minimum element from the list of latitudes min_long = min( longs ) # Get max latitude and max longitude max_lat = max( lats ) max_long = max( longs ) # Average for the geocenter :D average_lat = ( min_lat + max_lat ) / 2 average_long = ( min_long + max_long ) / 2 print( average_lat, average_long )