Fall 2018 2018/09/24
GEOG 496
GIS Scripting Fundamentals
Path
Recap
• Pandas & GeoPandas
Topics
• Path
Path
Path
Path
• Location of a file or a directory on your operating system (OS)
/users/nara/myprogram/test.py
myprogram/
/ users/ nara/ documents/
main.py
midterm.py
goeg596/
etc/ shared/
var/ test.py
mylib1.py
Mylibs/
Forward slash / Backslash
http://www.cs.ucsb.edu/~pconrad/topics/BackslashVsForwardSlash/
Path
Path
• Absolute (full) Path
• Relative Path
Absolute Path:
myprogram/
/ home/ anara/ documents/
main.py
midterm.py
goeg596/
etc/ shared/
var/ test.py
mylib1.py /users/nara/myprogram/test.py
Mylibs/
Path
Path
• Absolute (full) Path: a path containing the root directory and all
other subdirectories that contain a file or folder
myprogram/
/ home/ anara/ documents/
main.py
midterm.py
goeg596/
etc/ shared/
var/ test.py
mylib1.py /users/nara/myprogram/test.py
Mylibs/
Absolute Path:
Path
myprogram/
Path
• Relative Path: a path relative to the current working directory
/ home/ anara/ documents/
main.py
midterm.py
goeg596/
etc/ shared/
var/
. (single dot or period): The current working directory
.. (double dots or periods): The parent of the current working directory
test.py
mylibs/
mylib1.py
Current working
directory
Relative Path: ./mylibs/mylib1.py
Path
myprogram/
Path
• Relative Path: a path relative to the current working directory
/ home/ anara/ documents/
main.py
midterm.py
goeg496/
etc/ shared/
var/
. (single dot or period): The current working directory
.. (double dots or periods): The parent of the current working directory
test.py
mylibs/
mylib1.py
Current working directory
Relative Path: ../../documents/geog496/main.py
Path
Path
• Python Built-in Module: OS
Python Syntax
https://docs.python.org/3.6/library/os.html
Get the current directory path os.getcwd()
Change directory os.chdir(path)
Get an absolute path os.path.abspath(path)
Join path os.path.join(path, path, …)
Get a list containing files and dirs os.listdir(path)
Check if a file or a directory exists os.path.exist(path)
Check if a path is a directory os.path.isdir(path)
Check if a path is a file os.path.isfile(path)
Path
Path
• Jupyter Notebook
e.g.)
Jupyter Notebook is
running on the server at
130.191.118.187:8890
Path
Path e.g.)
Jupyter Notebook is
running on the server at
130.191.118.187:8890
import webbrowser
webbrowser.register(‘firefox’, None, webbrowser.GenericBrowser(‘C:\\Program Files\\Mozilla Firefox\\firefox.exe’))
c.NotebookApp.browser = ‘firefox’
c.NotebookApp.notebook_dir = ‘C:\\Users\\yourname’
Starting Directory Path
Jupyter Notebook Configuration
Path
• Jupyter Notebook
Path e.g.)
Jupyter Notebook is
running on the server at
130.191.118.187:8890
Path
• Jupyter Notebook
Internet Browser View
Path
• Python Built-in Module: OS e.g.)
Jupyter Notebook is
running on the server at
130.191.118.187:8890
Backend server at
130.191.118.187
Path
Command Line View
Path
• Python Built-in Module: OS e.g.)
Jupyter Notebook is
running on the server at
130.191.118.187:8890
Backend server at
130.191.118.187
Path
Window View
Path e.g.)
Jupyter Notebook is
running on the server at
130.191.118.187:8890
Path
• Jupyter Notebook & OS
Make sure to include the file extension
Path e.g.)
Jupyter Notebook is
running on the server at
130.191.118.187:8890
Path
• Jupyter Notebook & OS
Get an absolute path from a relative path
Path e.g.)
Jupyter Notebook is
running on the server at
localhost
Path
• Jupyter Notebook: Make a directory
New -> Folder Rename the folder after creating it
Path e.g.)
Jupyter Notebook is
running on the server at
localhost
Path
• Jupyter Notebook: Make a directory
Make a directory with Python scripts using OS
Path e.g.)
Jupyter Notebook is
running on the server at
localhost
Path
• Jupyter Notebook: Copy files to a directory
Drag & Drop!
Path e.g.)
Jupyter Notebook is
running on the server at
localhost
Path
• Jupyter Notebook: Copy files to a directory
Click Upload!
Path
Path & GeoJson & Folium
e.g.) Jupyter Notebook
is running on the server
at localhost
Path
os.path.join()
Join a directory path and a
file name to create a file
path string.
Path & GeoJson & Folium
e.g.) Jupyter Notebook
is running on the server
at localhost
Path
json.load(open(file_path))
Load a json/geojson file and
create a dictionary object.
Path & GeoJson & Folium
e.g.) Jupyter Notebook
is running on the server
at localhost
Path & GeoJson & Folium
e.g.) Jupyter Notebook
is running on the server
at localhost
Path
folium.GeoJson(geojson_obj).add_to(map_obj)
Add a geojson object to a folium map object
Source:
https://github.com/python-visualization/folium/blob/master/examples/GeoJSON_and_choropleth.ipynb
Path & Shape File & GeoPandas & Folium
Path
e.g.)
Jupyter Notebook is running on the server at localhost
Path & Shape File & GeoPandas & Folium
Path
e.g.)
Jupyter Notebook is running on the server at localhost
Shapefile file path &
Read as GeoDataFrame
using GeoPandas
Path & Shape File & GeoPandas & Folium
Path
e.g.)
Jupyter Notebook is running on the server at localhost
Add the GeoDataFrame
object to folium using
folium.GeoJson()
Source:
https://github.com/python-visualization/folium/blob/master/examples/Geopandas%20and%20geo_interface.ipynb
Don't use plagiarized sources. Get Your Custom Essay on
GIS Scripting Fundamentals Path Recap
Just from $13/Page