def execute(self, parameters, messages): analysisType = self.kfHelper.getAnalysisTypeSelection()[parameters[0].valueAsText] srcPoints = parameters[1].valueAsText destPoints = parameters[2].valueAsText networkDataset = parameters[3].valueAsText snapDist = parameters[4].value cutoff = parameters[5].value outLoc = parameters[6].valueAsText outFC = parameters[7].valueAsText numPerms = self.kfHelper.getPermutationSelection()[parameters[8].valueAsText] outCoordSys = parameters[9].value numPointsFieldName = parameters[10].value ndDesc = arcpy.Describe(networkDataset) # Refer to the note in the NetworkDatasetLength tool. if outCoordSys is None: outCoordSys = ndDesc.spatialReference messages.addMessage("\nAnalysis type: {0}".format(analysisType)) messages.addMessage("Origin points: {0}".format(srcPoints)) messages.addMessage("Destination points: {0}".format(destPoints)) messages.addMessage("Network dataset: {0}".format(networkDataset)) messages.addMessage("Snap distance: {0}".format(snapDist)) messages.addMessage("Cutoff distance: {0}".format(cutoff)) messages.addMessage("Path to output feature class: {0}".format(outLoc)) messages.addMessage("Output feature class name: {0}".format(outFC)) messages.addMessage("Number of random permutations: {0}".format(numPerms)) messages.addMessage("Network dataset length projected coordinate system: {0}".format(outCoordSys.name)) messages.addMessage("Number of Points Field Name: {0}\n".format(numPointsFieldName)) # The actual work is done in a reusable service. randODCMPermSvc = RandomODCMPermutationsSvc() randODCMPermSvc.generateODCMPermutations(analysisType, srcPoints, destPoints, networkDataset, snapDist, cutoff, outLoc, outFC, numPerms, outCoordSys, numPointsFieldName, messages)
def execute(self, parameters, messages): srcPoints = parameters[0].valueAsText destPoints = parameters[1].valueAsText networkDataset = parameters[2].valueAsText numBands = parameters[3].value begDist = parameters[4].value distInc = parameters[5].value snapDist = parameters[6].value outNetKLoc = parameters[7].valueAsText outRawODCMFCName = parameters[8].valueAsText outRawFCName = parameters[9].valueAsText outAnlFCName = parameters[10].valueAsText numPerms = self.kfHelper.getPermutationSelection()[ parameters[11].valueAsText] outCoordSys = parameters[12].value numPointsFieldName = parameters[13].value ndDesc = arcpy.Describe(networkDataset) gkfSvc = GlobalKFunctionSvc() # Refer to the note in the NetworkDatasetLength tool. if outCoordSys is None: outCoordSys = ndDesc.spatialReference messages.addMessage("\nOrigin points: {0}".format(srcPoints)) messages.addMessage("Destination points: {0}".format(destPoints)) messages.addMessage("Network dataset: {0}".format(networkDataset)) messages.addMessage("Number of distance bands: {0}".format(numBands)) messages.addMessage("Beginning distance: {0}".format(begDist)) messages.addMessage("Distance increment: {0}".format(distInc)) messages.addMessage("Snap distance: {0}".format(snapDist)) messages.addMessage( "Path to output cross-K feature class: {0}".format(outNetKLoc)) messages.addMessage( "Raw ODCM data table: {0}".format(outRawODCMFCName)) messages.addMessage( "Raw cross-K data table (raw analysis data): {0}".format( outRawFCName)) messages.addMessage( "Cross-K summary data (plottable data): {0}".format(outAnlFCName)) messages.addMessage( "Number of random permutations: {0}".format(numPerms)) messages.addMessage( "Network dataset length projected coordinate system: {0}".format( outCoordSys.name)) messages.addMessage( "Number of Points Field Name: {0}\n".format(numPointsFieldName)) # Calculate the length of the network. networkLength = self.kfHelper.calculateLength(networkDataset, outCoordSys) messages.addMessage("Total network length: {0}".format(networkLength)) # Count the number of crashes. numDests = self.kfHelper.countNumberOfFeatures( os.path.join(outNetKLoc, destPoints)) # Set up a cutoff lenght for the ODCM data if possible. (Optimization.) cutoff = gkfSvc.getCutoff(numBands, distInc, begDist) # The results of all the calculations end up here. netKCalculations = [] # Use a mutable container for the number of bands so that the below callback # can write to it. The "nonlocal" keyword not available in Python 2.x. numBandsCont = [numBands] # Callback function that does the Network K calculation on an OD cost matrix. def doNetKCalc(odDists, iteration): # Do the actual network k-function calculation. netKCalc = CrossKCalculation(networkLength, numDests, odDists, begDist, distInc, numBandsCont[0]) netKCalculations.append(netKCalc.getDistanceBands()) # If the user did not specifiy a number of distance bands explicitly, # store the number of bands. It's computed from the observed data. if numBandsCont[0] is None: numBandsCont[0] = netKCalc.getNumberOfDistanceBands() # Generate the ODCM permutations, including the ODCM for the observed data. # doNetKCalc is called on each iteration. randODCMPermSvc = RandomODCMPermutationsSvc() randODCMPermSvc.generateODCMPermutations( "Cross Analysis", srcPoints, destPoints, networkDataset, snapDist, cutoff, outNetKLoc, outRawODCMFCName, numPerms, outCoordSys, numPointsFieldName, messages, doNetKCalc) # Store the raw analysis data. messages.addMessage("Writing raw analysis data.") gkfSvc.writeRawAnalysisData(outNetKLoc, outRawFCName, netKCalculations) # Analyze the data and store the results. messages.addMessage("Analyzing data.") gkfSvc.writeAnalysisSummaryData(numPerms, netKCalculations, outNetKLoc, outAnlFCName)