annotate contrib/python/foobar.py @ 218:fb1ffd385115

merged with upstream changes
author Stephan Holl <stephan.holl@intevation.de>
date Mon, 25 Jul 2011 11:09:52 +0200
parents 93699e8f2d1f
children
rev   line source
114
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
1 # Author: ESRI
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
2 # Date: July 5, 2010
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
3 # Version: ArcGIS 10.0
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
4 # Summary: This script will add a layer file into a map document. The script
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
5 # must be run from within ArcMap because it references the CURRENT
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
6 # map document. The purpose of the script is to create a user
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
7 # friendly tool that allows users to simply add a layer from a list
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
8 # of existing layer files all stored in a common location. A validation
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
9 # script is used to automatically populate two of the parameters.
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
10 # The parameters are:
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
11 # 1) Browse to a folder that contains layer files. This could be
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
12 # hard coded within the validation script eliminating the need
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
13 # for entering this parameter.
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
14 # 2) Select a layer file from the list. This is auto populated
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
15 # using a validation script.
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
16 # 3) Select a data frame. This is also auto populated using a
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
17 # validation script.
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
18 # 4) Select one of 3 placement positions.
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
19 #
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
20 # Note: This script tool will only work if background processing is disabled.
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
21 # because CURRENT is being used.
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
22 # Note: To run the script from ArcMap either run the script tool from the
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
23 # Catalog window from within ArcMap or add the script tool into the UI
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
24 # via the customize dialog box [Geoprocessing Tools].
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
25
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
26 import arcpy
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
27 import shlex, subprocess
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
28
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
29 #Helper for executing an external shell-scrip or programm
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
30 def executeCommand(command):
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
31 success = False
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
32 try:
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
33 args = shlex.split(command)
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
34 p = subprocess.Popen(args)
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
35 p.wait()
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
36
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
37 returnCode = p.returncode
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
38
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
39 if (returnCode == 0):
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
40 success = True
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
41 else:
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
42 print "Subproccess terminates with %s. This is an error"\
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
43 % returnCode
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
44 except OSError, err:
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
45 success = False
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
46
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
47 return success
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
48
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
49 try:
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
50 #Read parameters from dialog
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
51 inputMXD = arcpy.GetParameterAsText(0)
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
52 outputMXD = arcpy.GetParameterAsText(1)
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
53 template = arcpy.GetParameterAsText(2)
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
54
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
55 print "InputMXD: %s,\nOutputMXD: %s" % (inputMXD, outputMXD)
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
56
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
57 # execute Java-command for converting
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
58 javacmd = "-Dmapserver.library.name=lib/mapscript -jar mxd-testbed_sh.jar"
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
59 javafiles = "-mxd %s -map %s -template %s " % (inputMXD, outputMXD, template)
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
60
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
61 cmd = "java "+ javafiles + javacmd
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
62 print cmd
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
63 executeCommand(cmd)
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
64
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
65 except Exception, e:
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
66 import traceback
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
67 map(arcpy.AddError, traceback.format_exc().split("\n"))
93699e8f2d1f contrib/python/FixWorkspacePaths.py, contrib/python/foobar.py:
Stephan Holl <stephan.holl@intevation.de>
parents:
diff changeset
68 arcpy.AddError(str(e))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)