Locating and reading the shapefiles

To create file dialogs that allow the user to search for and locate shapefiles, Tkinter's Tk class is instantiated and assigned to the variable root. The Tk class creates a small console window that is not necessary, so it is withdrawn using the root.withdraw method:

# Initiate the Tkinter module and withdraw the console it generates
root = Tk()
root.withdraw()

The file dialogs are generated using the filedialog.askopenfilename method. The method accepts a number of arguments, including the title of the file dialog window, the initial directory, and the file extensions that should be visible while using the file dialog. Here is the Select Arena Shapefile dialog code as an example:

# Navigate to the Arena shapefile using the Tkinter file dialog
root.arenafile = filedialog.askopenfilename(initialdir = "/",
title = "Select Arena Shapefile",
filetypes = (("shapefiles","*.shp"),
("all files", "*.*")))

Within the script, this is repeated for each of the downloaded shapefiles. After using the file dialogs, each of the shapefiles located will pass a string type file path to the root variable and the file path will be held in a property.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset