Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error.Where do I acce...

http://training.esri.com/Courses/PythonDesktop10_0/player.cfm

Exercise: Use Python in ArcGIS Desktop 10
This exercise is designed to introduce you to some of the common ways of using Python with ArcGIS 10. During this exercise, you will write several Python scripts to automate GIS tasks and increase your productivity. You will learn how to use your scripts in the Python window and Field Calculator in ArcMap, as well as in PythonWin, a widely used third-party Python integrated development environment (IDE). Note: This exercise requires the use of PythonWin 2.6, which is included on the ArcGIS Desktop 10 installation DVD but is not installed by default. If you do not have PythonWin installed on your machine and you do not have access to the ArcGIS Desktop DVD, download and install PythonWin now. Estimated completion time: 45 minutes
Step 1: Download the data

To complete the exercise, you need to download the data. If you have already downloaded and installed the data, continue to the next step.
Step 2: Verify a setting and open the map document

Before you begin working in ArcMap, you will ensure that the option to hide file extensions is turned off. Start ArcCatalog. From the Customize menu, choose ArcCatalog Options. On the General tab, make sure Hide file extensions is unchecked.

1 of 37

11/10/2011 11:43 AM

Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error.Where do I acce...

http://training.esri.com/Courses/PythonDesktop10_0/player.cfm

Step 2a: Verify a setting and open the map document.

Click OK. On the Standard toolbar, click the Launch ArcMap button After the ArcMap window opens, close ArcCatalog. In the ArcMap – Getting Started dialog box, under Existing Maps, click Browse for more. Browse to your C:\Student\PythonDesktop10_0 folder, or the folder containing your data. Click the Westerville map document and click Open. The map shows an area within the city of Westerville, Ohio. Notice that the table of contents displays several layers for the city. .

2 of 37

11/10/2011 11:43 AM

Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error.Where do I acce...

http://training.esri.com/Courses/PythonDesktop10_0/player.cfm

Step 2b: Verify a setting and open the map document.

You will use these layers in upcoming steps as you create your Python scripts.
Step 3: Buffer schools using the Python window

In this step, you will use the Python window to create buffer polygons around the schools. City planners will use these polygons when making land-use decisions in the areas near schools. On the Standard toolbar, click the Python window button .

3 of 37

11/10/2011 11:43 AM

4 of 37 11/10/2011 11:43 AM . docking it below the map. Click the title bar of the Python window and drag it the bottom of the interface. is where you enter your Python script. The Python window is divided into two sections: The left section. which currently displays the primary prompt (>>>).com/Courses/PythonDesktop10_0/player. http://training. Note: The Python window can also be opened from the Geoprocessing menu.esri. help..Where do I acce.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error.. The section on the right displays syntax.cfm Step 3a: Buffer schools using the Python window. and execution messages.

com/Courses/PythonDesktop10_0/player. you will enter code into the Python window to set the current workspace environment.en 5 of 37 11/10/2011 11:43 AM .esri. type: arcpy.Where do I acce. In your Python window. http://training.cfm Step 3b: Buffer schools using the Python window. First.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error...

type the path to the location where you downloaded the data instead. In this line of code. type: = "C:/Student/PythonDesktop10_0/Data/Westerville. After arcpy. type: 6 of 37 11/10/2011 11:43 AM . At the prompt in the Python window. this also reduces errors in your code. you will run the Buffer geoprocessing tool using Python.w Press the Tab key to add workspace to your line of Python code.esri. you will set the value of the workspace.. Next.com/Courses/PythonDesktop10_0/player. http://training.. rather than typing. The env class stores the ArcGIS environment settings used for geoprocessing. press Enter to move to a new prompt. Press the Tab key on your keyboard to accept the env value in the list.workspace To assign the path to your data. you have accessed the workspace geoprocessing environment setting and set its value to the Westerville geodatabase.env.Where do I acce. type: . When you have finished setting your workspace. The ArcPy site package contains the Python libraries and modules which enable you to access many ArcGIS functions from within Python. Code completion allows you to complete your code faster by choosing options from a drop-down list. This list of choices is called code completion.cfm The syntax for the Python statement appears in a drop-down list.gdb" Note: If your course data is not in the C:\Student\PythonDesktop10_0 folder.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. Next. Verify that your code now looks like this: arcpy.env. which is an environment setting. In addition to allowing you to work faster.

