Beispiel #1
0
 def mapData(self, table, mappers=[]):
   prog = common.progressor('mapping attributes', common.count(table))
   cur = arcpy.UpdateCursor(table)
   for row in cur:
     for mapper in mappers:
       row = mapper.remap(row, row)
     cur.updateRow(row)
     prog.move()
   del cur, row
   prog.end()
Beispiel #2
0
 def process(self):
   # check if ID is integer - if not, create an integer field
   count = common.count(self.zones)
   idFld = self.zoneMapper.getIntIDField(setID=True, unmapPrevious=False, progressor=common.progressor('creating temporary IDs', count))
   self.zoneMapper.loadData(common.progressor('loading zone data', count))
   # generate SWM file
   common.progress('generating spatial matrix')    
   arcpy.GenerateSpatialWeightsMatrix_stats(self.zones, idFld, self.swmFile, self.method)
   common.progress('converting matrix to table')
   arcpy.ConvertSpatialWeightsMatrixtoTable_stats(self.swmFile, self.tmpTable)
   self.zoneMapper.setJoinIDFields([idFld, self.NEIGH_ID_FLD])
Beispiel #3
0
 def getGeometryDict(self, attributes={}):
   prog = common.progressor('caching geometries', common.count(self.routeSublayer))
   geomDict = {}
   inCur = arcpy.SearchCursor(self.routeSublayer)
   for inRow in inCur:
     ids = self.placeMapper.getIDs(inRow)
     geomDict[ids] = {'shape' : inRow.shape}
     for attrTo in attributes:
       geomDict[ids][attrTo] = inRow.getValue(attributes[attrTo])
     prog.move()
   prog.end()
   del inCur, inRow
   return geomDict
Beispiel #4
0
 def remapData(self, source, output, mappers=[], processor=None):
   count = common.count(source)
   if count == 0:
     common.warning('remapping source is empty, empty output generated')
     return
   prog = common.progressor('remapping records', count)
   inCur = arcpy.SearchCursor(source)
   outCur = arcpy.InsertCursor(output)
   # common.debug('remapping')
   for inRow in inCur:
     outRow = outCur.newRow()
     for mapper in mappers:
       outRow = mapper.remap(inRow, outRow, processor)
       # common.debug(mapper, outRow)
       if outRow is None:
         break
     if outRow is not None:
       outCur.insertRow(outRow)
     prog.move()
   prog.end()
   del inCur, inRow, outCur, outRow
  except KeyError:
    raise ValueError, 'invalid mass type: {}, JOBS or EA allowed'.format(massType)
  zoneSlots = {'id' : zoneIDFld, 'mass' : zoneMassFld}
  interSlots = {'from' : interFromIDFld, 'to' : interToIDFld, 'value' : interStrengthFld}
  # 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, zoneSlots)
  regload.sourceOfInteractions(interLayer, interSlots)
  regload.load()
  zonelist = regload.getZoneList()
  prog = common.progressor('calculating intraflows', len(zonelist))
  intraDict = {}
  for zone in zonelist:
    intraflow = zone.getMass() - zone.sumFlows(out=subtractOutflows)
    if intraflow > 0:
      id = zone.getID()
      intraDict[id] = {id : intraflow}
    prog.move()
  prog.end()
  # common.progress('writing ')  
  loaders.InteractionWriter(interLayer, interSlots, append=True).write(intraDict, text='writing intraflows')

Beispiel #6
0
 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:
   # load input geometry
   pt = inRow.getValue(inShpFld).getPart(0)
   id = inRow.getValue(ptsIDFld)
   coor = (pt.X, pt.Y)
   # load radius
   radius = math.sqrt(inRow.getValue(weightFld)) * normalization
   print inRow.getValue(weightFld), radius, normalization
   ptCount = max(int(pi2 * radius / tolerance), 3)
   delta = pi2 / ptCount
   angle = 0
   while angle < pi2:
     outRow = outCur.newRow()
     outRow.setValue(circShapeFld, arcpy.Point(coor[0] + radius * math.cos(angle), coor[1] + radius * math.sin(angle)))
  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
  
  if distLimitStr:
    distLimit = common.toFloat(distLimitStr, 'distance limit')
  else:
    distLimit = extR + extC
  
  ## COUNTING potentials
  prog = common.progressor('calculating potentials', rowCount * colCount)
  values = numpy.zeros((rowCount, colCount), dtype=numpy.float32)
  for i in range(rowCount):
    curX += cellSize
    curY = defCurY
    for j in range(colCount):
      curY += cellSize
      val = 0
      for point in pointList:
        dist = math.hypot((point[0] - curX), (point[1] - curY))
        if dist <= distLimit:
          val += point[2] / dist ** decayCoef
      values[rowCount - i - 1][j] = val
      prog.move()
  prog.end()
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
Beispiel #9
0
 def loadPlaces(self):
   self.placeMapper.loadData(common.progressor('loading place data', common.count(self.places)))