Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for...

32
Python: An Introduction Brittney White

Transcript of Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for...

Page 1: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

Python: An IntroductionBrittney White

Page 2: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

Questions we’ll address

• What is Python?• Why use Python with ArcGIS?• What is ArcPy?• Where do I write Python code?• How do I run a geoprocessing tool?• How do I perform batch processing?• How do I use data properties to control the flow of a script?• Bonus: 5 tips & tricks for getting started with Python

Page 3: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

What is Python?

• Simple and easy to learn• Free and open source• Cross platform• Scripting language of ArcGIS

Page 4: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

Why use Python with ArcGIS?

• Automate repetitive tasks- Data management- Spatial analysis- Map automation

• Make your own geoprocessing tools

Page 5: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

What is ArcPy?

• Access point to ArcGIS desktop functionality through Python

1. Geoprocessing tools2. Functions like ListFeatureClasses,

Describe3. Classes like Polygon, SpatialReference4. Modules like arcpy.da, arcpy.mp

Page 6: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

Demo: ArcGIS Pro Python Reference

Page 7: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

Where do I write Python code?

• Integrated Development Environment (IDE)- PyCharm, Spyder, Wing IDE, Python IDLE,…

• Python window in ArcGIS

Page 8: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

Demo: Python window & IDE

Page 9: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

Where do I write Python code?

Desired task Python window Python IDEExecute a single line of code Work directly with layers in ArcGIS Pro Test geoprocessing workflows and visually verify results Work with tools to enter, edit, and check syntax in your code

Page 10: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

How do I run a geoprocessing tool?

• Tool syntax- arcpy.toolname_toolboxalias(parameters)

- arcpy.toolboxalias.toolname(parameters)

• Where do I find the syntax?- Tool help page- help(arcpy.buffer_analysis)

- Copy Python command- Send to Python window

Page 11: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

Demo: Geoprocessing tool syntax

Page 12: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

How do I perform batch processing?

Page 13: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

How do I perform batch processing?List feature classes example

• arcpy.ListFeatureClasses ({wild_card}, {feature_type}, {feature_dataset})

- Returns a list of feature classes in the workspace

Page 14: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

How do I access data properties?

• arcpy.Describe()- Returns a describe object - Describe object has dynamic properties

Page 15: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

How do I access data properties?…to control the flow the script?

if arcpy.Describe().property == something:

#Do something

else:

#Do something else

Page 16: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

Demo: Prepare shapefiles for analysis

Goal ArcPyList the shapefiles in a folder

List function -arcpy.ListFeatureClasses()

Check the coordinate system of each shapefile

Describe function - arcpy.Describe()

Project the shapefiles into the local coordinate system

Geoprocessing tool -arcpy.Project_management()

Move shapefiles into a file geodatabase

Geoprocessing tool -arcpy.CopyFeatures_management()

Page 17: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

5 tips & tricks for getting started with Python

Page 18: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

5. Use the print function

Page 19: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

print function

Page 20: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

4. Copy and paste

Page 21: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

Copy and paste - Code samples

Page 22: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

Copy and paste - Paths

Shift + Right-click a file reveals the Copy as path option

Page 23: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

3. Participate in the GeoNetPython community

Page 24: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()
Page 25: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

2. Take Esri Training about Python

https://www.esri.com/training/catalog/

Page 26: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()
Page 27: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

1. Manage Python packages with ArcGIS Pro

Page 28: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()
Page 29: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()
Page 30: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

Print Your Certificate of AttendancePrint Stations Located at L Street Bridge

Tuesday Wednesday12:30 pm – 6:30 pm GIS Solutions Expo Hall D

5:15 pm – 6:30 pm GIS Solutions Expo SocialHall D

10:45 am – 5:15 pm GIS Solutions Expo Hall D

6:30 pm – 9:00 pm Networking ReceptionNational Building Museum

Page 31: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

Please Take Our Survey on the AppDownload the Esri Events app and find your event

Select the session you attended

Scroll down to find the feedback section

Complete answersand select “Submit”

Page 32: Python: An Introduction - Esri · -PyCharm, Spyder, Wing IDE, ... Demo: Prepare shapefiles for analysis. Goal. ArcPy. List the shapefiles in a folder. List function - arcpy.ListFeatureClasses()

Python Sessions at #FedGIS

Session Tuesday WednesdayPython: An Introduction 1:45 pm – 2:45 pm in 202B 8:30 am – 9:30 am in 202BPython: Beyond the Basics 4:15 pm – 5:15 pm in 208AB 11:00 am – 12:00 pm in 202BUsing Python in ArcGIS Enterprise

8:30 am – 9:30 am in 201

Python: Building Geoprocessing Tools

5:15 pm – 6:15 pm in 201

Data Science in ArcGIS Using Python and R

4:00 pm – 5:00 pm in 202B

Machine Learning in ArcGIS 4:15 pm – 5:15 pm in 202 A 8:30 am – 9:30 am in 202A