Opening the file and getting its contents
Now, we will open the downloaded file and prepare it for processing. This is something that we already did in Chapter 1, Preparing the Work Environment, so we will copy our function and improve it so that we can reuse it in this application and the ones to come. Here are the steps that we will perform:
- Create a new file named
geo_functions.py
inside theutils
directory. - Open the
world_areas.py
file from Chapter 1, Preparing the Work Environment, and copy theopen_shapefile
function. Then, paste it into the created file. - Now, change the name of the function to
open_vector_file
so that it makes more sense as we will use this function to open many kinds of file. The geocaching file isn't a shapefile—it's a GPX, and to open it, we don't need to change anything. OGR will handle this for us. - Now, to keep the code well documented, change the docstring to reflect the function's capabilities. Change it to something similar to
"...