import arcpy, common from networking import BulkInteractionCreator PARAM_COUNT = 13 with common.runtool(PARAM_COUNT) as parameters: places, placesIDField, network, impedance, cutoff, cutoffFld, numToFind, numToFindFld, searchDist, chosenFields, excludeSelf, location, outputName = parameters transferFieldList = common.parseFields(chosenFields) conn = BulkInteractionCreator(places, placesIDField, location, excludeSelf=common.toBool(excludeSelf, 'self-interaction switch')) conn.loadNetwork(network, impedance, cutoff=cutoff, numToFind=numToFind, cutoffFld=cutoffFld, numToFindFld=numToFindFld, searchDist=searchDist) conn.addPlaceFields(transferFieldList) conn.loadPlaces() conn.solve() conn.output(outputName, PARAM_COUNT) conn.close()
import common from networking import TableInteractionCreator with common.runtool(9) as parameters: table, fromIDField, toIDField, interFields, places, placesIDField, placesFields, location, outName = parameters interFieldList = common.parseFields(interFields) placesFieldList = common.parseFields(placesFields) link = TableInteractionCreator(table, [fromIDField, toIDField], places, placesIDField, location) link.addLinkFields(interFieldList) link.addPlaceFields(placesFieldList) link.loadPlaces() link.output(outName) link.close()
import sys, os, arcpy, math sys.path.append('.') import common TMP_CIRCPTS = 'tmp_circ' TMP_ALLPOLY = 'tmp_voroall' with common.runtool(7) as parameters: common.progress('parsing attributes') ## GET AND PREPARE THE ATTRIBUTES # obtained from the tool input points, ptsIDFld, weightFld, normStr, transferFldsStr, tolerStr, outPath = parameters location, outName = os.path.split(outPath) normalization = math.sqrt(common.toFloat(normStr, 'normalization value') / math.pi) tolerance = common.toFloat(tolerStr, 'positional tolerance value') transferFlds = common.parseFields(transferFldsStr) common.progress('creating weighting layer') common.overwrite(True) circLayer = common.createFeatureClass(os.path.join(location, TMP_CIRCPTS), crs=points) inShpFld = arcpy.Describe(points).ShapeFieldName circShapeFld = arcpy.Describe(circLayer).ShapeFieldName arcpy.AddField_management(circLayer, ptsIDFld, common.outTypeOfField(points, ptsIDFld)) inCount = common.count(points) common.progress('opening weighting layer') inCur = arcpy.SearchCursor(points) outCur = arcpy.InsertCursor(circLayer) prog = common.progressor('weighting points', inCount) pi2 = 2 * math.pi for inRow in inCur:
import common, objects, loaders, regionalization, collections, operator INTRAFLOW_MODES = {'NONE' : [], 'ALL' : [(True, True, True, True)], 'CORE-HINTERLAND' : [(True, False, False, True), (False, True, True, False)], 'CORE-CORE' : [(True, False, True, False)], 'CORE-(CORE+HINTERLAND)' : [(True, False, True, True), (False, True, True, False)]} with common.runtool(11) as parameters: common.progress('loading settings') zoneLayer, zoneIDFld, zoneRegFld, zoneCoreFld, aggregMode, intraflowMode, \ interLayer, interFromIDFld, interToIDFld, aggregFldsStr, outPath = parameters # set up data loading regload = loaders.RegionalLoader(regionalization.Regionalizer(objects.FunctionalRegion)) regload.sourceOfZones(zoneLayer, {'id' : zoneIDFld}, targetClass=objects.MonoZone) regload.sourceOfPresets({'assign' : zoneRegFld, 'coop' : zoneCoreFld}) interDict = {'from' : interFromIDFld, 'to' : interToIDFld} aggregFlds = common.parseFields(aggregFldsStr) interDict.update({fld : fld for fld in aggregFlds}) regload.sourceOfMultiInteractions(interLayer, interDict, ordering=aggregFlds) # flow aggregation mode regSrc, regTgt = aggregMode.split('-') hinterSrc = bool(regSrc != 'CORE') coreTgt = bool(regTgt == 'CORE') try: intraFlowSetting = INTRAFLOW_MODES[intraflowMode] except KeyError: raise ValueError, 'unknown intraflow setting: ' + intraflowMode # load the data regload.load() # aggregate regs = regload.getRegionalizer().getRegions() common.progress('aggregating flows') flows = {} for region in regs:
import common, objects, loaders, regionalization OUT_MEASURES = {'TOT_IN_CORE' : 'IN', 'TOT_OUT_CORE' : 'OUT'} with common.runtool(9) as parameters: zoneLayer, zoneQuery, zoneIDFld, interLayer, interQuery, interStrengthFlds, \ interFromIDFld, interToIDFld, doCount = parameters interFlds = common.parseFields(interStrengthFlds) zoneInSlots = {'id' : zoneIDFld} objects.MultiInteractions.setDefaultLength(len(interFlds)) objects.MonoZone.interactionClass = objects.MultiInteractions interSlots = {'from' : interFromIDFld, 'to' : interToIDFld} interSlots.update({fld : fld for fld in interFlds}) measuresToSlots = {} outSlots = {} for measure in OUT_MEASURES: measuresToSlots[measure] = [] for fld in interFlds: slotName = fld + '_' + OUT_MEASURES[measure] measuresToSlots[measure].append(slotName) outSlots[slotName] = slotName regload = loaders.RegionalLoader(regionalization.Regionalizer(objects.FunctionalRegion)) regload.sourceOfZones(zoneLayer, zoneInSlots, targetClass=objects.MonoZone, coreQuery=zoneQuery) regload.sourceOfMultiInteractions(interLayer, interSlots, where=interQuery, ordering=interFlds) regload.load() common.progress('summarizing') measurer = objects.ZoneMeasurer() zoneData = {} indexes = range(len(interFlds)) for zone in regload.getZoneList(): zoneID = zone.getID()
import arcpy, common, loaders ASSIGNED = 'tmp_z057' with common.runtool(11) as parameters: zones, idFld, regionFld, coopFld, regTransFldsStr, nameFldsStr, sumCoreFldsStr, countCoresStr, sumAllFldsStr, countAllStr, outPath = parameters # parse field lists nameFlds = common.parseFields(nameFldsStr) regTransFlds = common.parseFields(regTransFldsStr) if regionFld in regTransFlds: regTransFlds.remove(regionFld) sumCoreFlds = common.parseFields(sumCoreFldsStr) sumAllFlds = common.parseFields(sumAllFldsStr) coreTrans = {fld : 'CORE_' + fld for fld in sumCoreFlds} allTrans = {fld : 'ALL_' + fld for fld in sumAllFlds} outSumFlds = coreTrans.values() + allTrans.values() coreTransItems = coreTrans.items() allTransItems = allTrans.items() countCores = common.toBool(countCoresStr, 'core count switch') countAll = common.toBool(countAllStr, 'zone count switch') zoneSlots = {'id' : idFld, 'assign' : regionFld} if coopFld: zoneSlots['core'] = coopFld for fld in set(nameFlds + regTransFlds + sumCoreFlds + sumAllFlds): zoneSlots[fld] = fld common.progress('reading zone data') zoneData = loaders.DictReader(zones, zoneSlots).read() print zoneData common.progress('computing region statistics')
import common from networking import ODJoiner with common.runtool(6) as parameters: table, fromIDField, toIDField, places, placesIDField, placesFields = parameters placesFieldList = common.parseFields(placesFields) link = ODJoiner(table, [fromIDField, toIDField], places, placesIDField) link.addPlaceFields(placesFieldList) link.loadPlaces() link.join() link.close()