ArcGIS 10.0 - Arcpy Map Export: how to get the actual maextent in the exported image?

1397
3
02-24-2014 10:54 AM
SimonLeo
New Contributor III
Environment:
ArcGIS 10.0

As v10 doesn't have out-of-box printing service, we are developing a simple one to export map layers to image (JPEG). The service is called in web browser.

Input params:
XMin, YMin, XMax, YMax, Scale, requiredImageWidth, requiredImageHeight

Output params:
image url
exported image extent(XMin, YMin, XMax, YMax)

sample code:
#configuration params
config.mxdTemplate = "test.mxd"


# Get the map document template
mapDoc = arcpy.mapping.MapDocument(config.mxdTemplate)

# Get data frame
dataFrames = arcpy.mapping.ListDataFrames(mapDoc)
dataFrame = dataFrames[0]

# Set map extent
newExt = dataFrame.extent
newExt.XMin = xMin
newExt.XMax = xMax
newExt.YMin = yMin
newExt.YMax = yMax
dataFrame.extent = newExt
dataFrame.scale = scale

#export
arcpy.mapping.ExportToJPEG(mapDoc, outputJpgPath,
                        data_frame=dataFrame,
                        df_export_width=inputImageWidth,
                        df_export_height=inputImageHeight)


so far the service has successfully exported map to JPEG file;

but what is the way to get the actual extent represented by the exported image?

The actual extent is different from the input extent. it is affected by dataFrame's extent and image size.

any ideas? thanks!
Tags (2)
0 Kudos
3 Replies
JeffBarrette
Esri Regular Contributor
Exporting a dataframe to get the exact extent is tricky for a couple of reasons.  First, the aspect ratio of the provided coordinates may not match the shape of the frame.  Second, the output depends on the DPI settings of the computer.

The easiest way to get what you want is to build a layout with a dataframe that is the same size of the layout.  Export the layout instead of just the data frame.  Exporting the layout allows you to use the layout page units rather than try to calculate height and width in pixel length.

Jeff
0 Kudos
SimonLeo
New Contributor III
Jeff, thanks for your reply. I must say that I don't quite understand the way you proposed. I think I know the reasons why it's tricky. could you elaborate a little more?

the image height and width are given from web UI. so these two values are known.

a little more about the whole situation:
this is a printing service that deals with a lot of features. The feature data are from a separate service hosted by an application server(diff from ArcGIS Server). One way to print them is to send the data from web UI to ArcGIS Server, but those are a lot of data that needs a long while for transmission. Another way is to let ArcGIS Server print basemap and map service layers, then send the exported image to application server and draw all features over exported basemap image. But to draw, we need to know the exported image's map extent.

thanks again.

Exporting a dataframe to get the exact extent is tricky for a couple of reasons.  First, the aspect ratio of the provided coordinates may not match the shape of the frame.  Second, the output depends on the DPI settings of the computer.

The easiest way to get what you want is to build a layout with a dataframe that is the same size of the layout.  Export the layout instead of just the data frame.  Exporting the layout allows you to use the layout page units rather than try to calculate height and width in pixel length.

Jeff
0 Kudos
JeffBarrette
Esri Regular Contributor
All I'm suggesting is that you try exporting your MXD Layout rather than a dataframe.  Create an MXD with a layout that has a a single dataframe that is the same size/orientation as the layout.

Jeff
0 Kudos