Arcpy.mapping Common Four pieces-mapsurroundelement

Source: Internet
Author: User

Arcpy.mapping Common Four pieces-mapsurroundelement

by Li Yuanxiang

In Arcpy.mapping, in addition to the data entry mapdocument, layer layers, another important role is mapsurroundelement. Mapsurroundelement is directly related to the map of the decoration elements. As long as this big three, ArcGIS's cartographic automation is basically possible.

There are many decorations for the map, such as text (title and other descriptions), legend, scale bar, North arrow, picture, plus graphics, and so on. With the Mapsurroundelement class of arcpy.mapping, the layout of these elements can be precisely arranged.

Next you can look at some of the properties and methods of Mapsurroundelement. Strictly speaking, Mapsurroundelement has no method, all settings are in the attribute, the following is the official help of mapsurroundelement, from which can see its main role.

Basic property settings, such as the position of the finishing element, the long-width rename can be set, and a parentdataframename used to identify its dataframe (this generally does not work, unless you need to do a graph to use multiple dataframe), from which you can see, Its main function lies in the recognition of the decoration elements and the adjustment of size and position. The detail adjustment section mainly falls on the type. This is a bit like the layer,type mentioned in the previous chapter is also read-only, but the specific configurable parts are in different inclusion objects. It relates to Dataframe_element, Graphic_element, Legend_element, Mapsurround_element, picture_element, text_element these categories, All are inherited mapsurroundelement, so, if it is only the size and position of the operation, it is through the Name property to identify, and then through the code to adjust the position and size of the element. Different types also appropriately add some properties that can be set, but in general, there are not many properties to set.

In these categories, there is a very mysterious is dataframe_element, I experienced several versions of the ArcGIS Help, have not been able to find its description, it should be a reserved interface, literally, it is estimated to be able to set the graticule, but not yet open, see Help to know, There are several other categories that can be found, except for the description.

Graphic_element corresponding to the "Drawing" toolbar is drawn out of the graph, relative to the Mapsurroundelement base class, the main is to increase the isGroup (read-only) properties, its use, but the current role is not very small, only the interpretation is not a combination of it, There is no way to ungroup them. method is to increase the copy clone and delete method.

Legend_element corresponds to the operation of the legend, the legend object is the most properties and methods of a subclass, AutoAdd, items, title. Where items is read-only, returns a list of strings that represent the name of the legend item, and cannot be modified. The title is a read-write property, can be directly set up, there is a autoadd, this is a Boolean value, used to determine whether the new layer added to the legend, its actual role is "Legend"-"Properties"-"general" in the " Add a new item to the legend when a new layer is added to the map

The method of the legend is open a lot of more useful functions, the following is a good way

    • Adjustcolumncount (Column_count): Sets the number of columns for the legend
    • Listlegenditemlayers (): Get a list of layers for the legend
    • RemoveItem (Legend_item_layer, {index}): Remove an item from the legend
    • UpdateItem (Legend_item_layer, {Legend_item_style_item}, {preserve_item_sizes}, {use_visible_extent}, {Show_feature _count}, {use_ddp_extent}, {index}): Update legend settings

For these methods of operation of the legend, it is still satisfactory, of course, it is not possible to convert the legend to graphics these operations add in, after all, arcpy positioning is coarse-grained operation, legend to the graphics these are put on the AO up code editing, are more troublesome.

Picture_element is an inserted picture object, which has an additional sourceimage attribute that can be used to read the path (very few people will be naïve to read the path) and to set a new insert picture. In addition, there is no specific way for this subclass to be used.

Text_element is the most commonly used subclass, and all text objects, including static or dynamic text objects, can be set with it. It adds the angle, fontsize, and Text properties, which are basically words too literally. The most common is to make text content and text font modification. The addition of clone and delete is also done on the method.

In all mapsurroundelement, the sharp-eyed point person will find that there is no word for add or create. because the Mapsurroundelement object cannot be created by code, at least there is currently no ArcGIS version that supports code creation . This means that in arcpy, the use of mapsurroundelement is limited to the decoration elements that have already been created. The personal feeling is that Esri's position with arcpy.mapping is to do automated mapping based on a fixed template, rather than creating a map decoration element from the code level.

Next you can see how the code is called. Take a look at the official example and replace all occurrences of 2009 in the layout view with 2010 years.

Import arcpy
Mxd = Arcpy.mapping.MapDocument (r "C:\Project\Project.mxd")
For Elm in arcpy.mapping.ListLayoutElements (Mxd, "text_element"):
    if elm.text = ="":
        Elm.text = "All"
Mxd.save ()
Del Mxd

In general, however, it is rarely used in this way to replace text values. The most common way is to identify the object by its name, and specify it to the specific object. The way to get the finishing element is to use listlayoutelements, which returns an array and is determined by the name of the object that the element is set in ArcMap. For example, the following code

Import arcpy
Mxd = Arcpy.mapping.MapDocument (r "C:\Project\Project.mxd")
For Elm in arcpy.mapping.ListLayoutElements (Mxd, "text_element"):
    if Elm. name = = "Tile_elm":
        Elm.text = " modified title "
Mxd.save ()
Del Mxd

It can be seen that in the Arcpy.mapping.ListLayoutElements method, the object is not directly specified with the name parameter, and it needs to be looked up through an array. In addition, you must name the element object beforehand, for example, set a name called "Tile_name" for the caption text.

Other decoration element settings are the same, the most important principle is that when adding the decoration elements must give an element name, which is a normative approach, regardless of whether or not to use arcpy to adjust later. This can circumvent some of the later changes. The author has helped a certain user to solve the production of thousands thematic map, one of the most important part is to modify the position of the finishing elements at a later stage, are some minor operations, such as fine-tuning position and modified text values, if the first not set the name of the decoration element, then the late face of thousands of mxd, is a disastrous job.

Summarize:

Mapsurroundelement is a very useful finishing element object, which gives very high convenience in cartography automation. Of course, it has a fixed usage pattern and scenario where you need to create a good element object at the beginning and set its element name. Since these objects cannot be created by code, it is unreasonable to use arcpy to do the map template. Mapsurroundelement is just a convenient way to help .

Arcpy.mapping common four pieces-mapsurroundelement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.