import common
from networking import TableConnectionCreator

with common.runtool(14) as parameters:
  table, fromIDField, toIDField, interFields, places, placesIDField, placesFields, network, cost, searchDist, speedupStr, speedupDist, location, outName = parameters
  interFieldList = common.parseFields(interFields)
  placesFieldList = common.parseFields(placesFields)
  link = TableConnectionCreator(table, [fromIDField, toIDField], places, placesIDField, location)
  link.addLinkFields(interFieldList)
  link.addPlaceFields(placesFieldList)
  if common.toBool(speedupStr, 'geometry speedup switch'):
    link.speedupOn(common.toFloat(speedupDist, 'maximum geometry speedup range'))
  link.loadNetwork(network, cost, searchDist)
  link.loadPlaces()
  link.output(outName)
  link.close()
import os, arcpy, numpy, math, common

with common.runtool(7) as parameters:
  points, valueField, extent, cellSizeStr, decay, distLimitStr, output = parameters
  decayCoef = common.toFloat(decay, 'distance decay exponent')
  cellSize = common.toFloat(cellSizeStr, 'cell size')
  
  ## LOAD POINTS and their values
  common.progress('loading points')
  pointList = []
  shapeFld = arcpy.Describe(points).ShapeFieldName
  pointCur = arcpy.SearchCursor(points)
  for row in pointCur:
    geom = row.getValue(shapeFld).getPart()
    val = row.getValue(valueField)
    if val is not None:
      pointList.append((geom.Y, geom.X, float(val)))
  del row, pointCur, geom
  
  ## CREATE RASTER
  # calculate row and column counts
  extVals = [common.toFloat(val, 'extent value') for val in extent.split()]
  extR = abs(extVals[3] - extVals[1])
  extC = abs(extVals[2] - extVals[0])
  rowCount = int(round(extR / float(cellSize)))
  colCount = int(round(extC / float(cellSize)))
  # bottom left pixel coordinates minus one pixel
  curX = extVals[1] - cellSize / 2.0
  curY = extVals[0] - cellSize / 2.0
  defCurY = curY
  
示例#3
0
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:
  mass = 0.0
  area = 0.0
  for zone in zonelist:
    mass += zone.get('mass')
    area += zone.get('area')
  return mass / area
      
def delimitDensityAreals(zones, idFld, popFld, thrDens, minPop, targetFld, neighTable=None, doMergeEnclaves=True):
  common.progress('loading areal data')
  loader = loaders.RegionalLoader()
  # common.progress('calculating zone densities')
  areaFld = common.ensureShapeAreaField(zones)
  inSlots = {'id' : idFld, 'mass' : popFld, 'area' : areaFld}
  loader.sourceOfZones(zones, inSlots, targetClass=DensityZone)
  loader.possibleNeighbourhood(neighTable, exterior=True)
  loader.load()
  zones = loader.getZoneDict()
  common.progress('delimiting areals')
  regionalize(zones, thrDens, minPop, doMergeEnclaves)
  common.progress('saving data')
  loader.addZoneOutputSlot('assign', targetFld, require=True)
  loader.outputZones(zones)

if __name__ == '__main__':
  with common.runtool(8) as parameters:
    parameters[3] = common.toFloat(parameters[3], 'threshold density')
    parameters[4] = common.toFloat(parameters[4], 'minimum areal population')
    parameters[7] = common.toBool(parameters[7], 'enclave merge switch')
    # import cProfile
    # cProfile.run('delimitDensityAreals(*parameters)')
    delimitDensityAreals(*parameters)
import arcpy, common

strLayer = 'tmp_i095'
relLayer = 'tmp_i043'

