Data Driven Pages-Restrict Indexed Feature

1207
12
06-24-2011 11:00 AM
BarbaraMcIntosh
New Contributor
I'm creating a series of Data Driven pages at a fixed scale of 1:12000.  I have multiple features in my index layer that, at that scale, appear within the data frame.  I'd like to be able to restrict the feature that appears within the data frame to only the one feature defined by the indexing for that page.  Is there an easy way to do this?  Used to be able to do this in DSMapbook by clicking "Restrict display to active feature"
0 Kudos
12 Replies
DarrenWiens2
MVP Honored Contributor
You should check out Page Definition Queries. They are meant to restrict features based on the data driven page displayed.
0 Kudos
BarbaraMcIntosh
New Contributor
Thanks...works great...
0 Kudos
JasonMoore
New Contributor
This seems to be limited to the field used for the PageName.  Is there a way to Query a layer based off of a different field in the Data Driven Pages Layer?

Is there a way to make the Page Definition Query look at Field 2 but the PageName be pulled from Field 1 in the Data Driven Pages (DDP) layer?

Example:
DDP Layer: Field 1 (PageName), Field 2 (Global ID)
Map Layer: Field 1 (Map Reference), Field 2(Global ID)
0 Kudos
DarrenWiens2
MVP Honored Contributor
I don't know of a way to apply a Page Definition to a field other than the Page Name, but you should be able to join the DDP Layer to the Map Layer table to access the matching Page Names.

Example:
DDP Layer: Field1 (PageName), Field2 (Global ID)
Map Layer: Field1 (Map Reference), Field2(Global ID)

JOIN ->

Map Layer: Map.Field1 (Map Reference), Map.Field2 (Global ID), DDP.Field2 (Global ID), DDP.Field1 (PageName)
0 Kudos
JasonMoore
New Contributor
Thank you for your promt reply.  I tried your solution and came up bust.

That would work under most normal circumsances. 

However, the problem is that when you join the two layers the each Global_ID actually has two PageName record associated with them, so there isn't a unique match that way.
0 Kudos
DarrenWiens2
MVP Honored Contributor
I'm pretty sure this is what you want: Make Query Table. You need a many-to-one join between your map layer (many) and data driven pages (one), based on Global ID being equal.
0 Kudos
JasonMoore
New Contributor
Thanks again for your prompt reply.

I will look into this and let you know of the outcome.
0 Kudos
JasonMoore
New Contributor
This works great if the data is stored in the same database.  However, that is another hurdle I must overcome.  The Map Layer is in an SDE database, that I do not have adequate privledges to alter the schema as I would need it, and the Pages Layer is in a File GDB. 

I really wish I could just write a definition query on a layer based upon a sub query from another layer.

Map Layer: GLOBALID IN (SELECT GLOBALID FROM DDP_LAYER)
0 Kudos
JasonMoore
New Contributor
I have found a work around. PYTHON saved the day again.  Something like the following. 

# Import Modules
import arcpy, os

# Set Variables
mxdpath = r'FULL PATH TO MXD FILE' # string
outputfolder = 'FULL PATH TO OUTPUT FOLDER' # string
namefield = 'THE FIELD CONTAINING THE NAME OF THE RESULTING PDF FILE' # string
queryfield = 'THE FIELD CONTAINING THE VALUE FOR THE DESIRED QUERY' # string
layers = ['LIST','OF','LAYERS'] # list

mxd = arcpy.mapping.MapDocument(mxdpath)
# Start Loop through Data Driven Pages
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1)
  mxd.dataDrivenPages.currentPageID = pageNum # set the current page
  pageName = mxd.dataDrivenPages.pageRow.getValue(field) # get the pageName
  pageName += '.pdf' # add '.pdf' extension for file name
  pdf = os.path.join(outputfolder, pageName) # add pageName to output folder to get full output path
  # Start Loop through all layers of mxd file
  for lyr in arcpy.mapping.ListLayers(mxd)  # for every layer in mxd's Layer List
    if lyr.name in layers: # if layer name in user input list above
      value = mxd.DataDrivenPages.pageRow.getValue(queryfield) # get the value out of the query field
      if lyr.defintionQuery == True:  # if a defintionQuery Exsts...
        query = lyr.defintionQuery + "AND QueryField = \'%s\'" % (value) # Add the new to the old
      else:
        query = "QueryField = \'$s\'" % (value) # else create a new query
      lyr.defintionQuery = query  # set the layers defintionQuery
    else:
      print 'Next' # else print next, this isn't necassary, but its a good place holder
    arcpy.mapping.ExportToPDF(mxd, pdf) # export the current Page to pdf

del mxd, lyr, pageName, pageNum, query, value
0 Kudos