[924] ArcGIS Pro Mapping Module - arcpy.mp

发布时间 2023-10-24 10:08:57作者: McDelfino

ref: Introduction to arcpy.mp

ref: Getting started with arcpy.mp tutorial

ref: Guidelines for arcpy.mp

ref: Alphabetical list of arcpy.mp functions

ref: Alphabetical list of arcpy.mp classes

ref: SQL reference for query expressions used in ArcGIS


The following diagram illustrates the utility of list functions for navigating and referencing the objects within a project or a layer file. The diagram is only an example and does not display a complete set of objects. 

Classes

  • ArcGISProject: The ArcGISProject object provides access to ArcGIS Pro project methods and properties. A reference to this object is essential for most map automation workflows.

    • listMaps ({wildcard}): Returns a Python list of Map objects in an ArcGIS project (.aprx).

    • listLayouts ({wildcard}): Returns a Python list of Layout objects in an ArcGIS project (.aprx).

  • Map: The Map object is the primary object for referencing and managing layers and tables within an ArcGIS Pro project.

    • listLayers ({wildcard}): Returns a Python list of Layer objects that exist within a map.

    • listTables ({wildcard}): Returns a Python list of Table objects that exist within a map.

  • Layer: Provides access to basic layer properties and methods.

    • supports (layer_property): Used to determine if a particular layer type supports a property on the layer object. Not all layers support the same set of properties; the supports property can be used to test if a layer supports that property before attempting to set it. i.e., lyr.supports("BRIGHTNESS") and lyr.supports("NAME").

    • listLayers ({wildcard}): Returns a Python list of Layer objects that exist within a map.

    • listTables ({wildcard}): Returns a Python list of Table objects that exist within a map.

    • getSelectionSet (): Returns a layer's selection as a Python set of object IDs.
  • Table: Provides access to basic table properties and methods.

    • listLayers ({wildcard}): Returns a Python list of Layer objects that exist within a map.

    • listTables ({wildcard}): Returns a Python list of Table objects that exist within a map.

  • Layout: The Layout object references a single-page layout in an ArcGIS Pro project (.aprx). It provides access to common properties like page size and a number of different export methods.

    • listElements ({element_type}, {wildcard}): Returns a Python list of page layout elements that exist on a Layout object. The listElements method provides access to all the elements on the page layout: GraphicElementLegendElementMapFrameElementMapSurroundElementPictureElement, and TextElement.

      lyt.listElements("mapframe_element")
    • exportToPDF (out_pdf, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {layers_attributes}, {georef_info}, {jpeg_compression_quality}, {clip_to_elements}, {output_as_image}, {embed_color_profile}, {pdf_accessibility}): Exports the Layout to Portable Document Format (PDF).
  • MapFrame: The MapFrame object is a page layout element that is used to display the contents of a map on a layout. It also provides access to page size and positioning, basic navigation methods, and export options.

    • map(Read and Write): The Map being displayed in the map frame.

    • camera(Read and Write): The Camera controls the location and viewing positions of the data being displayed within a map frame.
    • getLayerExtent (layer, {selection_only}, {symbolized_extent}): Returns a layer's extent for all features or only the selected features in a layer.

    • panToExtent (extent): Pans and centers the MapFrame using a new Extent object without changing the map frame's scale. 

    • zoomToAllLayers ({selection_only}, {symbolized_extent}): Modifies the MapFrame view to match the extent of all layers or selected layers in a map.

  • GraphicElement: The GraphicElement object provides access to properties that enables its repositioning on the page layout, as well as methods that allow for duplicating and deleting existing graphic elements.

  • LegendElement: The LegendElement object provides access to properties that enable its positioning and resizing on the page layout as well as modifying its title. It also provides access to individual LegendItems.

  • MapsurroundElement: Provides access to properties that enables its repositioning on the page layout as well as identifying its associated map frame.

  • PictureElement: Provides access to picture properties that enable the repositioning of a picture on the page layout as well as getting and setting its data source.

  • TextElement: The TextElement object provides access to properties that enable its repositioning on the page layout as well as modifying the text string and font size.

  • Camera: The Camera object provides access to 2D and 3D viewer properties that control the display in a MapFrame or MapView.
    • getExtent (): Returns an Extent object for a 2D map frame.
    • setExtent (extent): Sets the Extent for a map frame in a layout.

  • Extent: An extent is a rectangle specified by providing the coordinate of the lower left corner and the coordinate of the upper right corner in map units.

    • XMax(Read Only): The extent XMax value. None if no m-value.

    • XMin(Read Only): The extent XMin value. None if no m-value.

    • YMax(Read Only): The extent YMax value. None if no m-value.

    • YMin(Read Only): The extent YMin value. None if no m-value.

    • contains (second_geometry, {relation}): Indicates if the base geometry contains the comparison geometry. contains is the opposite of within.

    • equals (second_geometry): Indicates if the base and comparison geometries are of the same shape type and define the same set of points in the plane. This is a 2D comparison only; M and Z values are ignored.

  • Geometry: Geometry objects define a spatial location and an associated geometric shape.

    • extent (Read and Write): The extent of the geometry.
    • boundary (): Constructs the boundary of the geometry. (polygon to polyline)

    • buffer (distance): Constructs a polygon at a specified distance from the geometry.

    • clip (envelope): Constructs the intersection of the geometry and the specified extent.

    • cut (cutter): Splits this geometry into a part left of the cutting polyline, and a part right of it.

    • intersect (other, dimension): Constructs a geometry that is the geometric intersection of the two input geometries. Different dimension values can be used to create different shape types. The intersection of two geometries of the same shape type is a geometry containing only the regions of overlap between the original geometries.

    • union (other): Constructs the geometry that is the set-theoretic union of the input geometries. The two geometries being unioned must be the same shape type.

  • SearchCursor: Establishes read-only access to the records of a feature class or table. It returns an iterator of tuples. The order of values in the tuple matches the order of fields specified by the field_names argument.
    Geometry object properties can be accessed by specifying the token SHAPE@ in the list of fields.
    Search cursors can be iterated using a for loop.
    Accessing full geometry with SHAPE@ is an expensive operation. If only simple geometry information is required, such as the x,y coordinates of a point, use tokens such as SHAPE@XYSHAPE@Z, and SHAPE@M for faster, more efficient access.

    SearchCursor (in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause}, {datum_transformation})
    •  fields (Read Only): A tuple of field names used by the cursor. The tuple will include all fields and tokens specified by the field_names argument.

  • Code sample:

    import arcpy
    
    fc = 'c:/data/base.gdb/well'
    fields = ['WELL_ID', 'WELL_TYPE', 'SHAPE@XY']
    
    # For each row, print the WELL_ID and WELL_TYPE fields, and
    # the feature's x,y coordinates
    with arcpy.da.SearchCursor(fc, fields) as cursor:
        for row in cursor:
            print(u'{0}, {1}, {2}'.format(row[0], row[1], row[2]))
  • SpatialReference: Each part of the spatial reference has a number of properties (especially the coordinate system) that defines what map projection options are used to define horizontal coordinates.
    SpatialReference object can also be accessed from existing datasets using the Describe spatialReference property.
    SpatialReference ({item}, {vcs}, text)