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?
Answer
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:
Add your attribute table in some other format (Excel sheet, database table, ArcGIS report).
Use external Python packages such as
PyPdf
orreportlab
to construct .pdf files combining the map image (exported with arcpy) and the table data (read from the data source usingarcpy.da.SearchCursor
).
No comments:
Post a Comment