Step 3c: Buffer schools using the Python window. Tip: You can also use the up/down arrow keys on your keyboard to choose the Schools layer from the list. Type a left parenthesis to continue your line of code.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error.com/Courses/PythonDesktop10_0/player. Notice that the syntax for the Buffer tool displays in the help section of the Python window.cfm arcpy. and that the code completion provides a list of layers corresponding to the in_features. 7 of 37 11/10/2011 11:43 AM .Bu Press your Tab key to choose Buffer_analysis from the drop-down list.esri.Where do I acce.) and observe that the next argument for the Buffer tool (out_feature_class) is highlighted in the help and syntax section. Type a comma (. http://training. choose the Schools layer and press your Tab key. In the drop-down list...

) and then type "1000 feet" for the buffer_distance_or_field value. including the quotation marks. Type another comma (.. type "Buffer_1000". For out_feature_class.. followed by a right parenthesis ). Step 3e: Buffer schools using the Python window.esri.com/Courses/PythonDesktop10_0/player.cfm Step 3d: Buffer schools using the Python window.Where do I acce. Verify that your code now looks like this: 8 of 37 11/10/2011 11:43 AM .Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. http://training.

Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. http://training. Notice that the help for the Buffer tool is no longer displayed because you have finished adding all of the arguments and provided a closing parenthesis. How does the Buffer tool know where to save the Buffer_1000 output feature class? Press Enter on your keyboard to run the Buffer tool. Step 3f: Buffer schools using the Python window. as well as the start and finish times. I received an error.. notice that the help and syntax section displays the status of the Buffer command. After it is finished.cfm Note: Depending on the width or your Python window. The buffer will take a few moments to execute.Where do I acce.. 9 of 37 11/10/2011 11:43 AM . a new Buffer_1000 layer is added to your map.com/Courses/PythonDesktop10_0/player.esri. your code may wrap to the next line. In the Python window.

choose Tile. From the Window menu. Where do I access PythonWin? From the File menu.Where do I acce.cfm Click the X in the upper right corner of the Python window to close it. From the File menu. http://training.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. Step 4: Buffer schools using PythonWin ArcPy can also be accessed outside of ArcGIS Desktop in any Python integrated development environment (IDE). choose Python Script and click OK. Close ArcMap without saving your changes. choose Save As. you will see how the Buffer tool can be accessed from within the PythonWin IDE. choose New...esri. 10 of 37 11/10/2011 11:43 AM . Open PythonWin.\PythonDesktop10_0 folder and name your script SchoolBuffer. Step 4a: Buffer schools using PythonWin. In this step. Save your script in your .py.com/Courses/PythonDesktop10_0/player.. In the New dialog box.

com/Courses/PythonDesktop10_0/player.cfm Step 4b: Buffer schools using PythonWin. In the Interactive Window at the bottom.esri.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. http://training.. type: import arcpy 11 of 37 11/10/2011 11:43 AM .Where do I acce..

type: arcpy. In the SchoolBuffer scripting window on the top.w Step 4c: Buffer schools using PythonWin.workspace 12 of 37 11/10/2011 11:43 AM . To highlight workspace in the drop-down list.esri.. Verify that your code now looks like this: arcpy.com/Courses/PythonDesktop10_0/player.en The drop-down list opens as shown below.cfm This loads ArcPy into memory and allows you to access classes and functions with drop-down lists similar to the Python window in ArcMap.env. With env highlighted in the list.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error.. type: .Where do I acce. Press the Tab key. press the Tab key on your keyboard. http://training.

.cfm Set the workspace pathname to complete your code: = "C:/Student/PythonDesktop10_0/Data/Westerville. Press Enter to finish your first line of code..gdb" Note: If your data is not in the C:\Student\PythonDesktop10_0 folder. change the pathname in your code to the location where you downloaded the data.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error.Where do I acce. http://training. 13 of 37 11/10/2011 11:43 AM .com/Courses/PythonDesktop10_0/player.esri.

esri..com/Courses/PythonDesktop10_0/player.Bu Select Buffer_analysis from the drop-down list and press your Tab key. On the next line.. http://training.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error.cfm Step 4d: Buffer schools using PythonWin.Where do I acce. type: arcpy. 14 of 37 11/10/2011 11:43 AM .

