arcgis.mapping module

The arcgis.mapping module provides components for visualizing GIS data and analysis. This module includes WebMap and WebScene components that enable 2D and 3D mapping and visualization in the GIS. This module also includes mapping layers like MapImageLayer and VectorTileLayer

WebMap

class arcgis.mapping.WebMap(webmapitem)

Bases: collections.OrderedDict

Represents a webmap and provides access to it’s basemaps and operational layers as well as functionality to visualize and interact with them. http://resources.arcgis.com/en/help/arcgis-web-map-json/index.html#/Web_map_format_overview/02qt00000007000000/

update()

WebScene

class arcgis.mapping.WebScene(websceneitem)

Bases: collections.OrderedDict

Represents a web scene and provides access to it’s basemaps and operational layers as well as functionality to visualize and interact with them.

update()

MapImageLayer

class arcgis.mapping.MapImageLayer(url, gis=None)

Bases: arcgis.gis.Layer

MapImageLayer allows you to display and analyze data from sublayers defined in a map service, exporting images instead of features. Map service images are dynamically generated on the server based on a request, which includes an LOD (level of detail), a bounding box, dpi, spatial reference and other options. The exported image is of the entire map extent specified.

MapImageLayer does not display tiled images. To display tiled map service layers, see TileLayer.

estimate_export_tiles_size(exportBy, levels, tilePackage=False, exportExtent='DEFAULTEXTENT', areaOfInterest=None, asynchronous=True)

The estimateExportTilesSize operation is an asynchronous task that allows estimation of the size of the tile package or the cache data set that you download using the Export Tiles operation. This operation can also be used to estimate the tile count in a tile package and determine if it will exceced the maxExportTileCount limit set by the administrator of the service. The result of this operation is Map Service Job. This job response contains reference to Map Service Result resource that returns the total size of the cache to be exported (in bytes) and the number of tiles that will be exported.

Inputs:

tilePackage - Allows estimating the size for either a tile package

or a cache raster data set. Specify the value true for tile packages format and false for Cache Raster data set. The default value is False

Values: True | False
exportExtent - The extent (bounding box) of the tile package or the
cache dataset to be exported. If extent does not include a spatial reference, the extent values are assumed to be in the spatial reference of the map. The default value is full extent of the tiled map service.
Syntax: <xmin>, <ymin>, <xmax>, <ymax>
Example 1: -104,35.6,-94.32,41
exportBy - The criteria that will be used to select the tile
service levels to export. The values can be Level IDs, cache scales or the Resolution (in the case of image services).

Values: LevelID | Resolution | Scale levels - Specify the tiled service levels for which you want to get

the estimates. The values should correspond to Level IDs, cache scales or the Resolution as specified in exportBy parameter. The values can be comma separated values or a range.

Example 1: 1,2,3,4,5,6,7,8,9 Example 2: 1-4,7-9 areaOfInterest - (Optional) The areaOfInterest polygon allows

exporting tiles within the specified polygon areas. This parameter supersedes exportExtent parameter. Also excepts geometry.Polygon.
Example: { “features”: [{“geometry”:{“rings”:[[[-100,35],
[-100,45],[-90,45],[-90,35],[-100,35]]], “spatialReference”:{“wkid”:4326}}}]}
asynchronous - (optional) the estimate function is run asynchronously

requiring the tool status to be checked manually to force it to run synchronously the tool will check the status until the estimation completes. The default is True, which means the status of the job and results need to be checked manually. If the value is set to False, the function will wait until the task completes.

Values: True | False
export_map(bbox, bboxSR=None, size='600, 550', dpi=200, imageSR=None, image_format='png', layerDefFilter=None, layers=None, transparent=False, timeFilter=None, layerTimeOptions=None, dynamicLayers=None, mapScale=None)

The export operation is performed on a map service resource. The result of this operation is a map image resource. This resource provides information about the exported map image such as its URL, its width and height, extent and scale. Inputs:

bbox - (Required) The extent (bounding box) of the exported
image. Unless the bboxSR parameter has been specified, the bbox is assumed to be in the spatial reference of the map. Example: bbox=”-104,35.6,-94.32,41”

