• arcgis python 布局中所有元素信息报告


    # Author:  ESRI
    # Date:    July 5, 2010
    # Version: ArcGIS 10.0
    # Purpose: This script generates a report of each page layout element and its
    #          associated properties. This script is intended to run as a scrip tool
    #          and requires two parameters:
    #               1) Input map document,
    #               2) Output text file.
    
    import arcpy, os, datetime
    
    #Read parameters from tool
    mxdPath = arcpy.GetParameterAsText(0)
    output = arcpy.GetParameterAsText(1)
    
    try:
    
        #Create r/w output file
        outFile = open(output, "w")
    
        #Generate Report header
        outFile.write("PageLayout Element Report: 
    ")
        outFile.write("
    ")
        outFile.write("This report lists the properties of invidual page layout elements within a single MXD. 
    ")
        outFile.write("
    ")
        outFile.write("MXD location: " + mxdPath + "
    ")
        outFile.write("
    ")
        outFile.write("Date: " + str(datetime.datetime.today().strftime("%B %d, %Y")) + "
    ")
        outFile.write("
    ")
    
        #Reference MXD file
        mxd = arcpy.mapping.MapDocument(mxdPath)
                    
        #Report data frame elements
        if len(arcpy.mapping.ListLayoutElements(mxd, "DATAFRAME_ELEMENT")) > 0:
            outFile.write("
    ")
            outFile.write(" DATA FRAME ELEMENTS: 
    ")
            
            for elm in arcpy.mapping.ListLayoutElements(mxd, "DATAFRAME_ELEMENT"):
                outFile.write("
    ")
                outFile.write("	 Name:                " + elm.name + "
    ")
                outFile.write("	 X Position:          " + str(elm.elementPositionX) + "
    ")
                outFile.write("	 Y Position:          " + str(elm.elementPositionY) + "
    ")
                outFile.write("	 Height:              " + str(elm.elementHeight) + "
    ")
                outFile.write("	 Width:               " + str(elm.elementWidth) + "
    ")
    
        #Report graphic elements
        if len(arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT")) > 0:
            outFile.write("
    ")
            outFile.write(" GRAPHIC ELEMENTS: 
    ")
            
            for elm in arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT"):
                outFile.write("
    ")
                outFile.write("	 Name:                " + elm.name + "
    ")
                outFile.write("	 X Position:          " + str(elm.elementPositionX) + "
    ")
                outFile.write("	 Y Position:          " + str(elm.elementPositionY) + "
    ")
                outFile.write("	 Height:              " + str(elm.elementHeight) + "
    ")
                outFile.write("	 Width:               " + str(elm.elementWidth) + "
    ")
    
        #Report legend elements
        if len(arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")) > 0:
            outFile.write("
    ")
            outFile.write(" LEGEND ELEMENTS: 
    ")
            
            for elm in arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT"):
                outFile.write("
    ")
                outFile.write("	 Name:                " + elm.name + "
    ")
                outFile.write("	 Parent data frame:   " + elm.parentDataFrameName + "
    ")
                outFile.write("	 Title:               " + elm.title + "
    ")
                outFile.write("	 X Position:          " + str(elm.elementPositionX) + "
    ")
                outFile.write("	 Y Position:          " + str(elm.elementPositionY) + "
    ")
                outFile.write("	 Height:              " + str(elm.elementHeight) + "
    ")
                outFile.write("	 Width:               " + str(elm.elementWidth) + "
    ")
    
        #Report map surround elements
        if len(arcpy.mapping.ListLayoutElements(mxd, "MAPSURROUND_ELEMENT")) > 0:
            outFile.write("
    ")
            outFile.write(" MAP SURROUND ELEMENTS: 
    ")
            
            for elm in arcpy.mapping.ListLayoutElements(mxd, "MAPSURROUND_ELEMENT"):
                outFile.write("
    ")
                outFile.write("	 Name:                " + elm.name + "
    ")
                outFile.write("	 Parent data frame:   " + elm.parentDataFrameName + "
    ")
                outFile.write("	 X Position:          " + str(elm.elementPositionX) + "
    ")
                outFile.write("	 Y Position:          " + str(elm.elementPositionY) + "
    ")
                outFile.write("	 Height:              " + str(elm.elementHeight) + "
    ")
                outFile.write("	 Width:               " + str(elm.elementWidth) + "
    ")
    
        #Report picture elements
        if len(arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT")) > 0:
            outFile.write("
    ")
            outFile.write(" PICTURE ELEMENTS: 
    ")
            
            for elm in arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT"):
                outFile.write("
    ")
                outFile.write("	 Name:                " + elm.name + "
    ")
                outFile.write("	 X Position:          " + str(elm.elementPositionX) + "
    ")
                outFile.write("	 Y Position:          " + str(elm.elementPositionY) + "
    ")
                outFile.write("	 Height:              " + str(elm.elementHeight) + "
    ")
                outFile.write("	 Width:               " + str(elm.elementWidth) + "
    ")
    
        #Report text elements
        if len(arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")) > 0:
            outFile.write("
    ")
            outFile.write(" TEXT ELEMENTS: 
    ")
            
            for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
                outFile.write("
    ")
                outFile.write("	 Name:                " + elm.name + "
    ")
                outFile.write("	 Text string:         " + elm.text + "
    ")
                outFile.write("	 X Position:          " + str(elm.elementPositionX) + "
    ")
                outFile.write("	 Y Position:          " + str(elm.elementPositionY) + "
    ")
                outFile.write("	 Height:              " + str(elm.elementHeight) + "
    ")
                outFile.write("	 Width:               " + str(elm.elementWidth) + "
    ")
    
        #Close the file
        outFile.close()
    
        #Automatically open the file in associated TXT application
        os.startfile(output)
    
        #Delete all variables
        del mxdPath, outFile, mxd, output
    
    except Exception, e:
      import traceback
      map(arcpy.AddError, traceback.format_exc().split("
    "))
      arcpy.AddError(str(e))
  • 相关阅读:
    面向对象第三次总结性博客
    面向对象程序设计lesson2心得体会
    面向对象程序设计先导课程心得体会
    面向对象程序设计先导lesson1心得体会
    Git 学习笔记
    asp.net 的Eval日期時間怎麼格式化
    正則表達式(轉)
    要等彈出窗口顯示信息後,点击确定再跳轉到其他頁面
    彈出窗口,確定再刪除數據
    SQL SERVER 2008中的兩種潛換字符方法
  • 原文地址:https://www.cnblogs.com/gisoracle/p/11370645.html
Copyright © 2020-2023  润新知