A PYTHON PRIMER FOR ARCGIS PDF

adminComment(0)

A Python Primer for the GIS Professional. • What is a script? Why automate a task ? • What is Python? What can Python do? Why use it? • What is ArcPy?. University of Pennsylvania. • ESRI Conference Workshop: Python. Essentials in ArcGIS-I. • LinuxWorld Tutorial: Introduction to. Python by Guido van. Python Scripting for ArcGIS. Nathan Jennings is experienced in GIS, Remote Sensing, GPS, GIS for web, geospatial technology, consulting, and business systems integration. This book is a poor, poor choice for anyone wanting to learn Python scripting in an ArcGIS environment, or any.


A Python Primer For Arcgis Pdf

Author:FREDERICK PITSTICK
Language:English, Indonesian, Arabic
Country:Estonia
Genre:Environment
Pages:666
Published (Last):17.02.2016
ISBN:856-5-15975-322-7
ePub File Size:26.50 MB
PDF File Size:12.72 MB
Distribution:Free* [*Sign up for free]
Downloads:23744
Uploaded by: JARRETT

Examples, Python and ArcGIS, Python versions. • Fundamentals of geoprocessing in ArcGIS. • Python language fundamentals. – Where to run Python code. Demonstrate how to build a Python script that uses ArcMap tools Manual process (e.g. following documentation/tutorial). • Difficult to share. Using ArcGIS and Python. Nick Santos, Josh Viers, and Anna Fryjoff-Hung. Feb University Extension. Contact: [email protected]

Joins, relates and further SQL knowledge is greatly valued in the field.

Customers who viewed this item also viewed

When given a database, explore the data models within it. Understand the structure of the database. This database design structure are often represented in UML diagrams.

Most design work for data models use it. Come up with a project and practice using your new SQL skills. If an employer asks for a portfolio, you have some good examples to share.

This is because R can visualize and analyze spatial data. It places emphasis on statistics, but it can do both.

And for this reason, R is often recommended:. OOP is about maintaining code as objects and reusing code through instantiation. And you should too! GitHub is like a Facebook for developers. Developers can inspect the entire history of a project by version. Test it out, and it might be a good investment to start in Python. Thanks to Reddit user Korlyth for his contributions and inspiration to us for creating this post. This list of earth-shattering remote sensing applications will change the way you feel about how this industry is changing our world and the way we think.

This post has really given me a road map to greatness. I am no longer confused on what path to take. Very interesting with lots of inspiring and thought provoking suggestions.

Thank you very much for the motivation. Thanks a ton! Thanks for this article. It has helped me streamline my thoughts and also provide a well-needed roadmap for my GIS Programming journey. Save my name, email, and website in this browser for the next time I comment. December 6, Remote Sensing. GIS Career. Leave a Reply Cancel reply Your email address will not be published.

We use cookies to optimize site functionality and give you the best possible experience. Data valueField String Property Explanation A string that represents a valid dataset field name used for the Type layer's classification symbology.

Changing this value will Read and Write automatically adjust other symbology properties based on the classBreakDescriptions A sorted list of strings that represent the descriptions for each List new information. These values are only accessible in the ArcMap user interface by right-clicking a symbol displayed within the Symbologytab in the Layer Properties dialog box and Method Overview selecting Edit Description.

The number of descriptions in the Method Explanation sorted list must always be one less than the number of classBreakValues. This is because the classBreakValues list also includes a minimum value reclassify Resets the layer's symbology to the layer's data source information and statistics. These values are affected by changes to nearly all other class properties, so it is best practice to set these values last.

The number of labels in the sorted list must always be one less than the number of classBreakValues. This is because the classBreakValues list also includes a The reclassify method updates a layer's symbology properties based on the minimum value which you don't see in the user interface. These underlying source data. It is useful when a layer's symbology is updated using values are affected by changes to nearly all other class the UpdateLayer function with symbology stored in another layer or layer file properties so it is best practice to set these values last.

This method will automatically update the symbology properties based on classBreakValues A sorted list of doubles that includes the minimum and List maximum values that represent the class breaks. When the layer's actual data source information and statistics and not the information Read and Write settingclassBreakValues, it will automatically set that is persisted in a layer file.

The method needs to be used cautiously because it the numClasses property and will also set the classification has the potential to overwrite other symbology properties.

Unlike the ArcMap user interface, regenerate classBreakValues, classBreakLabels, you have the ability to set a minimum value. The first value in the sorted list represents the minimum value and the remaining and classBreakDescriptions.

It will not values are the class breaks that appear in the user interface; affectnumClasses or normalization.

The reclassify method has no affect therefore, there will always be one more item in on a manual classification. This value cannot be set if the classification method is manual; therefore, numClasses should not be called after the classBreakValues property because it will automatically set the classification method to manual.

Code Sample GraduatedSymbolsSymbology example 2 GraduatedSymbolsSymbology example 1 The following script modifies the symbology for a layer in a map document.

It first The following script modifies the symbology for all layers in a map document. It updates the layer's symbology using a layer file on disk with iterates through each layer, changes the value field, changes the number of the UpdateLayer function. Next, it verifies that the layer has graduated symbols classes, and saves the map document.

