Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GEOG 315, Lecture 9

GEOG 315, Lecture 9

alan.kasprak

October 24, 2021
Tweet

More Decks by alan.kasprak

Other Decks in Education

Transcript

  1. For today… 1. Work together through a couple of homework

    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
  2. courses.fortlewis.edu Let’s walk through a couple of homework problems that

    I didn’t assign together. GEOG 315: GIS Programming and Web Mapping Lecture 9 – Functions and Selection Sets
  3. 1. An introduction to functions and selections, this week’s topics

    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()
  4. A function is a block of organized, reusable code that

    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
  5. A function is a block of organized, reusable code that

    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
  6. A function is a block of organized, reusable code that

    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
  7. the classtools.py module is a great example of some custom

    functions the “get_extent” function the “plot” function the “is_path” function
  8. the classtools.py module is a great example of some custom

    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
  9. Functions are the most powerful thing you’ll learn in this

    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
  10. You’ve all (hopefully!) seen attribute tables by now: Have you

    selected data from attribute tables? What are some reasons you might want to select data from an attribute table?
  11. There are three main types of selections we can perform

    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
  12. There are three main types of selections we can perform

    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
  13. There’s a big difference between a new selection and adding

    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
  14. There’s a big difference between a new selection and adding

    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
  15. What happens when I run a geoprocessing tool when I

    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
  16. Lab this week will consist of Jupyter and a short

    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)