Select to view content in your preferred language

Data Driven Pages - Grids out of order

727
1
Jump to solution
12-11-2012 08:52 AM
ShawnDevereaux
Emerging Contributor
My data driven pages are sorted by OBJECTID. I do not currently have another field that is suitable for sorting.

The problem is that my pages do not follow any logical order, they'll skip around all across the grid since the OBJECTIDs are not in a
logical spatial order.

Is there a way to populate a field in the grid's attribute table so that the cells are number like reading a book (i.e. upper left most cell is 1, next one to the right is 2, and so on...)?

My grid is several hundred thousand cells so manually populating it is not possible.
0 Kudos
1 Solution

Accepted Solutions
JeffBarrette
Esri Regular Contributor
Fun question!  The solution really depends on the general shape of your index features.  It also depends on the way that you want to number the features.  I'm assuming starting NW then across and downward to SE.

If your features are rectangular then you could perhaps use GridIndexFeatures to generate a grid with page numbers, convert that to a point FC and overlay/calc fields into your original FC.

But if your features are not uniform, it gets more interesting.  Here is what I did.

Convert index FC into a raster based on OID.  Make sure your cell size is appropriate so there is a grid value for every OID (otherwise you'll need to test for that).  I convert to raster because when you process a raster you work with the upper left cell, move across, then down, etc.  Next I convert the raster into a numpy array (a list of a list of cell values in each row of the raster).  I build a unique list of OID values from the array.  They are built in the direction mentioned above and only the first occurance is added to the unique list.  I place each of those values into a dictionary along with a corresponding page number for every OID  value.  Then I simply iterate through each feature in the original index FC, gets its OID, then set a new field called "page number" based on the page number for that OID.

Here is the code:

import arcpy myArray = arcpy.RasterToNumPyArray(r"C:\Temp\test_fGDB.gdb\testraster")  mxd = arcpy.mapping.MapDocument("current")  pageNumber = 1 myUniqueList = [] myDictionary = {}  for eachArray in myArray:   for value in eachArray:     if value not in myUniqueList:       myUniqueList.append(value)       myDictionary[value] = pageNumber       pageNumber = pageNumber + 1  lyr = arcpy.mapping.ListLayers(mxd)[0] cur = arcpy.UpdateCursor(lyr)  for row in cur:   value = row.getValue("OBJECTID")   row.setValue("PageNumber", myDictionary[value])   cur.updateRow(row)  del cur


I hope the explaination is clearer than mud.

Jeff

View solution in original post

0 Kudos
1 Reply
JeffBarrette
Esri Regular Contributor
Fun question!  The solution really depends on the general shape of your index features.  It also depends on the way that you want to number the features.  I'm assuming starting NW then across and downward to SE.

If your features are rectangular then you could perhaps use GridIndexFeatures to generate a grid with page numbers, convert that to a point FC and overlay/calc fields into your original FC.

But if your features are not uniform, it gets more interesting.  Here is what I did.

Convert index FC into a raster based on OID.  Make sure your cell size is appropriate so there is a grid value for every OID (otherwise you'll need to test for that).  I convert to raster because when you process a raster you work with the upper left cell, move across, then down, etc.  Next I convert the raster into a numpy array (a list of a list of cell values in each row of the raster).  I build a unique list of OID values from the array.  They are built in the direction mentioned above and only the first occurance is added to the unique list.  I place each of those values into a dictionary along with a corresponding page number for every OID  value.  Then I simply iterate through each feature in the original index FC, gets its OID, then set a new field called "page number" based on the page number for that OID.

Here is the code:

import arcpy myArray = arcpy.RasterToNumPyArray(r"C:\Temp\test_fGDB.gdb\testraster")  mxd = arcpy.mapping.MapDocument("current")  pageNumber = 1 myUniqueList = [] myDictionary = {}  for eachArray in myArray:   for value in eachArray:     if value not in myUniqueList:       myUniqueList.append(value)       myDictionary[value] = pageNumber       pageNumber = pageNumber + 1  lyr = arcpy.mapping.ListLayers(mxd)[0] cur = arcpy.UpdateCursor(lyr)  for row in cur:   value = row.getValue("OBJECTID")   row.setValue("PageNumber", myDictionary[value])   cur.updateRow(row)  del cur


I hope the explaination is clearer than mud.

Jeff
0 Kudos