Finally, the script modifies a number of the properties on the GraduatedSymbolsSymbology class and exports the result to PDF. ListDataFrames mxd, "Census" [0] if lyr. Summary X and Y element positions are based on the element's anchor position which is also set via the Size and Position tab on the Properties dialog box in ArcMap.

It includes items such as groups of elements, inserted tables, graphs, neatlines, markers, lines, area shapes, and so on, that are added elementHeight Double to a page layout. The most common operations on a graphic element are to get or The height of the element in page units.

The units assigned or set its page layout position and size. The ListLayoutElements function returns a reported are in page units. Read and Write Python list of page layout element objects.

It is necessary to then iterate through each item in the list or specify an index number to reference a specific page elementPositionX Double The x location of the data frame element's anchor position. The element object. To return a list of only GraphicElements, use the units assigned or reported are in page units.

The Esri Community

A wildcard can Read and Write also be used to further refine the search based on the element name. This capability was initially The y location of the data frame element's anchor position. To accomplish this, a map document must be authored with at least two graphic line elements: The units assigned or line and a horizontal line.

As the information is read from a table, the lines can be reported are in page units. Read and Write cloned using the clone method and sized and positioned appropriately using other graphic element properties. When cloning an element it is very useful to isGroup Returns True if the layout element is a group element.

It is not Boolean provide a suffix value so that cloned elements can be easily identified while possible to clone or delete group elements. The returned list of elements can be further modified or deleted using the delete method.

There is a complete code sample for building a name String The name of the element. Read and Write Grouped graphic elements cannot be cloned. That is because grouped elements may include more than just graphic elements; they could also include items like type String north arrows, scale bars and so on.

Use the isGroup property to Returns the element type for any given page layout element. Method Overview GraphicElement example 2 Method Explanation The following script will construct a graphic table based on data values from a table in the map document. Each of the elements were authored with the appropriate delete Provides a mechanism to delete an existing graphic element on a page layout. The element's anchors were also set to the upper left position and the text element's vertical and horizontal justification were set to top Methods left.

The String Reference items in the map document new element will get the same element name as the parent graphic plus the suffix value plus a numeric sequencer. First check to see if a graphic element is grouped by using the isGroup property. SearchCursor lyr.

Discussion Read and Write The LabelClass object is essential for managing properties, such as label expression String expressions or SQL queries, that are associated with a layer's individual label Provides the ability to get or set a layer's individual label class expression. This can be as simple as a single field or more advanced classes. Access to these properties is essential when, for example, a map document's layers are redirected to a new workspace. This is useful for restricting labels to certain features.

Read and Write executed against. For example, field names in a personal geodatabase are surrounded by square brackets while field names in the file geodatabase are showClassLabels Boolean Provides the ability get or set the visibility of individual label surrounded with double quotes.

In addition to field names, other SQL properties classes. If the SQL query is not updated, layers may fail to draw. For more information on these special cases, refer to the Updating and fixing data sources within arcpy. The script first confirms that the change. Area and perimeter are commonly used fields in an expression, and layer supports the labelClasses property. If a layer supports labels, it also will support the labelClasses property, if lyr.

The labelClasses property will return a list of LabelClass objects. To reference if lblClass. A new output map document is saved, preserving the original map document. There are two Top ways of determining if a layer is a group layer.

First, you can check to see if the layer supports the isGroupLayerproperty. Second, you can evaluate Summary the longNameproperty. A layer's longName value will include the group name in Provides access to layer properties and methods.

It can either reference layers in addition to the layer name. For example, a layer named Layer1 in a group layer a map document. If the name value Discussion is equal to longName value, then the layer is not a group layer or the layer is not The Layer object is essential for managing layers that reside within a map inside a group layer. The layer object provides access Some layers within a map document or layer file may be password protected to many of the common layer properties found in the ArcMap Layer because the user and password information is not saved within the layer file or Properties dialog box and it also provides methods for saving layer files.

Map documents that contain these layers will prompt the user to The Layer function, the ListLayers function and enter the appropriate information while the document is opening. The the listLegendItemLayers method on the Legend object all provide ways to arcpy. In other words, secured layers will not be rendered in properties. For example, a feature layer supports a definition query whereas a any output. If it is necessary for these layers to render appropriately, then there raster layer does not, but a raster catalog does.

Rather than having to work with are a couple of options. First, save the user name and password information with different, individual layer objects for all possible layer types and property the layers. Second, the CreateArcSDEConnectionFile geoprocessing function combinations, a supports method is available to help identify which layer types allows you to create a connection file that is also persisted in memory. If this support which individual layer properties.

The supports method gives you the function is executed prior to opening a map document. Currently, there is no alternative for secured web services. The variable that references a layer file on disk will place a lock on the. There are essentially three categories of layers in a map document: There are two methods layer types but not all layer types. There are a few specialized layers and datasets on the Layer object that help with this.

In all of a layer's workspace path. The replaceDataSource method allows you to these cases you may need to test other properties to isolate a layer of interest change a layer's workspace and source dataset. For a more detailed discussion, before doing something to it. There are many and fixing data sources with arcpy. There exposed to the arcpy scripting environment for example, display properties, field are a limited number of supported symbology types for which properties and aliases, selection symbology, and so on.