size - size of image in pixels dpi - dots per inch imageSR - spatial reference of the output image image_format - Description: The format of the exported image.

The default format is .png. Values: png | png8 | png24 | jpg | pdf | bmp | gif

svg | svgz | emf | ps | png32
layerDefFilter - Description: Allows you to filter the
features of individual layers in the exported map by specifying definition expressions for those layers. Definition expression for a layer that is published with the service will be always honored.
layers - Determines which layers appear on the exported map.
There are four ways to specify which layers are shown:
show: Only the layers specified in this list will
be exported.
hide: All layers except those specified in this
list will be exported.
include: In addition to the layers exported by
default, the layers specified in this list will be exported.
exclude: The layers exported by default excluding
those specified in this list will be exported.
transparent - If true, the image will be exported with the
background color of the map set as its transparent color. The default is false. Only the .png and .gif formats support transparency. Internet Explorer 6 does not display transparency correctly for png24 image formats.
timeFilter - The time instant or time extent of the exported
map image.
layerTimeOptions - The time options per layer. Users can
indicate whether or not the layer should use the time extent specified by the time parameter or not, whether to draw the layer features cumulatively or not and the time offsets for the layer. see: http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Export_Map/02r3000000v7000000/
dynamicLayers - Use dynamicLayers parameter to modify the layer
drawing order, change layer drawing info, and change layer data source version for this request. New layers (dataLayer) can also be added to the dynamicLayers based on the map service registered workspaces.
mapScale - Use this parameter to export a map image at a specific
scale, with the map centered around the center of the specified bounding box (bbox).
Output:
Image of the map.
export_tiles(levels, exportBy='LevelID', tilePackage=False, exportExtent='DEFAULT', optimizeTilesForSize=True, compressionQuality=0, areaOfInterest=None, asynchronous=False)

The exportTiles operation is performed as an asynchronous task and allows client applications to download map tiles from a server for offline use. This operation is performed on a Map Service that allows clients to export cache tiles. The result of this operation is Map Service Job. This job response contains a reference to the Map Service Result resource, which returns a URL to the resulting tile package (.tpk) or a cache raster dataset. exportTiles can be enabled in a service by using ArcGIS for Desktop or the ArcGIS Server Administrator Directory. In ArcGIS for Desktop make an admin or publisher connection to the server, go to service properties, and enable Allow Clients to Export Cache Tiles in the advanced caching page of the Service Editor. You can also specify the maximum tiles clients will be allowed to download. The default maximum allowed tile count is 100,000. To enable this capability using the Administrator Directory, edit the service, and set the properties exportTilesAllowed=true and maxExportTilesCount=100000.

At 10.2.2 and later versions, exportTiles is supported as an operation of the Map Server. The use of the http://Map Service/exportTiles/submitJob operation is deprecated. You can provide arguments to the exportTiles operation as defined in the following parameters table:

Inputs:
exportBy - The criteria that will be used to select the tile
service levels to export. The values can be Level IDs, cache scales. or the resolution (in the case of image services).

Values: LevelID | Resolution | Scale levels - Specifies the tiled service levels to export. The values

should correspond to Level IDs, cache scales. or the resolution as specified in exportBy parameter. The values can be comma separated values or a range. Make sure tiles are present at the levels where you attempt to export tiles.

Example 1: 1,2,3,4,5,6,7,8,9 Example 2: 1-4,7-9 tilePackage - Allows exporting either a tile package or a cache

raster data set. If the value is true, output will be in tile package format, and if the value is false, a cache raster data set is returned. The default value is false

Values: true | false exportExtent - The extent (bounding box) of the tile package or the

cache dataset to be exported. If extent does not include a spatial reference, the extent values are assumed to be in the spatial reference of the map. The default value is full extent of the tiled map service.

Syntax: <xmin>, <ymin>, <xmax>, <ymax> Example 1: -104,35.6,-94.32,41 Example 2: {“xmin” : -109.55, “ymin” : 25.76,

“xmax” : -86.39, “ymax” : 49.94, “spatialReference” : {“wkid” : 4326}}
optimizeTilesForSize - (Optional) Use this parameter to enable
compression of JPEG tiles and reduce the size of the downloaded tile package or the cache raster data set. Compressing tiles slightly compromises the quality of tiles but helps reduce the size of the download. Try sample compressions to determine the optimal compression before using this feature.

