当前位置: 首页>>代码示例>>Python>>正文


Python SSUtilities.openFile方法代码示例

本文整理汇总了Python中SSUtilities.openFile方法的典型用法代码示例。如果您正苦于以下问题:Python SSUtilities.openFile方法的具体用法?Python SSUtilities.openFile怎么用?Python SSUtilities.openFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SSUtilities的用法示例。


在下文中一共展示了SSUtilities.openFile方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUniqueIDField

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import openFile [as 别名]
def setUniqueIDField(ssdo, weightsFile):
    """Replace SSUTILITIES.setUniqueIDField to support flexible weights file 
    headers."""
    if weightsFile == None:
        return ssdo.oidName
    
    weightsSuffix = weightsFile.split(".")[-1].lower()
    swmFileBool = (weightsSuffix == "swm")
    
    if swmFileBool:
        return UTILS.setUniqueIDField(ssdo, weightsFile)
    
    fo = UTILS.openFile(weightsFile, "r")
    header = fo.readline().strip()
    headerItems = header.split(" ") 
    
    if len(headerItems) == 1 and weightsSuffix == "gal":
        return ssdo.oidName
    
    elif len(headerItems) > 1:
        for item in headerItems:
            if not item.isdigit() and item.lower() != "unknown" \
               and len(item) > 0:
                masterField = item
                # check to see if in ssdo
                for fieldName, fieldObj in ssdo.allFields.items():
                    if fieldObj.baseName.upper() == masterField.upper():
                        return masterField
                    
    msg = "Header is not valid in Weights file (%s)." % weightsFile
    ARCPY.AddWarning(msg)
开发者ID:Esri,项目名称:PySAL-ArcGIS-Toolbox,代码行数:33,代码来源:pysal2ArcUtils.py

示例2: report

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import openFile [as 别名]
    def report(self, fileName = None):
        """Reports the Standard Distance results as a message or to a file.

        INPUTS:
        fileName {str, None}: path to a text file to populate with results
        """

        header = ARCPY.GetIDMessage(84224)
        columns = [ARCPY.GetIDMessage(84191), ARCPY.GetIDMessage(84211),
                   ARCPY.GetIDMessage(84212), ARCPY.GetIDMessage(84225),
                   ARCPY.GetIDMessage(84226)]
        results = [columns]
        for case in self.uniqueCases:
            if not self.caseField:
                strCase = "ALL"
            else:
                strCase = UTILS.caseValue2Print(case, self.caseIsString)
            meanX, meanY = self.meanCenter[case]
            rowResult = [ strCase, LOCALE.format("%0.6f", meanX),
                          LOCALE.format("%0.6f", meanY),
                          LOCALE.format("%0.6f", self.sd[case]),
                          LOCALE.format("%0.1f", self.stdDeviations) ]
            results.append(rowResult)

        outputTable = UTILS.outputTextTable(results, header = header)
        if fileName:
            f = UTILS.openFile(fileName, "w")
            f.write(outputTable)
            f.close()
        else:
            ARCPY.AddMessage(outputTable)
开发者ID:rvinc66,项目名称:ArcGISRuntimeBook,代码行数:33,代码来源:StandardDistance.py

示例3: report

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import openFile [as 别名]
    def report(self, fileName = None):
        """Reports the Central Feature results as a message or to a file.

        INPUTS:
        fileName {str, None}: path to a text file to populate with results.
        """

        header = ARCPY.GetIDMessage(84200)
        columns = [ARCPY.GetIDMessage(84191), ARCPY.GetIDMessage(84201), 
                   ARCPY.GetIDMessage(84202)]
        results = [ columns ]
        for case in self.uniqueCases:
            if not self.caseField:
                strCase = "ALL"
            else:
                strCase = UTILS.caseValue2Print(case, self.caseIsString)
            cfOIDs, minSumDist = self.cf[case]
            cfOIDs = [ str(i) for i in cfOIDs ]
            cfOIDs = ", ".join(cfOIDs)
            rowResult = [ strCase, 
                          cfOIDs,
                          LOCALE.format("%0.6f", minSumDist) ]
            results.append(rowResult)

        outputTable = UTILS.outputTextTable(results, header = header)
        if fileName:
            f = UTILS.openFile(fileName, "w")
            f.write(outputTable)
            f.close()
        else:
            ARCPY.AddMessage(outputTable)
开发者ID:rvinc66,项目名称:ArcGISRuntimeBook,代码行数:33,代码来源:CentralFeature.py

