Select to view content in your preferred language

MAP Book Functionality

2155
3
09-15-2016 04:22 AM
raviprakash
Emerging Contributor

Hi everyone,

 I'm using data driven pages for creating map book in desktop. Everything is working fine, but need to publish the tool as GP service.

1.Is it possible?

2.Is it possible to set a Multiple layers in DDP for en. Upto now we can set only a feature layer.

3.  Now,I need to perform a query based on the data with unique ID's like sample example Select and print data. For particular data , Can we perform the data driven page in server side ?

I am using Data Driven Pages and ArcGIS 10.2.

0 Kudos
3 Replies
FreddieGibson
Honored Contributor

As for your first question the answer is yes and I'm not sure if I understand your second question. Are you asking if you can use multiple layers for the driver in data driven pages? If so, the answer would be no. 

Essentially you'll need to combine the concepts behind the following two samples.

Tutorial: Basic web map printing and exporting using arcpy.mapping—Documentation | ArcGIS for Server 

OR 

Tutorial: Advanced web map printing/exporting using arcpy.mapping—Documentation | ArcGIS for Server 

AND

Creating a map book with facing pages—Help | ArcGIS for Desktop 

The actual workflow will vary depending on what you're needing to accomplish. One option is to have map documents on the server with data driven pages already setup. Then you'll have to determine how you want your users to interact with these pages to drive them and generate the needed pdf(s).

raviprakash
Emerging Contributor

Hi Freddie GibsonThanks for valuable Suggestions.

need to combine the two tools Select attributes and Data driven pages. User dont want to see in any viewer. Needs only a pdf file report.(your link are not helpful for my problem).

 

I try to modify question for your understanding.

1.User will pass only unquie id's in application end not in a GIS viewer. So, I need to user only GP tool.

2.User need output as a map book pdf for the Layers(more than 20 and different type of geomtery (line,point,polygon)) . User dont want to see in any viewer need of only a pdf file.(your link are not helpful for my problem) 

Workflow will be query the layer by an attribute and print the layer in a pdf of a particular scale level divided into page(map book).

Upto now,I worked with Select and print tool to create PDF file for user. Now, they want pdf look like as a map book. Upto my knowledge map book tool is work with Data driven page. I'm trying to set the ouput of Select and print tool to Map book. For that,im facsing problem  in creating a Grid Index layer. In index layer, We need to set

  1. Scale
  2. Polygon Width and Height.
  3. Number of rows and columns.They ouput of Select layer by attribute varies with the ID's . So, how can i set the origin co-oridnates or scale level.

Thanks

0 Kudos
FreddieGibson
Honored Contributor

Hi ravi prakash‌,

Let me explain in a little more detail how the links I sent you will relate to what you're needing to do. Let me know if this is closer to the answer you're wanting. I apologize in advance for the length of this email.

As a result of not needing a GUI in both scenarios we could leverage a custom geoprocessing tool with two parameters. The first parameter could be a GPLong Input that supports either single or multiple values. It would allow the users to input the unique id(s). The second parameter would be an output or derived GPFile. This would return the pdfs to the users. 

Off the top of my head I could come up with two scenarios to solve this problem, in which I would use the links I provided you earlier to help me get started. 

Option A

In this option I'd start by looking at Tutorial: Basic web map printing and exporting using arcpy.mapping—Documentation | ArcGIS for Server. I'd want to pay particular attention to how they're manipulating the map document behind the scenes. Even though you don't need a UI, you're still going to need a map document to host the data so that you can create your pdfs (i.e. MapBooks).

I'd start my tool by parsing out the unique ids supplied by the user. Without using data driven pages I could use these IDs to select the data in the map, zoom to the selected item and then call arcpy.mapping.ExportToPdf to export the current view to a pdf, which I could then give to the user. If you look at Tutorial: Basic web map printing and exporting using arcpy.mapping—Documentation | ArcGIS for Server  you'll see that the bulk of the workflow is already on the page. I've quickly tweaked the sample on the page to highlight how your logic would start. Note that this is just a rough draft of the needed workflow.

import arcpy
import os
import uuid

# Fetch the Unique ID...Assuming we only have one
uid = arcpy.GetParameterAsText(0)

# The template location in the server data store
templateMxd = r"\\MyComputer\MyDataStore\BasicTutorial\v103\WorldTopo_103Templatev2_288k_to_1k.mxd"
   
# Convert the WebMap to a map document
mxd = arcpy.mapping.MapDocument(templateMxd)

# Reference the data frame that contains the map
df = arcpy.mapping.ListDataFrames(mxd)[0]

# Select the feature with the specified Unique ID
arcpy.mapping.SelectLayerByAttribute(<LAYER>, "NEW_SELECTION", "{} = {}".format(<UNIQUE_ID_FIELD>, uid))

# Zoom to the select feature 
df.zoomToSelectedFeatures()

# Manipulate data frame properties as needed
# df.scale = ....
# df.extent = ...
# df.rotation = ...
        
# Use the uuid module to generate a GUID as part of the output name
# This will ensure a unique output name
output = 'WebMap_{}.pdf'.format(str(uuid.uuid1()))
Output_File = os.path.join(arcpy.env.scratchFolder, output)

# Export the WebMap
arcpy.mapping.ExportToPDF(mxd, Output_File) 

