コード例 #1
0
def weightedCostRaster(outputCodeName, layerOrder=None):
    """
	Source dir: preprocessed
	Output dir: costRasters

	outputCodeName: 1311011.asc where value of each digit |-->  weight
									  index of each digit |-->  layer index in given list
																(so use the same layer order every time in every function!)
	
	layerOrder: ['agl_resis', 'bcmp_resis', 'bestp_resis', ...] --- layer names in order that corresponds to outputCode
	"""

    if layerOrder is None:
        print "No layer order specified, that's kinda important."
        return

    sources = layerOrder
    weights = map(int, list(outputCodeName.replace(".asc", "")))

    # outputCode = "".join(map(str, weights))
    print "Making weighted cost raster {}".format(outputCodeName)

    paths.setEnv(env)

    output = paths.join(paths.costRasters, outputCodeName)
    if arcpy.Exists(output) and not redoExistingOutput:
        print "{} already exists, leaving it as is.".format(output)
        return output

    active = [(paths.join(paths.preprocessed, source), weight)
              for source, weight in zip(sources, weights) if weight > 0]
    if len(active) <= 1:
        # TODO: add the straight-line-distance raster, so least cost paths don't freak out?
        pass

    costRas = sa.CreateConstantRaster(0.0001, "FLOAT", env.cellSize,
                                      env.extent)
    for source, weight in active:
        costRas += sa.Raster(source) * weight

    arcpy.RasterToASCII_conversion(costRas, output)
    arcpy.CalculateStatistics_management(output,
                                         x_skip_factor=30,
                                         y_skip_factor=30)

    return output
コード例 #2
0

    deleteme.append(reclassSlope)

    # clip Elevaiton to AOI
    arcpy.AddMessage("Clipping Elevation...")
    elevClip = os.path.join(env.scratchGDB,"elevClip")
    #arcpy.MakeRasterLayer_management(inputElevation,"ElevLayer")
    #arcpy.CopyRaster_management("ElevLayer",elevClip)
    outElev = sa.ExtractByMask(inputElevation,inputAOI)
    outElev.save(elevClip)
    deleteme.append(elevClip)
    
    # make constant raster
    constNoEffect = os.path.join(env.scratchGDB,"constNoEffect")
    outConstNoEffect = sa.CreateConstantRaster(1.0,"FLOAT",env.cellSize,arcpy.Describe(inputAOI).Extent)
    outConstNoEffect.save(constNoEffect)
    deleteme.append(constNoEffect)
    
    # f1: vehicle parameters
    f1 = os.path.join(env.scratchFolder,"f1.tif")
    # f1 = (vehicle max off-road slope %) - (surface slope %) / (vehicle max on-road slope %) / (vehicle max KPH)
    if debug == True:
        arcpy.AddMessage(str(time.strftime("F1: %m/%d/%Y  %H:%M:%S", time.localtime())))
        arcpy.AddMessage("slopeClip: " + str(slopeClip))
    slopeAsRaster = sa.Raster(reclassSlope)
    outF1 = (float(vehicleParams[5]) - slopeAsRaster) / (float(vehicleParams[4]) / float(vehicleParams[3]))
    outF1.save(f1)
    ccmFactorList.append(f1)
    deleteme.append(f1)
    
コード例 #3
0

    deleteme.append(reclassSlope)

    # clip Elevaiton to AOI
    arcpy.AddMessage("Clipping Elevation...")
    elevClip = os.path.join(env.scratchGDB,"elevClip")
    #arcpy.MakeRasterLayer_management(inputElevation,"ElevLayer")
    #arcpy.CopyRaster_management("ElevLayer",elevClip)
    outElev = sa.ExtractByMask(inputElevation,inputAOI)
    outElev.save(elevClip)
    deleteme.append(elevClip)

    # make constant raster
    constNoEffect = os.path.join(env.scratchGDB,"constNoEffect")
    outConstNoEffect = sa.CreateConstantRaster(1.0,"FLOAT",env.cellSize,arcpy.Describe(inputAOI).Extent.projectAs(env.outputCoordinateSystem))
    outConstNoEffect.save(constNoEffect)
    deleteme.append(constNoEffect)

    # f1: vehicle parameters
    f1 = os.path.join(env.scratchFolder,"f1.tif")
    # f1 = (vehicle max off-road slope %) - (surface slope %) / (vehicle max on-road slope %) / (vehicle max KPH)
    if debug == True:
        arcpy.AddMessage(str(time.strftime("F1: %m/%d/%Y  %H:%M:%S", time.localtime())))
        arcpy.AddMessage("slopeClip: " + str(slopeClip))
    slopeAsRaster = sa.Raster(reclassSlope)
    outF1 = (float(vehicleParams[5]) - slopeAsRaster) / (float(vehicleParams[4]) / float(vehicleParams[3]))
    outF1.save(f1)
    ccmFactorList.append(f1)
    deleteme.append(f1)