Generate Mapbooks with Pythonscript on AGS

693
4
05-20-2014 03:12 AM
ChristianMüller
New Contributor
I tried to export Mapbooks to PNG with an PYthonscript. The script works fine on Desktop and on Server. But on Server it takes much more time for creating only one of the PNGs. In the sum of over 150 PNGs it makes over a half of a day for executin the script.

On Desktop, the script takes around 7 seconds per PNG, on server it takes around 100 seconds.

I tried it with two different servers, with different datasources (GDB and SDE) and I also tried it with Labeling on/off. It all makes no significant difference.

Could anyone give me a hint how I could get it work faster? Or could anyone could explain why it is so?
Tags (2)
0 Kudos
4 Replies
RaymondHuang
Occasional Contributor
Hi Christian,

Are you able to share your script here so that we can gain more insight to what methods your script is calling?

On top of that, when you say you are running your script on the server, do you mean you are serving it out as a GP service? If so, perhaps we need to look into your server logs to identify what is the bottleneck. You may need to log at FINE or INFO level to see the details of the duration each process is taking.

Raymond
0 Kudos
ChristianMüller
New Contributor
Hi Raymond,

of course I could post the code of the Python script:

#!/arcgisserver/arcgis/server/tools/python
#
# arcpy.GetParameterAsText(0): Kompletter Pfad der MXD
# arcpy.GetParameterAsText(1): Ausgabepfad fuer die Bilder
# arcpy.GetParameterAsText(2): Praefix fuer die Ausgabedatei, Nummerierung kommt aus Kartenserien-Konfiguration, Dateiendung wird angehaengt
# arcpy.GetParameterAsText(3): Debug-Flag

import arcpy

mxd = arcpy.mapping.MapDocument(arcpy.GetParameterAsText(0))
print arcpy.GetParameterAsText(0)
debugOn = arcpy.GetParameterAsText(3)
outPath = arcpy.GetParameterAsText(1)
outPrefix = arcpy.GetParameterAsText(2)

def getOutputName(prefix):
        result = prefix + str(ddp.pageRow.getValue(ddp.pageNameField.name)) + ".png"
        return result

print "Start exporting %s PNGs" % (mxd.dataDrivenPages.pageCount)
maxRange = mxd.dataDrivenPages.pageCount + 1
if (debugOn == "1"):
        for lyr in arcpy.mapping.ListLayers(mxd):
                #get the source from the layer
                if lyr.supports("workspacePath"):
                        source = lyr.workspacePath
                        print "%s -> %s" % (lyr, source)
        maxRange = 15
for pageNum in range(1, maxRange):
        if (debugOn == "1"):
                print "Page %s" % (pageNum)
        mxd.dataDrivenPages.currentPageID = pageNum
        ddp = mxd.dataDrivenPages
        if (debugOn == "1"):
                print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(maxRange))
        outputName = getOutputName(outPrefix)
        print str(outPath) + "/" + str(outputName)
        arcpy.mapping.ExportToPNG(mxd, str(outPath) + "/" + str(outputName), resolution=150)


The first parameter gets the absolute path of the mxd, the second is for the outputpath of the PNGs, the third is a prefix for the PNGs name, to put all PNGs of the three MXDs together in one path. The fourth parameter is just for debugging/testing.


The script is not served as as GP. As I start working on this topic, I got trouble with writing the files, and so we just used the script itself. In fact we (will) call the python script in an shell script. This shell script also produces PDF reports with the PNGs.
0 Kudos
GISDev1
Occasional Contributor III
Where is the data that is being displayed in the MXD's (the data source)?
0 Kudos
ChristianMüller
New Contributor
The datasources are on the same server as the MXD and the script.
The tested GDB was in the same directory as the MXD.
0 Kudos