The UpdateLayer function allows you to methods are available. It is good practice to first test the replace all layer properties available in the ArcMap Layer Properties dialog box layer'ssymbologyType property. If the value returned is not OTHER, then the Group layers and other sublayers for example, annotation classes are treated layer's symbology property will return one of the following symbology classes, just like ordinary layers.

The ListLayers function returns index values that are each with their own unique set of methods and generated from top to bottom as they appear in the table of contents or the way properties: The same applies if a group layer is within assifiedSymbology, and UniqueValuesSymbology.

Not all definitionQuery Provides the ability to get or set a layer's definition query. String layer types support time properties. Therefore, it is good practice to first test if the Not all layers support the definitionQuery property Read and Write for example, raster layers and group layers , so it is good layer supports time using the supports method.

If the layer does support time, practice to test for this ahead of time using then time properties can be accessed from the LayerTime class. Data isBroken Returns True if a layer's data source is broken. The Integer extension layer type. Enter a plus or minus sign to the left of the value to specify whether it is above or below 0. Not all layers support thebrightness property for example, isRasterizingLayer Returns True if a layer will cause rasterization of other Boolean group layers and feature layers , so it is good practice to test vector layers in the data frame when the map is printed or for this ahead of time using thesupports method.

Read Only exported. Rasterization of vector layers during output most often occurs when layer transparency is used but can also contrast Provides the ability to get or set the contrast value. Enter any value between field-based transparency. Not all isRasterLayer Returns True if a layer is a raster layer.

Boolean layers support thecontrast property for example, annotation layers and fabric layers , so it is good practice to Read Only test for this ahead of time using the supports method. GIS services Boolean Provides the ability to either get or set the layer's credits or are automated geographic information services that are copyright information. Read Only published and accessed over the web using standard Read and Write technologies and protocols.

Not all layers support returning a list of LabelClass objects. Read Only thedatasetName property for example, web services , Read and Write Individual LabelClass object properties can be read and so it is good practice to test for this ahead of time using modified and written back to the layer.

Not all layers the supportsmethod. It String for this ahead of time using the supports method. Not all layers longName This property is valuable when trying to determine whether String support the dataSource property for example, a layer belongs to a group layer. If a layer does not belong annotation classes and web services , so it is good practice Read Only to a group layer, the long name will equal the layer name.

If a layer does belong to a group layer, the group layer to test for this ahead of time using the supports method. If the support this property. Provides the ability to set or get the layer's maximum scale threshold. If the service is not password protected, this property will be null. Property threshold.

Programming in ArcGIS with Python – A Beginners Guide

Property displays the text string for the WMS service used for name String machine-to-machine communication. Provides the ability to set or get the name of a layer the way it would appear in the ArcMap table of contents. All layer types support this property. The returned results are dictionary key- machine communication. Property displays the based on the type of layer. The web services dictionary contains keys that work showLabels Controls the display of labels for a layer.

If set to True, Boolean for all service layer types and also includes specific keys labels will display; if set to False, labels will not be that work for only a particular web service type for Read and Write drawn. Either your for example, raster layers and annotation layers , so it is script can check the ServiceType key before evaluating good practice to test for this ahead of time using specific keys or you can use the get method that allows the supports method.

Layer types that support you to bypass keys that are not available. Not all layers the showLabels property also support support the serviceProperties property for the labelClassesproperty.

Each Object so it is good practice to test for this ahead of time using supported layer symbology class has its own unique set of the supports method. Read Only properties.

Not all layer symbology class types are supported; for where the ArcSDE geodatabase is located. This is not required when using Oracle. This will be blank if using The GraduatedSymbolsSymbology class. The RasterClassifiedSymbology class for raster layers. Integer This enables you to see through a layer to the layers Read and Write underneath. Type 0if you don't want a layer to be Methods transparent. Type visible Controls the display of a layer. This has the same effect as Boolean checking the check box next to the layer in the table of contents in ArcMap.

If an empty string is passed, then all set to False, the layer will not be drawn. String A string that represents the workspace path or connection Not all layers support the workspacePath property for file you want to replace. Read Only example, web services , so it is good practice to test for this ahead of time using the supports method.

If it is not valid, the workspace will not be Method Overview replaced. In this case, if a match does not exist, then the layer's data source would be broken. Returns a layer's geometric or symbolized extent. The supports property can be used to test which Return Value properties a layer does support. Returning a symbolized extent may be best for Parameter Explanation Type cartographic results because symbols won't be cut off at the data frame's edges. A geometric extent may be best for analysis.

Returning a symbolized extent may be best for the replaceDataSource method will attempt to replace the cartographic results because symbols won't be cut off at the data frame's edges. A dataset by finding a table with a the same name as the layer's current geometric extent may be best for analysis. If it is not valid, the workspace will not be replaced. In this case, if a match does not exist, then the data source would be broken.

The default value is True For more detailed discussion, parameter information, scenarios, and code samples, please refer to the Updating and fixing data sources with arcpy. The save method only works when a variable references a Type layer file and will not work with a map layer.