Values: true | false compressionQuality - (Optional) When optimizeTilesForSize=true, you

can specify a compression factor. The value must be between 0 and 100. The value cannot be greater than the default compression already set on the original tile. For example, if the default value is 75, the value of compressionQuality must be between 0 and 75. A value greater than 75 in this example will attempt to up sample an already compressed tile and will further degrade the quality of tiles.
areaOfInterest - (Optional) The areaOfInterest polygon allows
exporting tiles within the specified polygon areas. This parameter supersedes the exportExtent parameter. Must be geometry.Polygon object.
Example: { “features”: [{“geometry”:{“rings”:[[[-100,35],
[-100,45],[-90,45],[-90,35],[-100,35]]], “spatialReference”:{“wkid”:4326}}}]}
asynchronous - default True, this value ensures the returns are returned
to the user instead of the user having the check the job status manually.
find(searchText, layers, contains=True, searchFields='', sr='', layerDefs='', returnGeometry=True, maxAllowableOffset='', geometryPrecision='', dynamicLayers='', returnZ=False, returnM=False, gdbVersion='')

performs the map service find operation

classmethod fromitem(item)
generate_kml(save_location, docName, layers, layerOptions='composite')

The generateKml operation is performed on a map service resource. The result of this operation is a KML document wrapped in a KMZ file. The document contains a network link to the KML Service endpoint with properties and parameters you specify. Inputs:

docName - The name of the resulting KML document. This is the
name that appears in the Places panel of Google Earth.
layers - the layers to perform the generateKML operation on.
The layers are specified as a comma-separated list of layer ids.
layerOptions - The layer drawing options. Based on the option

chosen, the layers are drawn as one composite image, as separate images, or as vectors. When the KML capability is enabled, the ArcGIS Server administrator has the option of setting the layer operations allowed. If vectors are not allowed, then the caller will not be able to get vectors. Instead, the caller receives a single composite image. values: composite | separateImage |

nonComposite
identify(geometry, mapExtent, imageDisplay, tolerance, geometryType='esriGeometryPoint', sr=None, layerDefs=None, time_value=None, layerTimeOptions=None, layers='top', returnGeometry=True, maxAllowableOffset=None, geometryPrecision=None, dynamicLayers=None, returnZ=False, returnM=False, gdbVersion=None)

The identify operation is performed on a map service resource to discover features at a geographic location. The result of this operation is an identify results resource. Each identified result includes its name, layer ID, layer name, geometry and geometry type, and other attributes of that result as name-value pairs.

Inputs: geometry - The geometry to identify on. The type of the geometry is

specified by the geometryType parameter. The structure of the geometries is same as the structure of the JSON geometry objects returned by the ArcGIS REST API. In addition to the JSON structures, for points and envelopes, you can specify the geometries with a simpler comma-separated syntax. Syntax: JSON structures: <geometryType>&geometry={ geometry} Point simple syntax: esriGeometryPoint&geometry=<x>,<y> Envelope simple syntax: esriGeometryEnvelope&geometry=<xmin>,<ymin>,<xmax>,<ymax>
geometryType - The type of geometry specified by the geometry parameter.
The geometry type could be a point, line, polygon, or an envelope. Values: esriGeometryPoint | esriGeometryMultipoint | esriGeometryPolyline | esriGeometryPolygon | esriGeometryEnvelope
sr - The well-known ID of the spatial reference of the input and
output geometries as well as the mapExtent. If sr is not specified, the geometry and the mapExtent are assumed to be in the spatial reference of the map, and the output geometries are also in the spatial reference of the map.
layerDefs - Allows you to filter the features of individual layers in
the exported map by specifying definition expressions for those layers. Definition expression for a layer that is published with the service will be always honored.

time_value - The time instant or the time extent of the features to be identified.

