Getting more arcpy help

A lot of people are posting requests asking for a particular snippet in the comments section of this blog.

By all means, continue to do so, we do enjoy tackling the more generic and broadly useful requests… but we just can’t tackle all of them, and not in a timely manner.

So if you need help with code, and you need it fairly soon, please consider also opening a discussion on the Esri geonet site.

Happy coding.

Python & arcpy presentations at the 2014 user conference

Once upon a time, there was but a single tech workshop at the Esri international user conference which featured everybody’s favorite scripting language. No longer is the Python offering so paltry. Behold, the 2014 user conference technical workshops & demo theaters returned when you search for “python”.

Consult the online agenda for date and time when these are offered.

Technical workshops

  • Python: Getting started
  • Python: Beyond the Basics
  • Python: Map Automation
  • Python Map Automation: An Introduction to arcpy.mapping
  • Python Map Automation: Beyond the Basics of arcpy.mapping
  • Python: Raster Analysis
  • Python: Building Geoprocessing Tools
  • Python for Analysis
  • Analyzing Multidimensional Scientific Data in ArcGIS
  • Automating Geodatabase Creation with Geoprocessing Tools
  • Creating Geoprocessing Services
  • Customizing ArcPad with JavaScript, Python, and VBScript
  • Desktop Mapping: Building Map Books
  • ArcGIS Online: Administering your ArcGIS Organization Through Scripting
  • ArcGIS for Server Administrative Scripting and Automation
  • ArcGIS Network Analyst: Automating Workflows with Geoprocessing
  • Integrating Open-Source Statistical Packages with ArcGIS
  • Useflul Python Libraries for The GIS Professional

Demo theater presentations

  • Administering ArcGIS for Server with Python
  • Building Live Data Feeds Using Python
  • Consuming Geoprocessing and Hosted Analytic Services in ArcGIS for Desktop
  • Debugging Python Scripts
  • Esri Production Mapping: Automating Map Production Workflows Using the ArcPyProduction Site Package
  • Geoprocessing on Image Services
  • Getting Started With Map Algebra Using the Raster Calculator and Python
  • Getting Started with Python in ArcGIS
  • Interacting with the ArcGIS Server Admin API using Python
  • Managing an Online Data Warehouse: Using Python to Publish Data to ArcGIS Online
  • Python Add-ins: Tips and Tricks

python/arcpy code from the 2014 dev summit

Hey Everyone,

it was great meeting and talking to everybody at the dev summit.

A number of python/arcpy presenters already shared their code to github repos below.

Happy coding.

merge polyline paths

Somebody on the team was having trouble tracing streams due to breaks in the streams introduced when converting raster to feature.

So here is slick little solution which takes n paths in a line features and makes a 1 path (aka 1 part) out of it.
None of the vertices are moved. Where there were two paths separated by a gap you will have one path with no gap.

To work property the paths have to be pointed in the same direction and not be converging. To deal with that would require quite a bit more logic.

As is script modified data in place, so back up your data before using.

Using os.startfile and webbrowser.open in ArcGIS for Desktop

os.startfile and webbrowser.open are two very useful functions in the Python library. However, due to some conflicts in the way the Windows libraries expect to be called, they can fail or crash when called within ArcGIS for Desktop in an add-in script or geoprocessing script tool (see the Remarks section on this MSDN reference page).

import functools
import os
import threading
import webbrowser

# A decorator that will run its wrapped function in a new thread
def run_in_other_thread(function):
    # functool.wraps will copy over the docstring and some other metadata
    # from the original function
    @functools.wraps(function)
    def fn_(*args, **kwargs):
        thread = threading.Thread(target=function, args=args, kwargs=kwargs)
        thread.start()
        thread.join()
    return fn_

# Our new wrapped versions of os.startfile and webbrowser.open
startfile = run_in_other_thread(os.startfile)
openbrowser = run_in_other_thread(webbrowser.open)

The local functions startfile and openbrowser will be made available, which have the same parameters as the versions in the standard library but will run in another thread and therefore work as expected.