with common.runtool(7) as parameters:
  interLayer, strengthFld, lengthFld, minStrengthStr, minRelStrengthStr, maxLengthStr, output = parameters
  if minStrengthStr or maxLengthStr:
    queries = []
    if minStrengthStr:
      common.progress('assembling absolute strength exclusion')
      minStrength = common.toFloat(minStrengthStr, 'minimum absolute interaction strength')
      queries.append(common.query(interLayer, '[%s] >= %g', strengthFld, minStrength))
    if maxLengthStr:
      common.progress('assembling absolute length exclusion')
      maxLength = common.toFloat(maxLengthStr, 'maximum absolute interaction length')
      queries.append(common.query(interLayer, '[%s] <= %g', lengthFld, maxLength))
    common.selection(interLayer, strLayer, ' OR '.join(queries))
  else:
    strLayer = interLayer
  if minRelStrengthStr:
    common.progress('performing relative strength exclusion')
    minRelStrength = common.toFloat(minRelStrengthStr, 'minimum relative interaction strength')
    relQuery = common.query(interLayer, '[%s] > 0 AND ([%s] / [%s] * 1000) >= %g', lengthFld, strengthFld,
      lengthFld, minRelStrength)
    common.select(strLayer, relLayer, relQuery)
  else:
    relLayer = strLayer
  common.progress('counting selected interactions')
  common.message('%i interactions selected.' % common.count(relLayer))
  common.progress('writing output')
                         popFld,
                         thrDens,
                         minPop,
                         targetFld,
                         neighTable=None,
                         doMergeEnclaves=True):
    common.progress('loading areal data')
    loader = loaders.RegionalLoader()
    # common.progress('calculating zone densities')
    areaFld = common.ensureShapeAreaField(zones)
    inSlots = {'id': idFld, 'mass': popFld, 'area': areaFld}
    loader.sourceOfZones(zones, inSlots, targetClass=DensityZone)
    loader.possibleNeighbourhood(neighTable, exterior=True)
    loader.load()
    zones = loader.getZoneDict()
    common.progress('delimiting areals')
    regionalize(zones, thrDens, minPop, doMergeEnclaves)
    common.progress('saving data')
    loader.addZoneOutputSlot('assign', targetFld, require=True)
    loader.outputZones(zones)


if __name__ == '__main__':
    with common.runtool(8) as parameters:
        parameters[3] = common.toFloat(parameters[3], 'threshold density')
        parameters[4] = common.toFloat(parameters[4],
                                       'minimum areal population')
        parameters[7] = common.toBool(parameters[7], 'enclave merge switch')
        # import cProfile
        # cProfile.run('delimitDensityAreals(*parameters)')
        delimitDensityAreals(*parameters)
示例#7
0
import arcpy, common, randomize

with common.runtool(3) as parameters:
  conns, sdStr, target = parameters
  sd = common.toFloat(sdStr, 'standard deviation of position change')
  common.progress('copying connections')
  arcpy.CopyFeatures_management(conns, target)
  shpFld = arcpy.Describe(target).ShapeFieldName

  prog = common.progressor('randomizing', common.count(target))
  rows = arcpy.UpdateCursor(target)
  for row in rows:
    newPt = randomize.randomizePoint(row.getValue(shpFld), sd)
    row.setValue(shpFld, newPt)
    rows.updateRow(row)
    prog.move()

  prog.end()
  del row, rows
Decay rapidity correction coefficient q: %g

MODEL OUTPUT
Calculated parameters calibrated on real interaction length quantile strength sums
(empirical variogram fitting)
B parameter value: %g
G parameter value: %g
Quantiles (bins) used: %s

STATISTICAL ANALYSIS

'''

with common.runtool(7) as parameters:
  interactions, strengthFld, lengthFld, quantileN, coefStr, outputFld, reportFileName = parameters
  coef = common.toFloat(coefStr, 'distance-decay coefficient')
   
  ## ASSEMBLE INPUT
  common.progress('counting interactions')
  count = common.count(interactions)
  if count == 0:
    raise ValueError, 'no interactions found'
  common.message('Found ' + str(count) + ' rows.')

  common.progress('loading interactions')
  modelInters = loaders.BasicReader(interactions, {'strength' : strengthFld, 'length' : lengthFld}).read()
  
  # if i > 0:
    # common.warning('%i interactions failed to load due to invalid value' % i)
    
  ## OPTIMALIZE