示例4: report

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import openFile [as 别名]
    def report(self, fileName = None):
        """Reports the Moran's I results as a message or to a file.  If
        self.displayIt is set to True, then an html graphical report is
        generated to your default temp directory.

        INPUTS:
        fileName {str, None}: path to a text file to populate with results.
        """

        #### Create Output Text Table ####
        header = ARCPY.GetIDMessage(84160)
        giString = LOCALE.format("%0.6f", self.gi)
        eiString = LOCALE.format("%0.6f", self.ei)
        viString = LOCALE.format("%0.6f", self.vi) 
        ziString = LOCALE.format("%0.6f", self.zi) 
        pvString = LOCALE.format("%0.6f", self.pVal) 
        row1 = [ARCPY.GetIDMessage(84148), giString]
        row2 = [ARCPY.GetIDMessage(84149), eiString]
        row3 = [ARCPY.GetIDMessage(84150), viString]
        row4 = [ARCPY.GetIDMessage(84151), ziString]
        row5 = [ARCPY.GetIDMessage(84152), pvString]
        results =  [row1, row2, row3, row4, row5]
        outputTable = UTILS.outputTextTable(results, header = header,
                                            pad = 1)

        #### Add Linear/Angular Unit ####
        if self.wType in [0, 1, 7]:
            distanceOut = self.ssdo.distanceInfo.outputString
            dmsg = ARCPY.GetIDMessage(84344)
            distanceMeasuredStr = dmsg.format(distanceOut)
            outputTable += "\n%s\n" % distanceMeasuredStr

        #### Write/Report Text Output ####
        if fileName:
            f = UTILS.openFile(fileName, "w")
            f.write(outputTable)
            f.close()
        else:
            ARCPY.AddMessage(outputTable)

        #### Set Formatted Floats ####
        self.giString = giString
        self.eiString = eiString
        self.viString = viString
        self.ziString = ziString
        self.pvString = pvString
        
        return giString, ziString, pvString
开发者ID:rvinc66,项目名称:ArcGISRuntimeBook,代码行数:50,代码来源:MoransI.py

示例5: report

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import openFile [as 别名]
    def report(self, fileName = None):
        """Generate Text and Graphical Output."""

        if fileName:
            f = UTILS.openFile(fileName, "w")
            f.write("%s\n" % self.coefTable.encode('utf-8'))
            f.write("%s\n" % self.diagTable.encode('utf-8'))
            f.write("%s" % self.interpretTable.encode('utf-8'))
            f.close()
        else:
            ARCPY.AddMessage(self.coefTable)
            ARCPY.AddMessage(self.diagTable)
            ARCPY.AddMessage(self.interpretTable)

            #### Report if Bad Probabilities Found ####
            if self.badProbs:
                ARCPY.AddIDMessage("WARNING", 738)
开发者ID:rvinc66,项目名称:ArcGISRuntimeBook,代码行数:19,代码来源:OLS.py

示例6: report

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import openFile [as 别名]
    def report(self, fileName = None):
        """Reports the General G results as a message or to a file.  If
        self.displayIt is set to True, then an html graphical report is
        generated to your default temp directory.

        INPUTS:
        fileName {str, None}: path to a text file to populate with results.
        """

        #### Format Output ####
        observedOut = LOCALE.format("%0.6f", self.nn)
        expectedOut = LOCALE.format("%0.6f", self.en)
        ratioOut = LOCALE.format("%0.6f", self.ratio)
        zValueOut = LOCALE.format("%0.6f", self.zn)
        pValOut = LOCALE.format("%0.6f", self.pVal)

        #### Create Output Text Table ####
        header = ARCPY.GetIDMessage(84161)
        row1 = [ ARCPY.GetIDMessage(84162), observedOut ]
        row2 = [ ARCPY.GetIDMessage(84163), expectedOut ]
        row3 = [ ARCPY.GetIDMessage(84164), ratioOut ]
        row4 = [ ARCPY.GetIDMessage(84151), zValueOut ]
        row5 = [ ARCPY.GetIDMessage(84152), pValOut ]
        total = [row1,row2,row3,row4,row5]
        outputTable = UTILS.outputTextTable(total, header = header, pad = 1)
        distanceOut = self.ssdo.distanceInfo.outputString
        dmsg = ARCPY.GetIDMessage(84344)
        distanceMeasuredStr = dmsg.format(distanceOut)
        outputTable += "\n%s\n" % distanceMeasuredStr

        if fileName:
            f = UTILS.openFile(fileName, "w")
            f.write(outputTable)
            f.close()
        else:
            ARCPY.AddMessage(outputTable)

        #### Set Formatted Floats ####
        self.nnString = observedOut
        self.enString = expectedOut
        self.ratioString = ratioOut
        self.znString = zValueOut
        self.pvString = pValOut
        self.nnStringD = self.ssdo.distanceInfo.printDistance(self.nn)
        self.enStringD = self.ssdo.distanceInfo.printDistance(self.en)
