1

I have this layout; it's a map that I divided it to 25 parts using FISHNET from arctoolbox. I want to prepare only one layout and then using a Python script I want to be able to automate the production of the other 24.

layout

The problem is when I use the layout of one part from the fishnet I got 24 empty PDFs and only one with the layout I already started with. But when I use the layout of the whole map it kind of works, and I got 25 PDFs with the 25 parts of the Fishnet but it look like this:

.

.

.

So who can help me to get PDFs with those parts but on the whole page!

My code:

gp=arcgisscripting.create()
arcpy.env.overwriteOutput=True
mxd=arcpy.mapping.MapDocument(r"D:\PFE\data\carte.mxd")
df=arcpy.mapping.ListDataFrames(mxd, "*")[0]
print df

source_geod= arcpy.mapping.Layer(r"D:\PFE\data\PFE\traitement\geod.lyr")
source_RR= arcpy.mapping.Layer(r"D:\PFE\data\PFE\traitement\RR.lyr")
source_oueds= arcpy.mapping.Layer(r"D:\PFE\data\PFE\traitement\oueds.lyr")
source_SBKA= arcpy.mapping.Layer(r"D:\PFE\data\PFE\traitement\SBKA.lyr")
source_Veg= arcpy.mapping.Layer(r"D:\PFE\data\PFE\traitement\Veg.lyr")


i=0
fc=(r"D:\PFE\data\fishnet1.shp")
rows=arcpy.SearchCursor(fc)

for row in rows:
    print i
    print row



    layerFishnet_src=gp.MakeFeatureLayer_management(fc, "lyr")
    layerFishnet=gp.SelectLayerByAttribute_management("lyr", "NEW_SELECTION",'("FID" = ' + str(i) + ')' )

    geod_i= arcpy.Clip_analysis(r"D:\PFE\data\Geod.shp", layerFishnet,
    r"D:\PFE\data\Geod_"+str(row.getValue("FID"))+".shp")

    rr_i= arcpy.Clip_analysis(r"D:\PFE\data\RR.shp", layerFishnet,
    r"D:\PFE\data\RR_"+str(row.getValue("FID"))+".shp")

    oueds_i= arcpy.Clip_analysis(r"D:\PFE\data\oueds.shp", layerFishnet,
    r"D:\PFE\data\oueds_"+str(row.getValue("FID"))+".shp")

    SBKA_i= arcpy.Clip_analysis(r"D:\PFE\data\SBKA.shp", layerFishnet,
    r"D:\PFE\data\SBKA_"+str(row.getValue("FID"))+".shp")

    Veg_i= arcpy.Clip_analysis(r"D:\PFE\data\Veg.shp", layerFishnet,
    r"D:\PFE\data\Veg_"+str(row.getValue("FID"))+".shp")


    geoidlyr=gp.MakeFeatureLayer_management(geod_i, "geoidlyr")
    rrlyr=gp.MakeFeatureLayer_management(rr_i, "rrlyr")
    ouedslyr=gp.MakeFeatureLayer_management(oueds_i, "ouedslyr")
    SBKAlyr=gp.MakeFeatureLayer_management(SBKA_i, "SBKAlyr")
    Veglyr=gp.MakeFeatureLayer_management(Veg_i, "Veglyr")

    geoid=arcpy.mapping.Layer(geoidlyr)
    rr=arcpy.mapping.Layer(rrlyr)
    oueds=arcpy.mapping.Layer(ouedslyr)
    SBKA=arcpy.mapping.Layer(SBKAlyr)
    Veg=arcpy.mapping.Layer(Veglyr)

    lyrr = arcpy.mapping.ListLayers(mxd)[3]
    print lyrr

    lygeoid = arcpy.mapping.ListLayers(mxd)[2]
    print lygeoid

    lyoueds = arcpy.mapping.ListLayers(mxd)[4]
    print lyoueds

    lySBKA = arcpy.mapping.ListLayers(mxd)[6]
    print lySBKA

    lyVeg = arcpy.mapping.ListLayers(mxd)[5]
    print lyVeg



    arcpy.mapping.UpdateLayer( df, lygeoid ,geoid, false )
    arcpy.mapping.UpdateLayer( df, lyrr ,rr,  False)
    arcpy.mapping.UpdateLayer( df, lyoueds ,oueds,  False)
    arcpy.mapping.UpdateLayer( df, lySBKA ,SBKA,  False)
    arcpy.mapping.UpdateLayer( df, lyVeg ,Veg,  False)


    titleTxt= arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "title")
    titleTxt=row.getValue("name")
    print titleTxt
    arcpy.mapping.ExportToPDF(mxd,r"D:\PFE" + row.getValue("name") + ".pdf")
    i = i + 1
2
  • 3
    Unless you specifically want to reinvent the wheel I would strongly suggest taking a look at Data Driven Pages. – Chris W May 23 '15 at 20:17
  • 1
    As Chris W commented, Esri's functionality called Data Driven Pages is exactly what you are trying to do. – MLowry May 23 '15 at 20:20
2

If I understand the question, you are trying to have the same layout but have the map pan to each grid cell for printing to pdf.

What version of ArcGIS are you using? At 10.x you can use data driven pages for this task. http://resources.arcgis.com/en/help/main/10.1/index.html#//00s90000003n000000

What is the purpose of clipping everything? As a faster cleaner option build a masking layer from the fishnet, and use a definition query to exclude the current grid cell to display the data in the grid.

The part that is missing from your code is manipulating the map extent to zoom to the current grid. From the feature cursor, get the envelope of the grid, and set the the map frame extent to the envelope. Something like is discussed here... Using Arcpy to zoom to selected feature? That will center the display on the grid. Be sure to refresh the map display before printing.

1
  • i'm using 10.1 but i have to do it with python script for my "PFE"... when i center to the limite i want ,i got 24 empty PDFs and only one with the layout i already start with..i tried the "zoom" :p but idk why it didn't works . THX i will try again with what u just told me :) – mrabet chayma May 23 '15 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.