layerTimeOptions - The time options per layer. Users can indicate
whether or not the layer should use the time extent specified by the time parameter or not, whether to draw the layer features cumulatively or not and the time offsets for the layer.
layers - The layers to perform the identify operation on. There are
three ways to specify which layers to identify on: top: Only the top-most layer at the specified location. visible: All visible layers at the specified location. all: All layers at the specified location.
tolerance - The distance in screen pixels from the specified geometry
within which the identify should be performed. The value for the tolerance is an integer.
mapExtent - The extent or bounding box of the map currently being viewed.
Unless the sr parameter has been specified, the mapExtent is assumed to be in the spatial reference of the map. Syntax: <xmin>, <ymin>, <xmax>, <ymax> The mapExtent and the imageDisplay parameters are used by the server to determine the layers visible in the current extent. They are also used to calculate the distance on the map to search based on the tolerance in screen pixels.
imageDisplay - The screen image display parameters (width, height, and DPI)
of the map being currently viewed. The mapExtent and the imageDisplay parameters are used by the server to determine the layers visible in the current extent. They are also used to calculate the distance on the map to search based on the tolerance in screen pixels. Syntax: <width>, <height>, <dpi>
returnGeometry - If true, the resultset will include the geometries
associated with each result. The default is true.
maxAllowableOffset - This option can be used to specify the maximum allowable
offset to be used for generalizing geometries returned by the identify operation. The maxAllowableOffset is in the units of the sr. If sr is not specified, maxAllowableOffset is assumed to be in the unit of the spatial reference of the map.
geometryPrecision - This option can be used to specify the number of decimal places
in the response geometries returned by the identify operation. This applies to X and Y values only (not m or z-values).
dynamicLayers - Use dynamicLayers property to reorder layers and change the layer
data source. dynamicLayers can also be used to add new layer that was not defined in the map used to create the map service. The new layer should have its source pointing to one of the registered workspaces that was defined at the time the map service was created. The order of dynamicLayers array defines the layer drawing order. The first element of the dynamicLayers is stacked on top of all other layers. When defining a dynamic layer, source is required.
returnZ - If true, Z values will be included in the results if the features have
Z values. Otherwise, Z values are not returned. The default is false. This parameter only applies if returnGeometry=true.
returnM - If true, M values will be included in the results if the features have
M values. Otherwise, M values are not returned. The default is false. This parameter only applies if returnGeometry=true.

gdbVersion - Switch map layers to point to an alternate geodatabase version.

item_info

returns the service’s item’s infomation

kml
manager
metadata

returns the service’s XML metadata file

thumbnail(out_path=None)

MapImageLayerManager

class arcgis.mapping.MapImageLayerManager(url, gis=None, map_img_lyr=None)

Bases: arcgis.gis._GISResource

allows administration (if access permits) of ArcGIS Online hosted map image layers. A map image layer offers access to map and layer content.

cancel_job(job_id)

The cancel job operation supports cancelling a job while update tiles is running from a hosted feature service. The result of this operation is a response indicating success or failure with error code and description.

Inputs:
job_id - job id to cancel
delete_tiles(levels, extent=None)

Deletes tiles for the current cache

Argument Description
extent optional dictionary, If specified, the tiles within this extent will be deleted or will be deleted based on the service’s full extent. Example: 6224324.092137296,487347.5253569535, 11473407.698535524,4239488.369818687 the minx, miny, maxx, maxy values or, {“xmin”:6224324.092137296,”ymin”:487347.5253569535, “xmax”:11473407.698535524,”ymax”:4239488.369818687, “spatialReference”:{“wkid”:102100}} the JSON representation of the Extent object.
levels required string, The level to delete. Example, 0-5,10,11-20 or 1,2,3 or 0-5
Returns:dictionary
edit_tile_service(service_definition=None, min_scale=None, max_scale=None, source_item_id=None, export_tiles_allowed=False, max_export_tile_count=100000)

This operation updates a Tile Service’s properties

Inputs:

service_definition - updates a service definition min_scale - sets the services minimum scale for caching max_scale - sets the service’s maximum scale for caching source_item_id - The Source Item ID is the GeoWarehouse Item ID of the map service export_tiles_allowed - sets the value to let users export tiles max_export_tile_count - sets the maximum amount of tiles to be exported

from a single call.
job_statistics(job_id)

Returns the job statistics for the given jobId

refresh(service_definition=True)

The refresh operation refreshes a service, which clears the web server cache for the service.

rerun_job

