problems that I didn’t assign 2. An introduction to functions and selections, this week’s topics GEOG 315: GIS Programming and Web Mapping Lecture 9 – Functions and Selection Sets
A function is a block of organized, reusable code that is used to perform a single, related action. You’ve seen many functions already. print() str() updateRow() imshow() float() writeRow() Clip_analysis()
is used to perform a single, related action. Most functions take at least one parameter (you might also hear these called arguments): print(‘Hello world’) str(943234) updateRow(row[0]) imshow(my_figure) float([9, 6, 7, 2, 1, 8]) writeRow(row) Clip_analysis(`input.shp`,`clip.shp`, `output.shp`) 1. An introduction to functions and selections, this week’s topics
is used to perform a single, related action. Some functions won’t work because they live in modules, which you need to import. print(‘Hello world’) str(943234) updateRow(row[0]) imshow(my_figure) float([9, 6, 7, 2, 1, 8]) writeRow(row) Clip_analysis(`input.shp`,`clip.shp`, `output.shp`) 1. An introduction to functions and selections, this week’s topics
is used to perform a single, related action. Some functions won’t work because they live in modules, which you need to import. print(‘Hello world’) str(943234) updateRow(row[0]) imshow(my_figure) import matplotlib float([9, 6, 7, 2, 1, 8]) writeRow(row) Clip_analysis(`input.shp`,`clip.shp`, `output.shp`) import arcpy 1. An introduction to functions and selections, this week’s topics
functions the “get_extent” function the “plot” function the “is_path” function every function starts with def function_name(parameters): to use any of these we need to import classtools
class. By writing our own functions, we can hand our code to someone else who has no idea how it works and all they need to do is type: import my_function my_function(‘a_shapefile_they’ve_got.shp’) and it’ll run just fine. Think about all the arcpy functions you’ve used: - clip_analysis() - project_management() - dissolve_analysis() - merge_analysis() - sa.flowDirection, sa.accumulation, sa.flow_area …and yet you’ve never seen the code behind any of these. All you have to do is import arcpy
on data (in GIS), but really only two that we actually want to perform: SELECT BY ATTRIBUTE select those features that meet some selection query (i.e., POPULATION > 500 or NAME = Durango or NAME like ‘a%’ SELECT BY LOCATION select features relative to other features based on some criteria (i.e., CITIES contained in LA PLATA COUNTY or RIVERS crossing ROADS or LAKES within 500 m of ROADS SELECT INTERACTIVELY aka, you manually go through and click the polygons/lines/points that you want to select which works if you only want to select a few, but takes forever otherwise
on data (in GIS), but really only two that we actually want to perform: SELECT BY ATTRIBUTE select those features that meet some selection query (i.e., POPULATION > 500 or NAME = Durango or NAME like ‘a%’ SELECT BY LOCATION select features relative to other features based on some criteria (i.e., CITIES contained in LA PLATA COUNTY or RIVERS crossing ROADS or LAKES within 500 m of ROADS SELECT INTERACTIVELY aka, you manually go through and click the polygons/lines/points that you want to select which works if you only want to select a few, but takes forever otherwise
to my current selection Select from CITIES where POPULATION > 1,000,000 returns DENVER [NEW SELECTION] Select from CITIES WHERE NAME STARTS WITH ‘D’ returns DENVER and DURANGO and DOVE CREEK NEW SELECTION: clears the current selection and starts from scratch
to my current selection Select from CITIES where POPULATION > 1,000,000 returns DENVER [NEW SELECTION] Select from CITIES WHERE NAME STARTS WITH ‘C’ returns CORTEZ and COLORADO SPRINGS Select from CITIES where POPULATION < 1,000 returns DOVE CREEK, ALAMOSA, MOSCA [ADD TO SELECTION] Select from CITIES WHERE NAME STARTS WITH ‘D’ returns DOVE CREEK, ALAMOSA, MOSCA, DENVER, DURANGO NEW SELECTION: clears the current selection and starts from scratch ADD TO SELECTION: adds more items to the current selection
have features selected? If a tool is run when features are selected, it’ll only run on the selected features. That means we can restrict our analysis (and make new shapefiles) using only the features we care about
Homework Two Homework Problems (1)Selections with Notebooks (2)Selections with Functions Three Jupyter Notebooks for Comprehension 1. Functions and Modules 2. Field Calculator 3. Selection Sets Turn in two notebooks in a single .zip folder (for the homework assignment) Turn in three notebooks as a single .zip folder (for the Jupyter Assignment)