When a layer is loaded from a layer file it will remember the file name and use that when the save method is called. Features that are not supported in prior versions of The default value is name the software will be removed from the newly saved layer. Return Value Data Type Explanation Boolean There are numerous types of layers and not all of them support the same properties. For example, a feature layer supports a definition query whereas a raster layer does not, but a raster catalog does.

Rather than creating individual layer objects for all possible layer types and property combinations, a support method was created to help identify which layer types support which properties. The support method gives you the option of testing the property before trying to get or set its value on a layer type that doesn't support it.

The supports property will return a true if a layer supports that property. Code Sample Layer example 2 Layer example 1 The following script will allow secured layers to render correctly by creating an The following script will reference a layer. This script simply defines the connection information, then exports the map document to a PDF file. It is good practice to delete this reference from memory before the script closes.

ListLayers lyrFile: Create temporary connection file in memory import arcpy arcpy. ListLayers lyrFile, "Highways": Similar to the example above, since some else: It first The following script tests if a layer file supports time and if time properties have updates the layer's symbology using a layer file on disk with been set. It then uses time information start time and end time to calculate the the UpdateLayer function.

The layer file contains a custom color ramp that is time extent of a time-enabled layer. Finally, the script modifies a number of the properties on the GraduatedColors symbology class and exports the result to PDF.

Layer r'C: ListLayers mxd, "StatePopulation", df [0] if lyr. Daylight Saving Time rules in the input time zone. The LayerTime object provides information about how time is stored and Read Only configured in a time-enabled layer.

Gets the end date and time for a time-enabled layer. Learn more about setting time properties on a layer Read Only The time properties on a layer are read-only. The UpdateLayerTime function allows you to replace all layer properties available on the Time tab of the Layer endTimeField String The name of the field containing the end time values.

Properties dialog box using a layer. Example one below shows how you can get the time extent of startTime DateTime your time-enabled layer using the startTime andendTime. Example two below Gets the start date and time for a time-enabled layer. Also, you can use the time information to ensure that the time specified for startTimeField String The name of the field containing the time values.

This selecting the features lies within the start and end time of the layer. Example three shows how you timeFormat String can step through your data based on time using thetimeStepInterval property The format in which the time values were stored in the input time field. The time format is important when and generate surfaces from features valid at various time steps. Note that Read Only formulating a time query. The time-step interval can be thought of Read Only as how often the time values were recorded in your data.

This value is a EsriTimeDelta object and is used to iterate over a period of time for example, 2 days, 1 month, and so on. It then uses time information start time and end time to calculate the Get the start and end time of the time enabled layer time extent of a time-enabled layer. Feature Class to Feature Class else: CheckOutExtension "spatial" print outRaster arcpy. This can be accomplished using the following workflow. It is recommended that each page layout element be given a unique name so that it can be easily isolated using ArcPy scripting.

Like a MapsurroundElement, the LegendElement object has an association with a single parent data frame.

In addition, the LegendElement also has methods X and Y element positions are based on the element's anchor position, which is and properties for managing the contents within the legend.

It is necessary to then iterate through each item in the list or specify an Data index number to reference a specific page element object. A wildcard can also be used to further refine the autoAdd Controls whether a layer should be automatically added to Boolean search based on the element name.

This property called Add a new item to the legend when a new layer is added to the map which mimics the Map Connection check box option labeled Add a new item to legend when a new layer is added to the map, allows the legend to automatically update when layers are added or removed from found via the Legend Properties dialog box's Item tab.

For example, you The height of the element in page units. Legend elements in the ArcMap user interface also have a property called Fixed The units assigned or reported are in page units. Read and Write Frame. When this property is toggled on and too many legend items get added, there may not be enough room for all items to fit within the fixed area specified.

The isOverflowing property allows you Read and Write to check for this, then resize the legend element or modify the legend items appropriately by providing a legend item style item that uses smaller fonts, for elementWidth Double The width of the element in page units.

The units assigned or example. Read and Write The removeItem and updateItem properties serve a basic arcpy. In the user interface, when you add a new layer to the Frame option is set within legend properties.

The arcpy. Read Only name String The name of the element. The default value is 1 Read and Write There are plenty of cases where there is not enough space on a layout to fit all type String Returns the element type for any given page layout element.

Another method would be to count the number of items in a legend. Each legend item references a layer. Provides a mechanism to set the number of columns in a legend. It is possible that a layer can layout.

Data Driven Pages must be enabled. Long The default value is False The index value provides a way to reference a specific legend item. If you have more than one item and you want to remove all index A single layer can be added into the same legend multiple Long instances, then the removeItem will need to be called multiple times.

The index value provides a way to reference a times. By default the first legend item for a layer is removed. If you have more than one item and you want to remove all instances, then The default value is 0 the updateItem method will need to be called multiple times.

By default the first legend item for a layer is updated. There may be times when you want to remove an item from the legend. For The default value is 0 example, a legend item for orthophotography doesn't really make sense to have in a legend.

The removeItem method allows you to remove an individual legend item from the legend on a layout after it has been automatically added.

Another The updateItem method serves a basic arcpy. In the user interface, when newly added layer will get automatically added to the legend. This item must come from the style folder name Legend Items. If set to True, the sizes authored in the style item will remain unchanged. A layer is added to the first data frame in the map document and the legend that includes an inserted legend element named Legend.