The rerun job operation supports re-running a canceled job from a hosted map service. The result of this operation is a response indicating success or failure with error code and description.

Argument Description
code required string, parameter used to re-run a given jobs with a specific error code: ALL | ERROR | CANCELED
job_id required string, job to reprocess
Returns:boolean or dictionary
update_tiles(levels=None, extent=None)

The starts tile generation for ArcGIS Online. The levels of detail and the extent are provided to determine the area where tiles need to be rebuilt.

..Note: This operation is for ArcGIS Online only.

Argument Description
levels Optional string, The level of details to update example: “1,2,10,20”
extent Optional string, the area to update as Xmin, YMin, XMax, YMax example: “-100,-50,200,500”
Returns:Dictionary. If the product is not ArcGIS Online tile service, the result will be None.

VectorTileLayer

class arcgis.mapping.VectorTileLayer(url, gis=None)

Bases: arcgis.gis.Layer

classmethod fromitem(item)
info

This returns relative paths to a list of resource files

styles
tile_fonts(fontstack, stack_range)

This resource returns glyphs in PBF format. The template url for this fonts resource is represented in Vector Tile Style resource.

tile_sprite(out_format='sprite.json')

This resource returns sprite image and metadata

vector_tile(level, row, column)

This resource represents a single vector tile for the map. The bytes for the tile at the specified level, row and column are returned in PBF format. If a tile is not found, an error is returned.

export_map

mapping.export_map(web_map_as_json: str = None, format: str = 'PDF', layout_template: str = 'MAP_ONLY', gis=None)

This function takes the state of the web map(for example, included services, layer visibility settings, client-side graphics, and so forth) and returns either (a) a page layout or (b) a map without page surrounds of the specified area of interest in raster or vector format. The input for this function is a piece of text in JavaScript object notation (JSON) format describing the layers, graphics, and other settings in the web map. The JSON must be structured according to the WebMap specification in the ArcGIS HelpThis tool is shipped with ArcGIS Server to support web services for printing, including the preconfigured service named PrintingTools. Parameters:

web_map_as_json: Web Map as JSON (str). Required parameter. A JSON representation of the state of the map to be exported as it appears in the web application. See the WebMap specification in the ArcGIS Help to understand how this text should be formatted. The ArcGIS web APIs (for JavaScript, Flex, Silverlight, etc.) allow developers to easily get this JSON string from the map.

format: Format (str). Optional parameter. The format in which the map image for printing will be delivered. The following strings are accepted.For example:PNG8 (default if the parameter is left blank)PDFPNG32JPGGIFEPSSVGSVGZ
Choice list:[‘PDF’, ‘PNG32’, ‘PNG8’, ‘JPG’, ‘GIF’, ‘EPS’, ‘SVG’, ‘SVGZ’]
layout_template: Layout Template (str). Optional parameter. Either a name of a template from the list or the keyword MAP_ONLY. When MAP_ONLY is chosen or an empty string is passed in, the output map does not contain any page layout surroundings (for example title, legends, scale bar, and so forth)
Choice list:[‘A3 Landscape’, ‘A3 Portrait’, ‘A4 Landscape’, ‘A4 Portrait’, ‘Letter ANSI A Landscape’, ‘Letter ANSI A Portrait’, ‘Tabloid ANSI B Landscape’, ‘Tabloid ANSI B Portrait’, ‘MAP_ONLY’]

gis: Optional, the GIS on which this tool runs. If not specified, the active GIS is used.

Returns:
output_file - Output File as a DataFile

See https://utility.arcgisonline.com/arcgis/rest/directories/arcgisoutput/Utilities/PrintingTools_GPServer/Utilities_PrintingTools/ExportWebMapTask.htm for additional help.

get_layout_templates

mapping.get_layout_templates(gis=None) → str

This function returns the content of the GIS’s layout templates formatted as dict.

Parameters:

gis: Optional, the GIS on which this tool runs. If not specified, the active GIS is used.

Returns:
output_json - layout templates as Python dict

See https://utility.arcgisonline.com/arcgis/rest/directories/arcgisoutput/Utilities/PrintingTools_GPServer/Utilities_PrintingTools/GetLayoutTemplatesInfo.htm for additional help.