0

Using ArcGIS Desktop v10.1 with an Advanced level license we have georeferenced our engineering drawings in PNG format. Next we have created a polygon layer for every single drawing to see the Area of Interest depicted in the drawing. Is there an automated way to bring individual PNG layers by clicking on their respective polygon? I want a simpler way to add the georeferenced PNG into the map without having to use the classic "add layer" tool, where a user has to find the respective layer in their location on the network.

1
  • 2
    This question is nearly identical (the only difference is versioning) to your previous question, which was closed as too broad. You'll need to make this a bit more specific.
    – Paul
    Apr 29, 2014 at 21:30

1 Answer 1

1

You'll need a little bit of python to do this, but it's certainly possible.

The key to doing this is to store the pngs in a directory and file name structure that can be inferred from the attributes in the polygon shapefile. So the polygon could have a year field and a project name field, and your pngs will be stored at "...\2004\projectname.png". If you do this, you can pull the attributes from the polygon, construct the path, and add the layer.

To select the polygon, you could use a few different methods. A python addin would definitely work, though that will be the most complicated if you are unfamiliar with addins. I think I would recommend doing it with a custom script in a new toolbox. You could have one "Feature Layer" parameter, and once a polygon is selected in ArcMap (with the normal selection tool), drag the layer from the table of contents into the tool parameter and run the tool. You could make multiple selections also.

The core of your code would look something like this (assuming the above directory structure):

import arcpy

fl = arcpy.GetParameterAsText(0)

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0] #to use the defaults "Layers" data frame

for row in arcpy.SearchCursor(fl):
    year = row.getValue("YEAR")
    project = row.getValue("PROJECT")

    pngpath = r"...\{0}\{1}.png".format(str(year),project)
    pnglyr = arcpy.mapping.Layer(pngpath)
    arcpy.mapping.AddLayer(df,pnglyr)

OR

If you don't want to deal with the directory structuring, you could simply have the file name in the polygon (assuming they are all unique), and then use os.walk() to find the file, though this may take a little longer:

import os

#modify the search cursor above like so
for row in arcpy.SearchCursor(fl):
    filename = row.getValue("FILENAME")
    for path, dirs, files in os.walk(r"root\folder\above\all\possible\png\locations"):
        for f in files:
            if f == filename:
                 png_path = path + "\\" + f
                 #do the whole layer process
3
  • I was looking to use a python script using hyperlinks.
    – Adrian
    May 2, 2014 at 18:39
  • I thought this might be faster. Any ideea of a code would be appreciated. I have tried a couple using the Add layer script, but is not working for me.
    – Adrian
    May 2, 2014 at 18:40
  • Hi @Adrian, because the question has been closed I'd recommend that you post a new question with your specific issue. I would also check out the ESRI forums, and see if you can find an answer there: forums.arcgis.com
    – mr.adam
    May 5, 2014 at 15:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.