The layers will item will be updated with a custom legend item style item automatically get added to the legend except for the orthophoto. This is controlled calledNewDefaultLegendStyle. The custom. Finally, after the layers are added, the number of profile location. Next, the script checks to see if the legend is overflowing, and if it columns are adjusted to two.

ListLayers mxd, "County Boundary" [0] arcpy. The following script works with a legend element with Fixed Frame toggled on. If the legend items are overflowing, the script will increase the height of the legend import arcpy by 0.

Top It is very important to understand how variables reference MapDocument objects Summary in the scripting environment, especially when you are saving your results to a new file. You must understand that when you initially create a variable that references Provides access to map document. A reference to a MapDocument object, it will always point to the original map document on disk this object is essential for most map scripting operations. In the ArcMap application, if you perform a SaveAs to a new file location, all subsequent changes are directed to the new Discussion file.

This is not possible within the scripting environment, and therefore, The MapDocument object is usually one of the first object references created in a a saveAs method is not provided. The MapDocument class map automation script because it is a required parameter for many of has save and saveACopy methods for managing modifications to a map the arcpy. It is through the MapDocument object that you document. The executed line of code. To refresh the map document to reflect the changes, use object also contains methods for managing map document thumbnails and either the RefreshActiveView or RefreshTOC functions.

These functions will methods for saving map documents that are found within the ArcMap File menu. The There are two different ways that a MapDocument object can be created using refresh functions are only needed if you want to see the application updated. The first, and most recommended, method is to Arcpy. This updated results without using these functions. Referencing a specific map document on disk provides more control in because the user and password information is not saved within the layer file or terms of how the script will execute because a given script may not work on all map document.

Map documents that contain these layers will prompt the user to map documents. This technique only works from within an ArcMap during execution, but that means that the layers will be treated as though they application because the MapDocument object references the map document that have broken data sources. In other words, secured layers will not be rendered in is currently loaded into the ArcMap application. If it is necessary for these layers to render appropriately, then there when quickly testing and learning the scripting capabilities and command syntax are a couple of options.

First, save the user name and password information with within the Python window. You may start off learning the syntax in the Python the layers. Second, the CreateArcSDEConnectionFile geoprocessing function window, then start pasting those lines of code into a more permanent script saved allows you to create a connection that persists in memory.

If this command is used to disk. Currently, there is from a custom menu or the Catalog window. For this same The variable that references the MapDocument object will place a lock on the map reason, if a script tool has a validation script that includes a reference to CURRENT, document file.

It is good practice to remove the Map Document object reference an error may occur if you try to edit the validation script from ArcCatalog. There are disabled. Background processing runs all scripts as though they were being run as two methods on the MapDocument object that help with this.

There is a all of a layer's or table's workspace path. For more dateExported Returns a Python datetime object that reports the date the DateTime detailed discussion, parameter information, scenarios, and code samples, please last time the map document was exported. This value is only Read Only current if the map document was saved after the map was refer to the Updating and fixing data sources with arcpy.

The activeDataFrameproperty will return the Read and Write Read Only appropriate data frame even if the map document is in page layout view. The Read and Write property works with a string that represents the active data pageSize Provides the ability to get the layout's page size.

If activeView is a map document's page width and height. Read and Write deleteThumbnail tags String This performs the same operation as clicking the Delete Thumbnail button on Provides the ability to either get or set the map document's tag information.

Separate tags with a single comma ,. If an empty string is passed, then all workspace paths will be replaced with deleteThumbnail Deletes a map document's. If it is not valid, the workspace will not be image replaced. In this case, if a match does not document. The default value is True save Saves a map document. If it Type is not valid, the workspace will not be replaced. In you want to find. If an empty string is passed, then all this case, if a match does not exist, then the data sources would workspace paths will be replaced with be broken.

If an empty string is passed, multiple samples, please refer to the Updating and Fixing Data Sources with workspaces can be redirected into one workspace. The default value will use the current version. This sample will update the first data frame's name and document. The output map documents will be saved in data view mode so when refresh the table of contents so the change can be see in the application. Paste each map document is opened, the corresponding data frame will be active data the following code into the Python window within a new ArcMap document.

The script also sets the title property of each output map document. ListDataFrames mxd [0]. Python strings cannot end with a backslash, arcpy. RefreshTOC even when the string is preceded by an r. You must use a double backslash. This del mxd becomes important when appending dynamic file names to a folder path. You must press the Enter key to execute these lines. MapDocument example 3 MapDocument example 4 The following is another simple script that demonstrates the use of The following script will allow secured layers to render correctly by creating an the CURRENT keyword within the Python window.

Each layer name will be printed SDE connection in memory before opening a map document that requires to the Python window. Loops are also possible, provided that you maintain the password information. This script simply defines the connection information and correct indentation.

Similar to the example above, paste the code below into the exports the map document to a PDF file. It is good practice to delete this reference Python window. When pasted into the interactive window it will appear as follows. Again, press the os. Summary Read and Write Provides access to properties that enables its repositioning on the page layout as parentDataFrameName A string that represents the name of the DataFrame for the String well as identifying its parent data frame.