# Set the output parameter to be the output file of the server job
arcpy.SetParameterAsText(1, Output_File)

# Clean up - delete the map document reference
filePath = mxd.filePath
del mxd, result
os.remove(filePath)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

To see how to manipulate the data properties you can take a look at DataFrame—Help | ArcGIS for Desktop. You'll also note that I'm only creating a single page in the above example. If you wanted to leverage multiple pages you'd also have to determine how you want to handle appending the pages into a single pdf or how to return multiple pdfs to the user. The example shown at Creating a map book with facing pages—Help | ArcGIS for Desktop will quickly show you how to append multiple pages into a single one if needed. Below is an example from the page. You'll want to keep an eye on finalPdf.

import arcpy, os

# Create an output directory variable
#
outDir = r"C:\temp\MBExample\final_output"  

# Create a new, empty pdf document in the specified output directory
#
finalpdf_filename = outDir + r"\FinalMB.pdf"
if os.path.exists(finalpdf_filename):
  os.remove(finalpdf_filename)
finalPdf = arcpy.mapping.PDFDocumentCreate(finalpdf_filename)

# Add the title page to the pdf
#
finalPdf.appendPages(r"C:\temp\MBExample\ancillary_pages\TitlePage.pdf")

# Add the index map to the pdf
#
finalPdf.appendPages(r"C:\temp\MBExample\maps\IndexMap.pdf")

# Create Facing Pages for the map book
# Create pages for left-hand side of the book
#
mxdPathLeft = r"C:\temp\MBExample\maps\Arenac County MB Left.mxd"
tempMapLeft = arcpy.mapping.MapDocument(mxdPathLeft)
tempDDPLeft = tempMapLeft.dataDrivenPages

# Loop creates individual pdf's for odd numbered pages
#
for pgNumLeft in range(1, tempDDPLeft.pageCount + 1, 2):
  temp_filename = r"C:\temp\MBExample\temp_pdfs\MB_" + \
                            str(pgNumLeft) + ".pdf"
  if os.path.exists(temp_filename):
    os.remove(temp_filename)
  tempDDPLeft.exportToPDF(temp_filename, "RANGE", pgNumLeft)

# Create pages for right-hand side of the book
#
mxdPathRight = r"C:\temp\MBExample\maps\Arenac County MB Right.mxd"
tempMapRight = arcpy.mapping.MapDocument(mxdPathRight)
tempDDPRight = tempMapRight.dataDrivenPages

# Loop creates individual pdf's for even numbered pages
#
for pgNumRight in range(2, tempDDPRight.pageCount + 1, 2):
  temp_filename = r"C:\temp\MBExample\temp_pdfs\MB_" + \
                             str(pgNumRight) + ".pdf"
  if os.path.exists(temp_filename):
    os.remove(temp_filename)
  tempDDPRight.exportToPDF(temp_filename, "RANGE", pgNumRight)

# Append right and left-hand pages together in proper order
#
for pgNum in range(1, tempDDPLeft.pageCount + 1):
  print "Page", pgNum, "of", tempDDPLeft.pageCount
  tempPDF = r"C:\temp\MBExample\temp_pdfs\MB_" + str(pgNum) + ".pdf"
  finalPdf.appendPages(tempPDF)

# Update the properties of the final pdf
#
finalPdf.updateDocProperties(pdf_open_view="USE_THUMBS",
                             pdf_layout="SINGLE_PAGE")

# Save your result
#
finalPdf.saveAndClose()

# Delete variables
#
del finalPdf, mxdPathLeft, mxdPathRight, tempDDPLeft, tempDDPRight, 
tempMapLeft, tempMapRight, tempPDF‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Option B

This option would be very similar to the first option, but instead of manipulating each page manually you could leverage data driven pages to help with the look of the pages. Instead of selecting the features and zooming to them manually, you could use the user's unique ids to locate the pageName or pageNumber for the data driven pages. Once you have this information you could write out a single or multiple pages with a single call to the DataDrivenPages.exportToPdf function. 

DataDrivenPages—Help | ArcGIS for Desktop 

For example, let's say the user gave me the IDs 1, 2, and 3. With data driven pages I could just call exportToPdf(<PDF_LOCATION>, "RANGE", "1-3") and it would put all three pages in a single pdf. To do this with the first option would take several lines of code. DataDrivenPages would also allow me to easy establish the Extent with the properties of the DataDrivenPages in the Map Document. I could tell it that I always want scale to be a certain number or a number in the field, or I could use a grid to sure all of the extents are the same, or I could even have it adjust the extent by a percentage. 

In it's simplest form, let's say that you named your data driven pages using the unique ids. If this were the case I could create the mapbooks with code as simple as the following.

import arcpy
mxd = arcpy.mapping.MapDocument(<PATH_TO_MAP_DOCUMENT>)
pageNames = arcpy.GetParameterAsText(0).split(';')

pageIDs = [mxd.dataDrivenPages.getPageIDFromName(pageName) for pageName in pageNames]
mxd.dataDrivenPages.exportToPDF(<PATH_TO_PDF>, "RANGE", ",".join([str(n) for n in pageNames]))
arcpy.SetParameterAsText(1, <PATH_TO_PDF>)‍‍‍‍‍‍‍