Thursday, 3 November 2016

cursor - ArcPy: (SearchCursor/export to tiff ) with no output



I'm trying to write a script that uses a search cursor to loop through a field in a .shp file (Incident_Z) find every value that meets a specific condition (zip code=10004) and then at a scale of 1000, the layout at that scale to a pdf.


With advice from various folks I've tried two approaches:





  1. Using a search cursor. However I've run into problems with it: The problem is that there is no output, and interestingly, no errors. The script runs, and when I include a print "Done" statement at the end, prints correctly.


    import arcpy


    mxd = arcpy.mapping.MapDocument("C:\temp\Graffiti_DM1.mxd") df = arcpy.mapping.ListDataFrames(mxd, "*")[0] expdir= "C:\temp"


    cursor=arcpy.SearchCursor("C:\temp\itscomplicated.shp",'"Incident_Z" = ' + "'10004'", "", "", "")


    for cur in cursor: cur.rotation = 0 cur.scale = 1000 outFile = expdir + "\" + cur.name + ".tif" cur.panToExtent(lyr.getSelectedExtent()) arcpy.mapping.ExportToTIFF(mxd, outFile, df)


    del cursor




  2. Additionally, I've tried as per @PolyGeo's suggestion, the definition query method, below, which runs and produces an output, but not exactly what.I'm looking for.Definition Query code. The problem is that the output is a pdf (I'm actually preferential to pdf than tiff) of the current extent of the layout, and only the current layout. What I'm looking to do is to have a page for each instance of the where_clause, i.e. each record where '"Incident_Z" = ' + "'10033'", at a specified scale of 1000. Is it possible to modify the existing definition_query script to achieve that? As always, any advice is greatly apprecaited.







No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...