Read Only Discussion A MapsurroundElement object is a page element that has an association with a type String Returns the element type for any given page layout data frame. For example, there is a one-to-one relationship between a north arrow element. Read Only and a data frame. A Code Sample wildcard can also be used to further refine the search based on the element name. MapsurroundElement example It is recommended that each page layout element be given a unique name so that The following script will find the mapsurround element named ScaleBar and it can be easily isolated using arcpy scripting.

X and Y element positions are change it's position. ListDataFrames mxd, scaleBar. Read and Write elementWidth Double The width of the element in page units. PDFDocument arcpy. Allows manipulation of PDF documents, including facilities for merging pages, For more discussion on how to create map books, see the Building Map Books deleting pages, setting document open behavior, adding file attachments, and with ArcGIS help topic. If a PDFDocument object is passed, the method will fail. It is also required that PDF import arcpy, os security be the same for all documents that are being appended, inserted, or attached.

It may take a long time to process dozens of pages. If only a Create the file and append pages relative few have been modified, it is faster to delete only those pages, then insert the newly updated pages using the insertPages method. However, no PDF file will be created until subsequent steps are performed to insert or append pages and save the PDF file.

A common scenario for using this function is the creation of a PDF map book. For example, if the document that is being appended to does an existing PDF document.

If a Parameter Explanation Type script exits before saveAndClose is executed, changes will not be saved. Ranges can also be applied for example, "1, 3, ". Data Parameter Explanation It is important to keep track of the pages that are being deleted, because each Type time pages are deleted, the internal PDF page numbers are automatically adjusted. If page 1 and page 2 are deleted, page 3 becomes page 1.

You need to consider this if you are using deletePages and then immediately The default value is None using appendPages or insertPages. A string that includes the location and name of the input PDF document to be inserted.

The default value is None encryption String import arcpy, os A string that defines the encryption technique used on the PDF. The permissions argument can accept a pdfDoc. The pdfDoc. The master password is required to make this change to a will open. Note how we insert the new page 3 before the current page 3 which was really page 4 before the original page PDFDocument example 3 3 was removed. The same applies to the range of pages 5—7.

The following script will set the user password to esri, encrypt the PDF import arcpy using RC4 compression, and require a password when the document is opened. Discussion elementHeight Double The height of the element in page units. The units assigned or The PictureElement object represents a raster or image that has been inserted reported are in page units.

Read and Write into the page layout. The ListLayoutElements function returns a Python list of page layout element objects. It is necessary to then iterate through each item in the list elementPositionX Double The x location of the data frame element's anchor position. The or specify an index number to reference a specific page element object. To return units assigned or reported are in page units. A wild card can also be used to further refine the elementPositionY Double search based on the element name.

The y location of the data frame element's anchor position. It is recommended that each page layout element be given a unique name so that Read and Write it can be easily isolated in Python. X,Y element positions are based on the element's anchor position, which is set using the Size and Position tab on elementWidth Double The width of the element in page units. The units assigned or the Elements Properties dialog box in ArcMap. Read and Write The PictureElement object has a sourceImage property that allows you to read or modify the picture source location.

If you plan on replacing a picture with name String The name of the element. When a picture is replaced using the sourceImage property and has a different aspect ratio, it will be fit to the area sourceImage String A text string that represents the path to the image data source.

Replaced pictures will never be Read and Write larger than the original authored size. You will also want to set the anchor position so that all new pictures are fit relative to that location.

If you don't want pictures to type String Returns the element type for any given page layout element. There is a different location. The pictures are named Photo1. The first value in The RasterClassifiedSymbology class provides access to different the classBreakValues list is the minimum value; all other values are the class properties that allow you to change the appearance of a layer's raster classified break values as they appear in the ArcMap use interface.

For this reason, symbology. Discussion Setting one parameter will often modify other parameters automatically. For The RasterClassifiedSymbology class provides access to a limited number example, if you set numClasses, normalization, or of properties and methods that allow you to automate layer symbology in a map the valueField parameters, the classBreakValues, classBreakLabels, document.

Basic operations, such as changing the andclassBreakDescriptions properties will automatically be adjusted based number of classes, modifying class break values and labels, or changing the field on the current classification method.

For this reason, the order in which properties that the symbology is based on, are some of the properties that can be modified. For access to the complete set of layer symbology properties and settings, for example, changing individual symbols for individual classes, it is necessary to The reclassify method updates a layer's symbology properties based on the author these changes in the ArcMap user interface and then save those changes underlying source data.

It is useful when a layer's symbology is updated using to a layer file. These custom settings can then be applied to existing layers using the UpdateLayer function with symbology stored in another layer or layer file the UpdateLayer function.

For example, let's say you want to update the color properties of the symbology of a layer in a map document with the symbology stored in a layer file. A layer can use any number of symbologies but not all of them can be modified.

However, the layer in the map document and the layer file have different data Not all layers will use the RasterClassifiedSymbology class, so it is sources. The minimum and maximum values and class breaks in the layer file may important to first test if the layer is using this symbology class before attempting to be different than the layer in the map document. Updating the symbology of the make changes to its properties. The symbologyType property on the Layer class layer in the map document with the symbology stored in the layer file may produce was designed for this purpose.

