arcpy 根据属性分类出图

给一个伙计写的,实现ArcMap主窗口屏幕伪截图效果。

代码实现的出图是出的数据视图的数据框,实现截图的效果,这得需要明白,布局视图咋搞自己搞,

提供一个思路,不会搞的可以联系博主定制。

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()

 

posted @ 2020-09-21 21:14  yzhyingcool  阅读(618)  评论(0编辑  收藏  举报