开发者ID:rvinc66,项目名称:ArcGISRuntimeBook,代码行数:47,代码来源:NearestNeighbor.py

示例7: report

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import openFile [as 别名]
    def report(self, fileName = None):
        """Reports Field Information.

        INPUTS:
        fileName {str, None}: path to report text file
        """

        header = "Candidate Field Description"
        row1 = ["Field Name: ", self.name]
        row2 = ["Field Type: ", self.type]
        row3 = ["Field Alias: ", str(self.alias)]
        row4 = ["Field Length: ", str(self.length)]
        results =  [row1, row2, row3, row4]
        outputTable = UTILS.outputTextTable(results, header = header)
        if fileName:
            f = UTILS.openFile(fileName, "w")
            f.write(outputTable)
            f.close()
        else:
            ARCPY.AddMessage(outputTable)
开发者ID:rvinc66,项目名称:ArcGISRuntimeBook,代码行数:22,代码来源:SSDataObject.py

示例8: report

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import openFile [as 别名]
    def report(self, fileName = None):
        """Reports the k-function results as a message or to a file.

        INPUTS:
        fileName {str, None}: path to a text file to populate with results.
        """
        header = ARCPY.GetIDMessage(84185)
        columns = [ARCPY.GetIDMessage(84342), ARCPY.GetIDMessage(84180), 
                   ARCPY.GetIDMessage(84181)]
        if self.permutations:
            columns += [ARCPY.GetIDMessage(84182), ARCPY.GetIDMessage(84183)]
        results = [columns]
        for testIter in range(self.nIncrements):
            dist = self.cutoffs[testIter]
            ldVal = self.ld[testIter]
            diff = ldVal - dist
            rowResults = [ LOCALE.format("%0.2f", round(dist, 2)),
                           LOCALE.format("%0.2f", round(ldVal, 2)),
                           LOCALE.format("%0.2f", round(diff, 2)) ]
            if self.permutations:
                minVal = round(self.ldMin[testIter], 2)
                maxVal = round(self.ldMax[testIter], 2)
                rowResults.append(LOCALE.format("%0.2f", minVal))
                rowResults.append(LOCALE.format("%0.2f", maxVal))

            results.append(rowResults)

        outputTable = UTILS.outputTextTable(results, header = header)
        distanceOut = self.ssdo.distanceInfo.outputString
        distanceMeasuredStr = ARCPY.GetIDMessage(84343).format(distanceOut)
        outputTable += "\n%s" % distanceMeasuredStr
        if fileName:
            f = UTILS.openFile(fileName, "w")
            f.write(outputTable)
            f.close()
        else:
            ARCPY.AddMessage(outputTable)
开发者ID:rvinc66,项目名称:ArcGISRuntimeBook,代码行数:39,代码来源:KFunction.py

