Geography 465 Managing Custom Python Script Tools - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Geography 465 Managing Custom Python Script Tools

Description:

locale. os. math. random. Other spatial statistics tools. import ... import sys, math, os, locale, random, tempfile, arcgisscripting. sys. Ways of importing ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 10
Provided by: nyer
Category:

less

Transcript and Presenter's Notes

Title: Geography 465 Managing Custom Python Script Tools


1
Geography 465 Managing Custom Python Script
Tools
2
Considerations for Creating Script Tools
  • End User
  • Purpose of the script tools
  • Toolbox organization
  • Documentation
  • Code structure
  • Reusable components, error handling, more
  • How to implement
  • Where to store, how to distribute, future tools,
    etc.
  • Mainteance issues

3
Organizing your script tools
  • Create the script tools (associate each with a
    .py script)
  • Group common tools into toolsets
  • Group toolsets into toolbox

4
Understanding program flow
  • Top-level file (.py file)
  • Module that you can run
  • Controls the flow
  • Can import other modules (.py files)

Top-level file
Imported modules
5
Example Spatial Statistics Toolbox
DirectionalDistribution.py
Top-level file
CentralFeature.py
os
locale
sys
HelperFunctions
sys
os
locale
HelperFunctions
random
sys
math
locale
os
Other spatial statistics tools import
HelperFunctions
HelperFunctions.py import sys, math, os, locale,
random, tempfile, arcgisscripting
6
Ways of importing
  • More than one way to import
  • import entire module requires module prefix
  • import math
  • math.sin (x)
  • fromimport specific names from module
  • from math import sin, cos,
  • sin(x)
  • fromimport
  • from math import
  • tan (x)
  • Affects readability, name collision, ability to
    reload

7
Code order
  • Writing custom functions
  • Put functions at top
  • Put top-level code at bottom so functions are
    recognized
  • Functions
  • def
  • def
  • top-level code

8
Controlling access to functions and variables
  • Each module has a built in _ _name_ _atttribute
  • Module can test its own _ _name_ _
  • Top-level file module
  • _ _name_ _ is equal to _ _main_ _
  • Imported module
  • _ _name_ _ is equal to ltmodulenamegt
  • _ _main_ _ prevents access when module is
    imported for
  • def statements
  • Variables

9
Code example Control access
  • MyTool.py
  • import Example
  • fmc Example.find_most_central()
  • ac Example.areaCalc()
  • Example.py
  • import arcgisscripting
  • gp arcgisscripting.create()
  • def get_imputs (arguments) access
    unrestricted
  • df find_most_central() in calling module
  • if _ _name_ _ _ _main_ _ access
    restricted
  • def areaCalc() in calling module
Write a Comment
User Comments (0)
About PowerShow.com