TransWikia.com

Adding image to existing data frame using ArcPy

Geographic Information Systems Asked by Megan on September 17, 2020

This is the first time I am using Python on my own, and I have searched for this answer for a few hours with no luck. I am wanting to take a .JPG image and put it in a data frame. The image has to be in color, and needs to change with data driven pages.

3 Answers

Sounds like you want a 'dynamic image' like 'dynamic attributes' - this might be a starting point:

From ArcGIS Pro's help: Dynamic Image

Insert dynamic pictures with Map Series

If you are using Map Series, you can make your picture element dynamic and have it update for each page. To do this, double-click the picture to open the Element pane. There are two options from which you can choose: Simple path and Dynamic (Map Series).

Dynamic (Map Series) allows you to reference images that you have as attachments on index layer features. You can also reference a raster field as well. In cases where you have more than one attachment for a feature, you should use the Name filter. For example, you can filer on the file type (.png) or on a portion of text in the name.

Answered by Barrett on September 17, 2020

I would suggest for you to template out your map document with a pseudo image and just replace the source using python instead of adding and removing the layer. I take that your image is an element, not actually apart of a data frame. If so, you may swap out the reference path to that image by using the

sourceImage

property, see code example below:

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:ProjectProject.mxd")
for elm in arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT"):
    if elm.name == "Photo":
        elm.sourceImage = r"C:ProjectDataNewPhoto.bmp"
mxd.save()
del mxd

Otherwise, you could technically store this image in a seperate data frame and resource it by the layer replaceDataSource method.

Answered by artwork21 on September 17, 2020

I don't think you need Python for this, unless there are other complicating factors not mentioned in the question.

Assuming that your JPG files are georeferenced (i.e. have *.jgw world files), and that you have a polygon feature class with one rectangular polygon that corresponds to each JPG file, then you should be able to use that polygon feature class as an index in Data Driven Pages.

Make sure the map you are enabling DDP on has all the JPG files in its Table of Contents and turned on.

Answered by PolyGeo on September 17, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP