Skip to content
A short script that maps geographic attributes (earthquake affected, war, etc) to multiple countries/cities.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
AUS.geo.json
GeoGraph.py
README.md
countries.geo.json
cri_cities.xlsx

README.md

GeoGrapher

Photo by Andrew Neel on Unsplash

To run the script, cd into the appropriate directory and run python GeoGrapher.py into the command line.

The script goes to the United States Geological Survey (USGS) website to retrieve the geo.json file of Significant Earthquakes in the past 30 days, parsing it using split() function to extract:

Colons can be used to align columns.

Extracted Data Notes To .csv
title Title
country Country
longitude Latitude
latitude Longitude
magnitude Magnitude
alert Alert
tsunami Tsunami
range Range
direction (from nearest coast Direction
MMI
Significance
Mag_max Country affected
(coming soon) City affected

The script will print the logs to the command line, just as a check for the content. Using the Shapely module and the countries.geo.json, a point is constructed from the extracted earthquake coordinates.

Comparing each earthquake, a for loop runs over each point and checks whether the point intersects or the country polygon. If this is true, then it prints the country that the earthquake has affected.

Finally, the writerow() function prints this information in a tabular format to Earthquakes.csv. Note that additional running of this script overwrites previous files with the same name. To change this instead append to existing file, change the following line:

w = csv.writer(open("Earthquakes.csv","w"))

to

w = csv.writer(open("Earthquakes.csv","a"))

"a" means append (add the data to the end of this file if it already exists), while "w" only writes.

You can’t perform that action at this time.