示例9: report

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import openFile [as 别名]
    def report(self, fileName = None):
        """Reports the Moran's I results as a message or to a file.

        INPUTS:
        fileName {str, None}: path to a text file to populate with results.
        """

        header = ARCPY.GetIDMessage(84160) + ARCPY.GetIDMessage(84282)
        results = [ self.resLabels ]
        hasNoNeighs = self.noNeighs.any()
        strNoNeighs = ARCPY.GetIDMessage(84111)

        #### Create Output Text Table ####
        for testIter in range(self.nIncrements):
            d, gi, ei, vi, zi, pv = self.giResults[testIter]
            d = LOCALE.format("%0.2f", round(d, 2))
            gi = LOCALE.format("%0.6f", gi)
            ei = LOCALE.format("%0.6f", ei)
            vi = LOCALE.format("%0.6f", vi)
            zi = LOCALE.format("%0.6f", zi)
            pv = LOCALE.format("%0.6f", pv)

            #### Add Asterisk to No Neigh Distances ####
            if hasNoNeighs:
                numNoNeighs = self.noNeighs[testIter]
                if numNoNeighs:
                    d += strNoNeighs
                else:
                    d += " "
            res = [d, gi, ei, vi, zi, pv]
            results.append(res)

        outputReport = UTILS.outputTextTable(results, header = header,
                                             justify = "right", pad = 1)

        #### Report Peaks ####
        firstPeakMess = ARCPY.GetIDMessage(84419)
        decimalSep = UTILS.returnDecimalChar()
        if decimalSep == ".":
            numSep = ","
        else:
            numSep = ";"
        if self.firstPeakInd != None:

            zi = LOCALE.format("%0.6f", self.giResults[self.firstPeakInd,4])
            d = LOCALE.format("%0.2f", round(self.firstPeakDistance, 2))

            firstPeakMess = firstPeakMess.format(d, numSep, zi)
        else:
            firstPeakMess = firstPeakMess.format("None", numSep, "None")
        outputReport += "\n" + firstPeakMess + "\n"

        maxPeakMess = ARCPY.GetIDMessage(84420)
        if self.maxPeakInd != None:
            zi = LOCALE.format("%0.6f", self.giResults[self.maxPeakInd,4])
            d = LOCALE.format("%0.2f", round(self.maxPeakDistance, 2))
            maxPeakMess = maxPeakMess.format(d, numSep, zi)
        else:
            maxPeakMess = maxPeakMess.format("None", numSep,"None")
        outputReport += maxPeakMess

        #### Add Linear/Angular Unit ####
        distanceOut = self.ssdo.distanceInfo.outputString
        dmsg = ARCPY.GetIDMessage(84344)
        distanceMeasuredStr = dmsg.format(distanceOut)
        outputReport += "\n%s\n" % distanceMeasuredStr

        if fileName:
            if hasNoNeighs:
                noNeighMess = ARCPY.GetIDMessage(84417) + "\n"
                outputReport += noNeighMess
            f = UTILS.openFile(fileName, "w")
            f.write(outputReport)
            f.close()
        else:
            ARCPY.AddMessage(outputReport)
            if hasNoNeighs:
                ARCPY.AddIDMessage("WARNING", 1532)

        return outputReport
开发者ID:rvinc66,项目名称:ArcGISRuntimeBook,代码行数:82,代码来源:MoransI_Increment.py

示例10: exportXYV

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import openFile [as 别名]
def exportXYV(inputFC, fieldList, delimiter, outFile, outFieldNames=False):
    """Exports the X,Y Coords and Set of Field Values for a Given
    Feature Class.

    INPUTS:
    inputFC (str): path to the input feature class
    fieldList (list): list of field names to export
    delimiter (str): token to delimit output file with
    outFile (str): path to the output text file
    outFieldNames (bool): return field names in first row of text file?

    OUTPUT:
    outFile (file): output text file
    """

    #### Get Feature Class Properties ####
    ssdo = SSDO.SSDataObject(inputFC, useChordal=False)
    inputFields = [ssdo.oidName, "[email protected]"] + fieldList

    #### Create Progressor Bar ####
    cnt = UTILS.getCount(inputFC)
    ARCPY.AddMessage(ARCPY.GetIDMessage(84012))
    ARCPY.SetProgressor("step", ARCPY.GetIDMessage(84012), 0, cnt, 1)

    #### Keep track of Invalid Fields ####
    badIDs = []
    badRecord = 0

    #### Process Field Values ####
    try:
        rows = DA.SearchCursor(ssdo.inputFC, inputFields, "", ssdo.spatialRefString)
    except:
        ARCPY.AddIDMessage("ERROR", 204)
        raise SystemExit()

    #### Get Field Types and Set LOCALE Dictionary ####
    floatTypes = ["Single", "Double"]
    localeDict = {}
    for field in fieldList:
        fieldType = ssdo.allFields[field].type
        if fieldType in floatTypes:
            formatToken = "%f"
        else:
            formatToken = "%s"
        localeDict[field] = formatToken

    #### Create Output File ####
    fo = UTILS.openFile(outFile, "w")

    #### Write Field Names to File ####
    if outFieldNames:
        outPath, outName = OS.path.split(outFile)
        allFieldNames = UTILS.getFieldNames(exyvFieldNames, outPath)
        allFieldNames += fieldList
        outRow = delimiter.join(allFieldNames)
        fo.write("%s\n" % outRow.encode("utf-8"))

    for row in rows:
        OID = row[0]
        badValues = row.count(None)
        badXY = row[1].count(None)
        badRow = badValues or badXY
        if not badXY:
            xCoord, yCoord = row[1]
            x = LOCALE.format("%0.8f", xCoord)
            y = LOCALE.format("%0.8f", yCoord)
        else:
            x = "NULL"
            y = "NULL"

        #### Check to see whether field values are OK ####
        rowValues = [x, y]
        for ind, field in enumerate(fieldList):
            value = row[ind + 2]
            if value == "" or value == None:
                rowValues.append("NULL")
            else:
                formatValue = LOCALE.format(localeDict[field], value)
                rowValues.append(formatValue)

        #### Keep TRack of Bad Records ####
        if badRow:
            badIDs.append(OID)

        #### Continue Based on Whether a Bad Row ####
        outRow = delimiter.join(rowValues)
        fo.write("%s\n" % outRow.encode("utf-8"))

        ARCPY.SetProgressorPosition()

    #### Clean Up ####
    del rows
    fo.close()
    ARCPY.AddMessage(outFile)

    #### Get Set of Bad IDs ####
    badIDs = list(set(badIDs))
    badIDs.sort()
    badIDs = [str(i) for i in badIDs]

