amaptor.Project

class amaptor.Project(path)[source]

An ArcGIS Pro Project or an ArcMap map document - maps in ArcGIS Pro and data frames in ArcMap are Map class attached to this project Access to the underlying object is provided using name ArcGISProProject and ArcMapDocument

active_map
Returns the active map object or data frame as determined by get_active_map()
Returns:
check_layout_name(name)[source]
PRO ONLY. Given the name of a layout, confirms it doesn’t exist and raised amaptor.LayoutExists if it’s found
Parameters:name – the case sensitive name of an existing layout to find
Returns:None. Raises amaptor.LayoutExists if layout with name exists.
check_map_name(name)[source]
Checks to see if the project or map document already has a map or data frame with a given name. Since names must be unique in ArcGIS Pro, this code helps check before adding new maps
Parameters:name – name of map to check for
Returns:None. Raises an error if name is taken
default_geodatabase
Returns the Project’s default geodatabase in Pro, and the current workspace (arcpy.env.workspace) in ArcMap. If arcpy.env.workspace is None, creates a GDB in same folder as map document and returns that value, to ensure that this function always returns a usable workspace. If a GDB is created, this function does NOT set arcpy.env.workspace to that, so as not to interfere with other operations. Do that explicitly if that behavior is desired.
Returns:
find_layer(path, find_all=True)[source]
Finds a layer in all maps by searching for the path. By default finds all, but can find just the first one too
Parameters:
  • path – the full path of the data source for the layer
  • find_all – When True, reutrns a list of amaptor.Map instances that match. When false, returns only the first match
Returns:

list of amaptor.map instances or a single amaptor.map instance.

find_layout(name)[source]
PRO ONLY. Given a layout name, returns the amaptor.Layout object or raises LayoutNotFoundError
Parameters:name – the name of the layout to find.
Returns:amaptor.Layout instance with given name.
find_map(name)[source]
Given a map name, returns the map object or raises MapNotFoundError
Parameters:name – name of map to find.
Returns:amaptor.Map instance
get_active_map(use_pro_backup=True)[source]
Emulates functionality of arcpy.mapping(mxd).activeDataFrame. In ArcMap, it returns the amaptor.Map object that corresponds to that active Data Frame. In Pro, which doesn’t have the concept of active maps, it by default returns the first map in the document. If use_pro_backup is set to False, it will instead raise amaptor.MapNotImplementedError
Parameters:use_pro_backup – When True, it uses the first map in the ArcGIS Pro project, since Pro doesn’t have a way to get the active map.
Returns:amaptor.Map instance
list_maps()[source]
Provided to give a similar interface to ArcGIS Pro - Project.maps is also publically accessible
Returns:
map_names
A convenience function to get a list of map names
Returns:
new_layout(name, template_layout='/home/docs/checkouts/readthedocs.org/user_builds/amaptor/envs/latest/local/lib/python2.7/site-packages/amaptor-0.1.2.4-py2.7.egg/amaptor/templates/pro/blank_layout.pagx', template_name='_pro_blank_layout_template')[source]
PRO ONLY. Adds a new layout to an ArcGIS Pro Project by importing a saved blank layout. Alternatively,
you can provide an importable layout document (.pagx) for ArcGIS Pro, and then provide that layout’s name as template_name so that it can be renamed, and the provided template will be used instead of a blank.
Parameters:
  • name – The name to give the new layout
  • template_layout – The template to use for creating the layout (an ArcGIS Pro .pagx file). If none is provided, uses a blank template
  • template_name – The name of the layout in the template. Only define this value if you also provide a new template layout and the name should match the layout name in the template. This parameter is used to find the inserted template and rename it. Strange things will happen if this value does not match the name of the layout in the template_layout.
Returns:

amaptor.Layout instance. This layout will already have been added to the project, but is returned for convenience.

new_map(name, template_map='/home/docs/checkouts/readthedocs.org/user_builds/amaptor/envs/latest/local/lib/python2.7/site-packages/amaptor-0.1.2.4-py2.7.egg/amaptor/templates/arcmap/pro_import_map_template.mxd', template_df_name='_rename_template_amaptor')[source]
PRO ONLY. Creates a new map in the current project using a hack (importing a blank map document, and renaming data frame) Warning: Only works in Pro due to workaround. There isn’t a way to add a data frame from arcpy.mapping. In the future, this could potentially work in arcmap by transparently working with a separate map document in the background (creating a project, map, and layout for those items and linking them into this project).
Parameters:
  • name – The name to give the imported map
  • template_map – The map document to import. If we’re just going with a blank new map, leave as default. To import some other template as your base, provide a path to a document importable to ArcGIS Pro’ .importDocument function for projects.
  • template_df_name – The current name of the imported map document for renaming. Only needs to be set if template_map is overridden
Returns:

amaptor.Map instance - also added to the map document, but returned for immediate use.

replace_text(text, replacement)[source]
Given a string and a replacement value, finds all instances (in the current map document or project) of that text in text elements and titles, and replaces those instances with the new value. Useful for creating your own variables like {species} or {field_id} in map templates. Careful when using this - in Pro, it will search all Layouts and replace the string. If you are concerned and want single layout behavior, use the same function on the Layout class.
Parameters:
  • text
  • replacement
Returns:

save()[source]
Saves the project or map document in place.
Returns:None
save_a_copy(path)[source]
Saves the project or map document to the provided path.
Parameters:path – the new path to save the copy of the document to.
Returns:None
to_package(output_file, summary, tags, **kwargs)[source]
Though it’s not normally a mapping method, packaging concepts need translation between the two versions, so we’ve included to_package for maps and projects. In ArcGIS Pro, project.to_package will create a Project Package and map.to_package will create a map package. In ArcMap, both will create a map package. Extra **kwargs beyond output path are only passed through to Pro Package command, not to map packages. To pass kwargs through to a map package, use a map object’s to_package method.
Parameters:
  • output_file – the path to output the package to
  • kwargs – dictionary of kwargs to pass through to project packaging in Pro.
Returns:

None