First test if the symbologyType for the layer is unintended results for example, the class break values will match the layer file's raster classified if lyr. In other words, source data.

You can only change the properties for a specific symbology class on If you are making these symbology modifications via the Python Window and you a layer. The only way to change the symbology type is by publishing the desired are referencing a map document using CURRENT, you may not immediately see result to a layer file and using the UpdateLayer function. The classification method cannot be changed.

In cases where you want to use different classification methods, you would need to preauthor layer files and use those to update a layer, then modify the properties that can be changed. This value cannot be set if the classification method is manual; Data therefore, numClasses should not be called after Property Explanation Type the classBreakValues property because it will automatically set the classification method to manual.

Changing this value will automatically adjust other symbology classBreakDescriptions A sorted list of strings that represent the descriptions for each List properties based on the new information. These values are only accessible in the valueField String A string that represents a valid dataset field name used for the ArcMap user interface by right-clicking a symbol displayed layer's classification symbology. Changing this value will within the Symbologytab in the Layer Properties dialog box Read and Write automatically adjust other symbology properties based on the and selecting Edit Description.

The number of descriptions in new information. This is because the classBreakValues list also includes a minimum value which you don't see in the user interface. These values are Method Overview affected by changes to nearly all other class properties, so it is Method Explanation best practice to set these values last.

The number of labels in the sorted list Resets the layer's symbology to the layer's data source information and statistics. Read and Write must always be one less than the number of classBreakValues. This is because the classBreakValues list also includes a minimum value Methods which you don't see in the user interface.

These values are affected by changes to nearly all other class properties, so it is reclassify best practice to set these values last. When underlying source data. It is useful when a layer's symbology is updated using Read and Write settingclassBreakValues, it will automatically set the UpdateLayer function with symbology stored in another layer or layer file the numClasses property and will also set the classification. This method will automatically update the symbology properties based on method to manual as well as update other properties such as classBreakLabels.

Unlike the ArcMap user interface, the layer's actual data source information and statistics and not the information you have the ability to set a minimum value. The first value in that is persisted in a layer file. The method needs to be used cautiously because it the sorted list represents the minimum value, and the has the potential to overwrite other symbology properties. It will not ns lists. Changing this value will automatically adjust other affectnumClasses or normalization.

The reclassify method has no affect symbology properties based on the new information. For example 1; 3; Read and Write ; and 8. The values are removed from the classification, and therefore, will not be displayed. The following script modifies the symbology for a layer in the current map It first updates the layer's symbology using a layer file on disk with document.

It first verifies that the layer has raster classified symbology.

Finally, it the UpdateLayer function. The layer file contains a custom color ramp that is modifies a number of the properties on theRasterClassifiedSymbology class applied to the layer. Next, it verifies that the layer has raster classified symbology. The script then calls the reclassify method.

This method will update the Since this sample uses the CURRENT keyword to access the map document, it symbology properties based on the layer's actual data source information and must be executed from within ArcMap.

This is because the MapDocument object statistics and not the information that is persisted in a layer file. Finally, the result references the map document that is currently loaded into the ArcMap application.

For more information regarding accessing map documents, see import arcpy the MapDocument class help topic. ListLayers mxd, "lakene. ListDataFrames mxd, "Lakes" [0] arcpy. RefreshActiveView arcpy. A layer is added to the first data frame in the map Provides access to StyleItem class properties. The symbols you choose to display features, elements, or graphics in your map are stored in style files.

You use the Style Manager dialog box to create, view, and modify styles and their contents. ListDataFrames mxd [0] folder name. In the user interface, when you add a new layer to the table to contents, and that feature is automatically added to the legend, a default style is applied. This can be accomplished using the del mxd following workflow. Read Only itemCategory A string that represents the category of the item the way it appears in String the Style Manager dialog box window.

Categories are used to group Read Only symbols within a style. Identifying Read Only thestyleFolderName allows you to determine the type of the style object you have referenced. TableView arcpy. Returns the name of the table's dataset the way it appears in the workspace, not in the table of contents.

Discussion Read Only The TableView object is essential for managing stand-alone tables that reside dataSource Returns table's data source path. It includes String within a map document. It provides access to basic table properties such the workspacePath and the datasetName combined. The TableView constructor function allows you to reference a table outside of a Read and Write map document within a workspace.

This provides the ability to add an external table into a map document using the AddTableView function. This function is name String Provides the ability to set or get the name of a table the way it would similar to MakeTableView, but the difference is that the result from appear in the ArcMap table of contents. Spaces can be included.

MakeTableView can't be added permanently into a map document. It is isBroken Returns True if a table's data source is broken. Boolean necessary to then iterate through each item in the list or specify an index number to reference a specific TableView object. Tables can be searched within an Read Only entire map document or within a specific data frame.

Wildcards can also be used to limit the search. A definition query will not work for all workspaces. For more information on updating Method Explanation workspaces and data sources in a map document or layer file, please refer to the Updating and Fixing Data Sources with arcpy. In this case, if a match does not exist, then the table's data source would be broken. The default value is True For more detailed discussion, parameter information, scenarios, and code samples, please refer to the Updating and Fixing Data Sources help topic.

