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 generatesroot = 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 ...

Get Mastering Geospatial Analysis with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.