the drop-down list will not highlight Buffer_analysis. Type a left parenthesis (. Step 4e: Buffer schools using PythonWin.cfm Note: Remember that Python is case sensitive. which displays the syntax for the Buffer_analysis tool.Where do I acce.. http://training.com/Courses/PythonDesktop10_0/player.esri.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. 15 of 37 11/10/2011 11:43 AM .. If you type a lower-case "b".

For in_features.Where do I acce. type: 16 of 37 11/10/2011 11:43 AM .cfm Step 4f: Buffer schools using PythonWin..esri. This syntax is similar to what you saw in the help and syntax section of the Python window in ArcMap..Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. http://training.com/Courses/PythonDesktop10_0/player.

For buffer_distance.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. 17 of 37 11/10/2011 11:43 AM .Where do I acce. For out_feature_class. type: "Buffer_500". followed by a comma to end the in_features argument.cfm "Schools"..com/Courses/PythonDesktop10_0/player.. Note: Remember to add the quotes around the word Schools.esri. type: "500 feet" Finish your code statement with a right parenthesis ). http://training.

. Prior to running your script.cfm Step 4g: Buffer schools using PythonWin. insert import arcpy as the first line in your script..Where do I acce. 18 of 37 11/10/2011 11:43 AM .Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error.esri. http://training.com/Courses/PythonDesktop10_0/player.

cfm Step 4h: Buffer schools using PythonWin. always include the necessary import statements as part of your Python script. as a best practice.com/Courses/PythonDesktop10_0/player. Running your scripts outside of PythonWin in other environments will often require the import statement as part of the script.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error.. http://training. However. Tip: Your script would run without this line because you previously imported arcpy in the Interactive Window.. 19 of 37 11/10/2011 11:43 AM .esri.Where do I acce.

Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. Right-click the Streets layer and choose Open Attribute Table. then click the Run button to execute your script. confirm that you do not have any error messages in the Interactive Window. These should all use capital letters for consistency.mxd map document that you used earlier in this exercise.. the following message displays on the status bar in the bottom left corner of PythonWin. http://training. 20 of 37 11/10/2011 11:43 AM . At the top of the Field Calculator. while others have DR. Close PythonWin. Under Fields. double-click TYPE. you will use Python in the Field Calculator to programmatically change attribute values. as shown below. Widen the table so you can see all the field names. If it finishes without error.. Notice that some streets have a value the TYPE field of dr. Right-click the TYPE field and choose Field Calculator. When the script is finished. Click the button next to Python. I received an error in the Interactive Window. notice that you have a choice of either VB Script or Python. Step 5: Create a calculation expression using Python In this step. The Field Calculator opens.esri.Where do I acce.cfm Click the Save button . The script takes a few moments to run. Open the Westerville. Click OK on the Run Script dialog box.com/Courses/PythonDesktop10_0/player.

cfm Notice that !TYPE! appears in the window at the bottom of the Field Calculator.Where do I acce. Click OK. Open the Field Calculator for the MAP_LABEL field. Click OK. After the calculation has completed. type MAP_LABEL. Remind me how and choose Add Field.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. for High School. "DR") This Python code will use the replace function to replace all occurrences of dr with DR. Scroll to the end of the table so you can see your new MAP_LABEL field. For example. Step 6: Create a multiline calculation expression In this step. if the value for TYPE is HIGH. This expression will create an attribute value that can be used for labeling the schools. For Type.. When referencing field names in the Field Calculator using Python. Now you will create an expression to combine the attribute values from the NAME and TYPE fields. your calculation will change it to HS. click the Table Options button In the Add Field dialog box. 21 of 37 11/10/2011 11:43 AM ..com/Courses/PythonDesktop10_0/player. http://training.esri. choose Text. At the top of the attribute table window. Open the Schools attribute table. the field is enclosed by exclamation points. you will create a Python expression in the Field Calculator that is several lines long. Close the attribute table. do the following: For Field Name. examine the TYPE field in the attribute table.replace("dr". Notice that the values of dr have been changed to DR. Complete the code as follows: !TYPE!. and to abbreviate the school type as well.

cfm Right-click the MAP_LABEL field and choose Field Calculator. Click Load.com/Courses/PythonDesktop10_0/player. like the one you created in the previous step. !TYPE! ) For each school.cal file. 22 of 37 11/10/2011 11:43 AM .Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. More complex expressions. Simple field calculator expressions.Where do I acce. Set the Parser to Python. such as multiline scripts and those that have looping or branching. and click Open.. and your MAP_LABEL attribute. click the Schools. are entered directly into the Expression text box. Notice that the bottom of the Field Calculator is now divided into two boxes: the Pre-Logic Script Code. http://training..\PythonDesktop10_0 folder. You will load a Python script that so formatted specifically for use in the Field Calculator. Step 6b: Create a multiline calculation expression. Browse to your . values from the NAME and TYPE attributes are read and passed to a function named label. are entered in the Codeblock boxes. Step 6a: Create a multiline calculation expression.. Check the box next to Show Codeblock.esri. Examine the newly added code at the bottom of the Field Calculator: label( !NAME!.