Code Sample TableView example 2 TableView example 1 The following script will reference a table in a file geodatabase and then add that The following script will find a table called Customers in a data frame table into the referenced map document. ListTableViews mxd, "", df: TableView r"C: AddTableView df, accidentsTable mxd. Double repositioning on the page layout as well as modifying the text string and font size. This elementHeight Double The height of the element in page units. The units assigned or includes items such as inserted text, callouts, rectangle text, titles, and so on.

It reported are in page units. Read and Write also includes text strings that have been grouped into a group element.

A Python Primer for ArcGIS(r) Solutions Manual

It does not include text strings that are part of a legend or inserted table. It is necessary to then iterate through each item in the list or specify an Read and Write index number to reference a specific page element object.

A wildcard can also be used to further refine the units assigned or reported are in page units. Read and Write search based on the element name.

Existing text elements can be cloned and deleted. This capability was initially elementWidth Double added to support the creation of dynamic graphic tables.

To accomplish this, a The width of the element in page units. If column field names have different text property settings than the cell values, then at least two text elements need to be authored.

As the information is fontSize Double The element font size in page units. When cloning an element it is very useful to provide a suffix value so that cloned elements can be easily name String identified while using the ListLayoutElements function with a wildcard and the The name of the element.

The returned list of elements can be further modified or Read and Write deleted using the delete method. The TextElement is also unique from most other page elements in that it has type String Returns the element type for any given page layout element. It is with this property that strings can be read and modified. X and Y element positions are based on the element's anchor position, which is set via theSize and Position tab on the element's properties dialog box in ArcMap.

The String new element will get the same element name as the parent text element plus the suffix value plus a numeric sequencer. Grouped text elements can't be cloned. All grouped elements are graphic element types. First check to see if a graphic element is grouped by using the isGroup property on the GraphicElement object.

Cloned elements, when created, can be given a custom suffix so they can be easy to find when using the wildcard parameter on the ListLayoutElements function.

(PDF Download) A Python Primer for ArcGIS®: Workbook II Download

TextElement example 2 TextElement example 3 The following script will update a static 9. It string to now incorporate the new version 10 dynamic text strings. Current time is essentially sets the initial font size to points and reduces the font size until the appended as a new line below the current date. The text string is set using a text string fits the desired width. The text string is set up as dynamic text that couple of different Python techniques.

All produce the same result. This script will only run properly if you set the title property of the map document. Use triple quotes and put the line break within the string. RefreshActiveView del mxd mxd. The UniqueValuesSymbology class provides access to different properties that allow you to change the appearance of a layer's unique value symbology. Properties Data Property Explanation Discussion Type The UniqueValuesSymbology class provides access to a limited number of properties and methods that allow you to automate layer symbology in a map classDescriptions A list of strings or numbers that represent the descriptions for List each unique value that can optionally appear in a map document's document.

Basic operations such as modifying class Read and Write legend. These values are only accessible in the ArcMap user values and labels, or changing the field that the symbology is based on are some interface by right-clicking a symbol displayed within of the properties that can be modified. For access to the complete set of layer the Symbology tab in the Layer Properties dialog box and symbology properties and settings, for example, changing individual symbols for selecting Edit Description.

The classDescriptions list needs to have the same number of elements and arranged in the individual classes, it is necessary to author these changes in the ArcMap user same order as the classValues property.

These custom settings can classLabels A list of strings or numbers that represent the labels for each List then be applied to existing layers using the UpdateLayer function.

The classDescriptions list needs to Not all layers will use the UniqueValuesSymbology class, so it is important to have the same number of elements and built in the same order as the classValues property. If this property is not set, its values first test if the layer is using this symbology class before attempting to make will be the same as classValues. The symbologyType property on the Layer class was classValues A list of strings or numbers that represent the class breaks.

List designed for this purpose. First test if the symbololgyType for the layer is Changing this property will automatically adjust other unique unique values if lyr.

It is good practice to always set this value before create a variable reference to the UniqueValuesSymbology class for that layer settingclassDescriptions and classLabels.

The symbologyType on the Layer object is a read-only property. In other words, Read and Write you can't change a unique values symbology to a graduated colors or graduated symbols symbology. You can only change the properties for a specific symbology valueField String A string that represents a valid dataset field name used for the class on a layer. The only way to change the symbology type is by publishing the Read and Write layer's unique value symbology. Changing this value will desired result to a layer file and using the UpdateLayer function.

The valueField is used to change the field the unique values are based on. After setting the new field it makes sense to immediately call the addAllValues method so that an updated list of classes is automatically Method Overview generated. Similar to the user interface, calling addAllValues will automatically Method Explanation sort the classes in accending order. If you want to change the order, then use the classValues and classLabels properties.

The addAllValues method is also useful for situations where data is addAllValues Adds all unique values to the symbology.Provides the ability to set or get the name of a layer the way it would appear in the ArcMap table of contents. ListDataFrames mxd, 'Webmap' [0] Export the web map Get a list of all service layer names in the map arcpy. If a Parameter Explanation Type script exits before saveAndClose is executed, changes will not be saved.

First check to see if a graphic element is grouped by using the isGroup property. The index values are automatically generated based on the Name andSort fields. There are essentially three categories of layers in a map document: