1. 程式人生 > 實用技巧 >arcpy 根據屬性出圖

arcpy 根據屬性出圖

提供一個思路,具體情況具體瞎改。

import arcpy
import os

def GetFieldUniqueValue(inTable,inField):
    rows=arcpy.da.SearchCursor(inTable,inField)
    value_lst=[row[0] for row in rows]
    return set(value_lst)

def main():
    layer=arcpy.GetParameter(0)
    field=arcpy.GetParameterAsText(1)
    outJpegDir=arcpy.GetParameterAsText(2)
    width
=arcpy.GetParameter(3) height=arcpy.GetParameter(4) res=arcpy.GetParameter(5) mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] uniqueValues=GetFieldUniqueValue(layer,field) try: recordCount=len(uniqueValues) arcpy.SetProgressor(
"step","{} unique-values in this table.".format(recordCount),0,recordCount,1) for val in uniqueValues: arcpy.SetProgressorLabel("{} is exporting...".format(val)) arcpy.SetProgressorPosition() arcpy.SelectLayerByAttribute_management(layer,"NEW_SELECTION","{0}='{1}'
".format(field,val)) df.zoomToSelectedFeatures() arcpy.SelectLayerByAttribute_management(layer,"CLEAR_SELECTION")#reset selected features as none. outJpegPath=os.path.join(outJpegDir,val+'.jpg') arcpy.AddMessage(outJpegPath) arcpy.mapping.ExportToJPEG (mxd, out_jpeg=outJpegPath, data_frame=df, df_export_width=width, df_export_height=height, resolution=res, world_file=True, color_mode='24-BIT_TRUE_COLOR', jpeg_quality=100, progressive=False ) except Exception as e: arcpy.AddError(e.message) if __name__ == '__main__': main()