If it is.com/Courses/PythonDesktop10_0/player. Also.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. notice that this line is indented two spaces and ends with a colon (:). This combined text string will be entered as the new value in the MAP_LABEL field. If the statement is false (e. type does not equal HIGH). which is indented below the previous if statement. use two or four spaces to define each logical level. return name + " HS" Lines that are indented at this same level will be executed if the value of the type variable is equal to HIGH. In the Field Calculator.cfm Now examine the first line of code under Pre-Logic Script Code: def label(name.esri. Examine the next line of code.. Note: Remember.Where do I acce.. Python enforces indentation as part of its syntax. the next condition will be evaluated: elif type == "MIDDLE": The elif statement ("else if") will check whether the type variable is equal to MIDDLE. 23 of 37 11/10/2011 11:43 AM . return the school's name concatenated to the text string ELEM. The colon tells Python to execute the next line(s) if the condition is true. Examine the next line of Python code: if type == "HIGH": This line compares the attribute value held in the type variable to a text string. HIGH. add the necessary code that will check if the type variable is equal to ELEMENTARY. http://training.. The label function reads the NAME and TYPE attribute values and holds them in two new variables: name and type. type): A function named label is created (or defined) with the def statement.g. Notice the elif statement is indented to the same level as the first if statement. Using your knowledge of Python and the previous code example. The return statement will combine the value in the name variable with the text string HS.

type): if type == "HIGH": return name + " HS" if type == "MIDDLE": return name + " MS" elif type == "ELEMENTARY": return name + " ELEM" After you have entered your new code.cfm def label(name. Step 7: Edit a script to accept user input 24 of 37 11/10/2011 11:43 AM .esri. http://training.. Minimize ArcMap.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. Step 6c: Create a multiline calculation expression. Close the attribute table. I received an error.Where do I acce. click OK.com/Courses/PythonDesktop10_0/player. Examine your new calculated values in the MAP_LABEL attribute field..

esri.GetParameterAsText(0) Verify that your line of code looks like this: inFCs = arcpy.. http://training.GetParameterAsText(0) The GetParameterAsText function will allow you to type an input value that will be used by the script. and dist. Although the script will run with these hard-coded values. The value you enter will be stored in the inFCs variable. choose Save As. Save your script in your .cfm In this step.com/Courses/PythonDesktop10_0/player. Open the Buffer_HardCoded.py script.\PythonDesktop10_0 folder. Open PythonWin. the variable which stores the buffer distance is set to a value of 1000 in the script.Where do I acce. choose Open and browse to your . outWS. From the File menu.. Notice that the values for these variables are already set within the script. you would have to edit the script each time you wished to use a different distance.py.. it is not very flexible. 25 of 37 11/10/2011 11:43 AM . For example..Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. From the File menu. you will see how you can make your Python script accept your input rather than using hard-coded values. read the comments describing the author and purpose. Read the comments describing the three variables in this script: inFCs. Before you convert this script to a script tool.\PythonDesktop10_0 folder with the name Buffer_multiple. you will remove the hard-coded values and replace them with a Python function that will allow you to provide your own input. At the top of the script. If you wanted to run the script with a different buffer distance. Locate the following code in your script: inFCs = "C:/Student/PythonDesktop10_0/Data/Shapefiles/Schools.shp" Delete the pathname (and the quotes) and replace it with: arcpy.

\PythonDesktop10_0 folder.GetParameterAsText(2) Notice that the GetParameterAsText value for inFCs is 0 and increments up to a value of 2 for the dist variable. Save your Buffer_multiple. from the Python window. and then dist). Once a script is part of ArcToolbox.cfm Using the same technique.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. http://training. it behaves like any other tool. This function is referred to as being zero-based. Open the Catalog window and navigate to your .py script. you will need to create a toolbox to store the script. you will create a tool in ArcToolbox from your Python script.. This means you can run the script from a dialog box. or from a model. Right-click Toolbox and choose Properties. Restore ArcMap.GetParameterAsText(1) dist = arcpy. as shown below. 26 of 37 11/10/2011 11:43 AM . In the Toolbox Properties dialog box.esri. meaning the first input value. Now you are ready create a script tool from your modified script. Before you can add a script tool. Step 8: Create a script tool In this step.Where do I acce. This is the order in which your input values will be assigned in your Python script (i. followed by outWS. Right-click the Data folder and choose New > Toolbox. inFCs is the first input value..e..com/Courses/PythonDesktop10_0/player. make the following changes to the outWS and dist variables: outWS = arcpy. A new toolbox is created in your Data folder. enter Westerville for both the Name and Label properties. will be item 0. Close PythonWin..