#.........这里部分代码省略.........
开发者ID:rvinc66,项目名称:ArcGISRuntimeBook,代码行数:103,代码来源:ExportXYV.py

示例11: runModels

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import openFile [as 别名]
    def runModels(self):
        """Performs additional validation and populates the
        SSDataObject."""

        #### Shorthand Attributes ####
        ssdo = self.ssdo

        #### Create Dependent Variable ####
        self.y = ssdo.fields[self.dependentVar].returnDouble()
        self.n = ssdo.numObs
        self.y.shape = (self.n, 1)

        #### Assure that Variance is Larger than Zero ####
        yVar = NUM.var(self.y)
        if NUM.isnan(yVar) or yVar <= 0.0:
            ARCPY.AddIDMessage("Error", 906)
            raise SystemExit()

        #### Validate Chosen Number of Combos ####
        k = len(ssdo.fields)
        if self.maxIndVars > (k - 1):
            ARCPY.AddIDMessage("WARNING", 1171, self.maxIndVars)
            self.maxIndVars = k - 1
            ARCPY.AddIDMessage("WARNING", 1172, self.maxIndVars)

        #### Assure Degrees of Freedom ####
        withIntercept = self.maxIndVars + 1
        dof = self.n - withIntercept
        if dof <= 2:
            ARCPY.AddIDMessage("WARNING", 1128, 2)
            dofLimit = self.n - 4
            ARCPY.AddIDMessage("WARNING", 1419, dofLimit)
            self.maxIndVars = dofLimit

        if self.maxIndVars < 1:
            ARCPY.AddIDMessage("WARNING", 1173)

        #### Assure Min Vars is less than or equal to Max Vars ####
        if self.maxIndVars < self.minIndVars:
            ARCPY.AddIDMessage("WARNING", 1174)
            ARCPY.AddIDMessage("WARNING", 1175)
            self.minIndVars = self.maxIndVars

        #### Gen Range Combos ####
        rangeVars = range(1, k)
        rangeCombos = NUM.arange(self.minIndVars, self.maxIndVars+1)

        #### Create Base Design Matrix ####
        self.x = NUM.ones((self.n, k), dtype = float)
        for column, variable in enumerate(self.independentVars):
            self.x[:,column + 1] = ssdo.fields[variable].data

        #### Calculate Global VIF ####
        self.globalVifVals = COLL.defaultdict(float)
        if k > 2:
            #### Values Less Than One Were Forced by Psuedo-Inverse ####
            self.printVIF = True
        else:
            self.printVIF = False

        #### Create Output Report File ####
        fo = UTILS.openFile(self.outputReportFile, "w")

        #### Hold Results for Every Choose Combo ####
        self.resultDict = {}
        self.vifVarCount = COLL.defaultdict(int)
        self.model2Table = {}
        self.sumRuns = 0
        self.sumGI = 0
        self.boolGI = 0
        self.boolResults = NUM.zeros(4, dtype = int)
        self.jbModels = []
        self.jbValues = []
        self.jbResiduals = NUM.empty((self.n, 3), dtype = float)
        self.perfectMultiWarnBool = False
        self.neighborWarn = False

        for choose in rangeCombos:
            #### Generate Index Combos ####
            comboGenerator = ITER.combinations(rangeVars, choose)

            #### Set Progressor ####
            message = ARCPY.GetIDMessage(84293).format(k-1, choose)
            ARCPY.SetProgressor("default", message)

            #### Set Result Structure ####
            rh = ResultHandler(self.independentVars, choose,
                               self.ssdo, self.weightsMatrix,
                               weightsType = self.weightsType,
                               minR2 = self.minR2, maxCoef = self.maxCoef,
                               maxVIF = self.maxVIF, minJB = self.minJB,
                               minMI = self.minMI, silent = self.neighborWarn)

            #### Loop Through All Combinations ####
            modelCount = 0
            emptyTabValues = [""] * ( self.maxIndVars - choose )
            perfectMultiModels = []
            for combo in comboGenerator:
                #### Create Design Matrix for Given Combination ####
                columns = [0] + list(combo)
