On this page, I'll demonstrate how I made the kml file responsible for my very basic web map. While it's not the most sophisticated use of Python, it makes it very ease to map basic places of importance--essential in laying out the terrain of one's own research. In this case, I wanted to display communities bordering Yosemite National Park. While not technically part of the park, the economic/cultural infrastructural symbiosis of "orbital communities" is fascinating to me.
First, I need a txt file with the places I want to geocode.
Then, I need a script that will geocode--but also produce a new txt file with my desired lat/long coordinates. I'll need a for loop that will store the returns for each line in a Python dictionary. The script will first need to activate an API call and then extract the lat/long from the JSON response that the Google server will give.
Then I run the program 'extract.py.'
The result: a new file entitled 'geocoded-placelist.txt.' Revel in its glory
Now this is a neat party trick, but can Python help me do more with my newly acquired lat/long? You bet. As with any programming languages, the trick is knowing how to ask. My next script uses the extremely useful 'simplekml' module. Essentially, it creates a simplekml object, adds points to it, and writes it to a separate file of my choosing.
Now I have a kml file. I want to know if my scripts worked correctly, so I simply double-click the kml file; it opens in Google Earth by default.
I'm almost certain I'll use these scripts again in my research. Although web mapping isn't a focus on my project, the kml layers that I create can also be imported into QGIS. My ultimate goal is to make my own maps, whether they are simple maps to set the stage or sophisticated stories with multiple variables. Whenever I read a new monograph, I always notice its use of maps. I've realized that if I have spatial data to augment a narrative, my reading goes much more in-depth. Hopefully my project about Yosemite will succeed in addressing spatial dimensions of the park that no one has addressed yet--the park's relation to the communities that orbit it.