cfm Step 8a: Create a script tool. The Name is used to execute the script tool from the Command Line window or from another script. http://training.com/Courses/PythonDesktop10_0/player.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. Click OK. choose Add > Script. and will determine how it appears in the ArcToolbox window.. Next. Right-click the Westerville toolbox. The following rules apply to the Name and Label properties: The Name cannot contain spaces or underscores.esri. set the following: Name: BufferMultiple Label: Buffer Multiple Description: Buffer multiple feature classes View result 27 of 37 11/10/2011 11:43 AM .Where do I acce.. and Description. The first panel asks for the script tool's Name. In the Add Script wizard. Labels may contain spaces or other special characters. you will add your script as a tool in your new toolbox. Label. The Add Script wizard opens. The Label is the display name for the script.

esri. Click Next.cfm Step 8b: Create a script tool. outWS.com/Courses/PythonDesktop10_0/player. Under Data Type...\PythonDesktop10_0 folder. On this panel. Now you will enter the three script arguments for the inFCs. do the following: For the first argument. View result 28 of 37 11/10/2011 11:43 AM .Where do I acce. click in the first empty field under Display Name and type Feature classes to buffer. and click Open. http://training. Navigate to your . Click Next. Under Parameter Properties.. click in the first empty row and choose Feature Layer from the drop-down list. Click the Browse button . select Buffer_multiple.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. and dist variables that you coded in a previous step. click in the Value column for MultiValue and choose Yes from the drop-down list.py.

you are enabling your script to accept multiple feature classes as input. The inFCs variable will store the list of feature classes.Where do I acce.GetParameterAsText(0) function.esri... 29 of 37 11/10/2011 11:43 AM . for Environment: Current Workspace [workspace] Note: You can move the vertical divider to the left of Display Name to view the entire contents of the column.com/Courses/PythonDesktop10_0/player. specify the following: Display Name: Output location Data Type: Workspace or Feature Dataset Under Parameter Properties.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. By setting the MultiValue property to Yes. http://training. which will set the value of the inFCs variable. For the second argument.cfm Step 8c: Create a script tool. The input feature classes will be associated with the arcpy.

http://training. The Output location will be associated with the arcpy.GetParameterAsText(1) function.com/Courses/PythonDesktop10_0/player.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error.. for Filter: Range In the Range dialog box that opens. 30 of 37 11/10/2011 11:43 AM .esri. set the following: Minimum Value: 500 Maximum Value: 1500 Click OK. set the following: Display Name: Distance Data Type: Double Under Parameter Properties.Where do I acce. For the last argument (the buffer distance). which will set the value of the outFC variable..cfm Step 8d: Create a script tool.

in this case. Verify that your Add Script dialog box matches the following graphic: Click Finish.esri..com/Courses/PythonDesktop10_0/player. you are restricting the buffer distance to a set of acceptable values for your application.Where do I acce. By setting a range filter. 31 of 37 11/10/2011 11:43 AM . if necessary.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. Open the Catalog window and. http://training. expand your Westerville toolbox.cfm Step 8e: Create a script tool. values between 500 and 1500 feet..

Note: Your script tool can support multiple input feature classes. you will run your new Buffer Multiple script tool.cfm Step 8f: Create a script tool. http://training. Step 9: Run your script tool In this step. In your Westerville toolbox. Step 9a: Run your script tool.com/Courses/PythonDesktop10_0/player. for this example...Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. 32 of 37 11/10/2011 11:43 AM .esri. double-click the Buffer Multiple script tool. For Feature classes to buffer. Your new Script tool named Buffer Multiple is now available in your toolbox. However. click the down arrow and choose Schools.Where do I acce.

