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

Post on 28-Jun-2020

15 views 0 download

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

Python: An IntroductionBrittney White

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

What is Python?

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

Why use Python with ArcGIS?

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

• Make your own geoprocessing tools

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

Demo: ArcGIS Pro Python Reference

Where do I write Python code?

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

• Python window in ArcGIS

Demo: Python window & IDE

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

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

Demo: Geoprocessing tool syntax

How do I perform batch processing?

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

How do I access data properties?

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

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

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

#Do something

else:

#Do something else

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()

5 tips & tricks for getting started with Python

5. Use the print function

print function

4. Copy and paste

Copy and paste - Code samples

Copy and paste - Paths

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

3. Participate in the GeoNetPython community

2. Take Esri Training about Python

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

1. Manage Python packages with ArcGIS Pro

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

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”

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