3

I have added an attribute table to my map but when it is exported to jpeg using arcpy the table is missing. The problem only seems to apply to attribute tables created in ArcGIS - if I copy and paste a table from Excel into the map document, there is no problem and the table is included in the exported image.

I have tried turning on the visibility of layout elements but this did not work:

df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]

for elm in arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT"):
        elm.visible = True

arcpy.mapping.ExportToJPEG(mxd, "mypath", data_frame='PAGE_LAYOUT', resolution = 240, jpeg_quality=100)

Any other suggestions on how to get this to work?

  • Are your graphic elements on the page before you export it? Perhaps print their X and Y positions before you make them visible. – PolyGeo Jul 31 '17 at 12:00
  • @PolyGeo♦ well I definitely added the table on the desktop interface and if I export manually (File>Export Map) then the table is there. It seems that arcpy cannot see it for some reason. When I iterate through using elm in ListLayoutElements it seems there is nothing to iterate over so neither the name nor the position is printed..... – alkey Jul 31 '17 at 12:18
2

I think you are hitting the limitations of arcpy. Export of map document's layout with an attribute table to an image will not work when you call outside of ArcMap session (that has the map document open).

Run this code in Python window in ArcMap while having your map document open:

mxd = arcpy.mapping.MapDocument('current')
arcpy.mapping.ExportToJPEG(mxd, r"C:\GIS\out.jpeg", data_frame='PAGE_LAYOUT', resolution = 240, jpeg_quality=100)

The attribute table will be visible in the output .jpeg file.

Run this code in a Python IDE or in a Python console (that is, outside of ArcMap session):

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\GIS\Temp\mydoc.mxd")
arcpy.mapping.ExportToJPEG(mxd, r"C:\GIS\out.jpeg", data_frame='PAGE_LAYOUT', resolution = 240, jpeg_quality=100)

No attribute table is exported.

Workarounds:

  1. Add your attribute table in some other format (Excel sheet, database table, ArcGIS report).

  2. Use external Python packages such as PyPdf or reportlab to construct .pdf files combining the map image (exported with arcpy) and the table data (read from the data source using arcpy.da.SearchCursor).

  • Thanks @AlexTereshenkov, this did the job, I was running the code through IDLE; however now that I run the code with the Session open the exported table does not look the same as it does on the ArcGis main interface. It seems there is another empty row and column on the table, any ideas why this is happening? Currently using the excel workaround but it would be good to know if it's possible to replicate the native table in arcPy. – alkey Jul 31 '17 at 13:30
  • 1
    @allankey, this would be super hard to troubleshoot remotely, sorry. I don't get any empty rows or columns when exported. I recommend starting a new question and explaining in details what are your steps and how does your input/output look like – Alex Tereshenkov Jul 31 '17 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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