. close the status window.com/Courses/PythonDesktop10_0/player. 33 of 37 11/10/2011 11:43 AM .\PythonDesktop10_0\Data\Westerville.Where do I acce. Your Python code named the output feature class with the name of the layer (in this case. Notice it contains a new feature class named Schools_buffer. browse to .\PythonDesktop10_0\Data\Westerville. Open the Catalog window.esri.. Schools). Click OK to run the Buffer Multiple tool.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. Drag the Schools_buffer feature class onto your map. For Distance.gdb geodatabase. For Output location. Navigate to and expand your .cfm you will only buffer the Schools feature class.. type 500. This new feature class was created when you ran your script tool. http://training.gdb and click Add. When the process has finished. followed by _buffer.. Step 9b: Run your script tool.

Click the Source tab. click the Python window button From the Geoprocessing menu. 34 of 37 11/10/2011 11:43 AM . Open the layer properties for the Streets layer.esri. Open the Python window. making sure it is exactly as shown in above. Imagine that you have migrated all of these shapefiles to a file geodatabase. In this step.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. You are setting a variable named mxd equal to the map document in which you are currently working. In the Python window.. Note: If you receive an error message. ... you will use Python to change the source of the layers in your map from shapefiles to their equivalent geodatabase feature classes. Using Python. you will set the source workspace for each layer from the Shapefiles folder to the Westerville geodatabase in your . reference shapefiles.com/Courses/PythonDesktop10_0/player. http://training. choose Python. Remind me how You can add Python window in two ways: From the Standard toolbar.\PythonDesktop10_0\Data folder. This map document is referenced by the CURRENT keyword. enter the following line of code: mxd = arcpy.MapDocument("CURRENT") Press Enter. reenter the line of code again. What is the workspace path for the streets data? Close Layer Properties.Where do I acce. You will then save a copy of your map document with the layers that point to the new geodatabase feature classes.cfm Step 10: Associate map layers with different source data All of the layers in your map document. with the exception of the newly created Schools_buffer layer.mapping.

Where do I acce. Old workspace path Old workspace type New workspace path New workspace type Validate (optional) In your map document..MapDocument("CURRENT") >>> mxd. http://training. 35 of 37 11/10/2011 11:43 AM . choose replaceWorkspaces and press your Tab key. In the Python window. Verify that your Python window matches the following code: >>> mxd = arcpy.replaceWorkspaces Type a left parenthesis and notice that the usage for the replaceWorkspaces appears in the help portion of the Python window.mapping. type: mxd. This function has four required arguments and one optional argument.rep From the drop-down list. you will use the replaceWorkspaces function.com/Courses/PythonDesktop10_0/player. the old workspace will reference the shapefiles folder and the new workspace will be your Westerville geodatabase.cfm Next.esri.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error..

Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error.esri.. the workspace is not replaced.cfm Step 10a: Associate map layers with different source data. checks to see if the new_workspace_path is a valid workspace. For the first argument. then type the new_workspace_type: "FILEGDB_WORKSPACE" Note: The optional argument. Type a comma.gdb" For the final argument. You will not enter a value for the validate argument. Step 10b: Associate map layers with different source data. the old_workspace_path. If it is not. then type the new_workspace_path: "C:/Student/PythonDesktop10_0/Data/Westerville..com/Courses/PythonDesktop10_0/player. 36 of 37 11/10/2011 11:43 AM . http://training. type: "C:/Student/PythonDesktop10_0/Data/Shapefiles" Type a comma. Type a right parenthesis ) to finish your line of code. your code may wrap to the next line. Validate.Where do I acce. then type the second argument (old_workspace_type): "SHAPEFILE_WORKSPACE" Note: Depending on the width or your Python window. type a comma.

leaving the existing map document unchanged.Where do I acce.cfm Press Enter to execute the replaceWorkspaces function. You have saved your map as a new .. 37 of 37 11/10/2011 11:43 AM ..mxd") Press Enter.esri. Close ArcMap without saving your changes.Exercise: Use Python in ArcGIS Desktop 10 Print Window I received an error. Open the layer properties for the Streets layer. In the Python window.mxd file. Do you see that the path has changed? The data source now points to the Westerville geodatabase. You can also use the Python window to save your map document.saveACopy("C:/Student/PythonDesktop10_0/Westerville_New. type: mxd.com/Courses/PythonDesktop10_0/player. You will save your current map with another name. http://training.

Sign up to vote on this title
UsefulNot useful