#.........这里部分代码省略.........
开发者ID:f-tonini,项目名称:Python-Scripts,代码行数:103,代码来源:ModelSelectionOLS.py

示例12: report2html

# 需要导入模块: import SSUtilities [as 别名]
# 或者: from SSUtilities import openFile [as 别名]

#.........这里部分代码省略.........
        }
        td {
            text-align: left;
        }
    """
    head.append(style)
    # </style>

    #### <title>...</title> ####
    title_element = reportTree.find('ssTitle')
    title = ET.Element('title')
    title_text = ("" if title_element is None else title_element.text)
    title.text = title_text

    #### </head> ####
    head.append(title)

    #### <body> ####
    body = ET.Element('body')

    #### <h1>Title</h1> ####
    title_header = ET.Element('h1')
    title_header.text = title_text
    body.append(title_header)

    #### <table>Moran's... ####
    key_div = ET.Element('div')
    key_div.attrib['id'] = "key"
    key_table = ET.SubElement(key_div, 'table')
    key_table.attrib['id'] = "keytable"
    table_element = reportTree.find('ssGraphic/ssFloat')
    for row in (table_element.findall('ssFloatRow') if table_element is not None else []):
        #### <tr> ####
        row_elt = ET.Element('tr')
        label = ET.Element('th')
        label_elt = row.find('Label')
        label.text = (label_elt.text if label_elt is not None else "")
        value = ET.Element('td')
        value_elt = row.find('Value')
        value.text = (value_elt.text if value_elt is not None else "")
        signbox = ET.Element('td')
        signbox_elt = row.find('SignBox')
        if signbox_elt is not None and signbox_elt.text:
            img = ET.Element('img')
            img.attrib['src'] = "file://%s" % signbox_elt.text
            signbox.append(img)
        row_elt.append(label)
        row_elt.append(value)
        row_elt.append(signbox)
        key_table.append(row_elt)
        #### </tr> ####
    #### </table> ####
    body.append(key_div)

    #### <img src="..."> #### 
    img_div = ET.Element('div')
    img_div.attrib['id'] = "mainImg"
    image = ET.SubElement(img_div, 'img')
    image_src = reportTree.find('ssGraphic/ssImage')
    image.attrib['src'] = ("" if image_src is None else "file://%s" % image_src.text)
    image.attrib['alt'] = title_text
    body.append(img_div)

    #### <p>given ...</p> ####
    explanation_element = reportTree.find('ssGraphic/ssFooter')
    expanatory_text = ("" if explanation_element is None else explanation_element.text)
    explanatory_par = ET.SubElement(img_div, 'p')
    explanatory_par.text = expanatory_text
    tables = reportTree.findall('ssTable')
    if tables is not None:
        for table_elt in tables:
            table = ET.Element('table')
            table.attrib["class"] = "infotable"
            caption = ET.Element('caption')
            caption_elt = table_elt.find('ssTableTitle')
            caption.text = (caption_elt.text if caption_elt is not None else "")
            if caption.text:
                table.append(caption)
            for row_elt in table_elt.findall('ssRow'):
                row = ET.Element('tr')
                label = row_elt.find('Label')
                value = row_elt.find('Value')
                label_elt = ET.Element('th')
                label_elt.text = (label.text if label is not None else "")
                value_elt = ET.Element('td')
                value_elt.text = (value.text if value is not None else "")
                row.append(label_elt)
                row.append(value_elt)
                table.append(row)
            body.append(table)
    #### </body> ####
    root.append(head)
    root.append(body)
    htmlStr = ET.tostring(root)
    outHTML = UTILS.openFile(htmlFile, 'w')
    strictDocStr = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">"""
    outHTML.write("%s\n" % strictDocStr)
    outHTML.write(htmlStr)
    outHTML.close()
开发者ID:rvinc66,项目名称:ArcGISRuntimeBook,代码行数:104,代码来源:SSReport.py


注:本文中的SSUtilities.openFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。