How to build rasters populated with an equation in Python?

المشرف العام

Administrator
طاقم الإدارة
I am working on creating a python toolbox to solve for WiFi signal properties based on various inputs, and for the end result I would like to have the output in the form of a raster. I need this raster to take on an equation value (FSPL) for each cell, based on a cost raster (distance raster) and numerical inputs (frequency type in GHz and feet-meter conversion coefficient). Below is the code that I have attempted, but I get an error reading:

Traceback (most recent call last): File "", line 108, in executeTypeError: can't multiply sequence by non-int of type 'float'.Failed to execute (FSPL).

Here is the code below (with line 108 marked with writing in the code itself near the bottom):

import arcpyimport mathclass Toolbox(object): def __init__(self): """Define the toolbox (the name of the toolbox is the name of the .pyt file).""" self.label = "Toolbox Label Property" self.alias = "Toolbox Alias Property" # List of tool classes associated with this toolbox self.tools = [FSPL, WAP_Buffer]class FSPL(object): def __init__(self): """Define the tool (tool name is the name of the class).""" self.label = "Free Space Path Loss" self.description = "This python script tool will create Free Space Path Loss to determine the dB range output from the WAPs." self.canRunInBackground = False def getParameterInfo(self): """Define parameter definitions""" param0 = arcpy.Parameter( displayName="Wireless Access Points", name="wireless_pts", datatype="GPFeatureLayer", parameterType="Required", direction="Input") param1 = arcpy.Parameter( displayName="Network Frequency Type", name="network_freq", datatype="String", parameterType="Required", direction="Input") param1.filter.type="ValueList" param1.filter.list = ["2.4 GHz", "5 GHz"] param2 = arcpy.Parameter( displayName="Distance Raster", name="dist_rast", datatype="GPRasterLayer", parameterType="Required", direction="Input") param3 = arcpy.Parameter( displayName="Distance Raster Units", name="units", datatype="String", parameterType="Required", direction="Input") param3.filter.type="ValueList" param3.filter.list = ["Feet", "Meters"] param4 = arcpy.Parameter( displayName="Output Raster", name="output_rast", datatype="GPRasterLayer", parameterType="Required", direction="Output") return [param0, param1, param2, param3, param4] def isLicensed(self): """Set whether tool is licensed to execute.""" return True def updateParameters(self, parameters): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed.""" return def updateMessages(self, parameters): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" return def execute(self, parameters, messages): """The source code of the tool.""" #Get inputs wireless_pts = parameters[0].valueAsText network_freq = parameters[1].valueAsText dist_rast = parameters[2].valueAsText units = parameters[3].valueAsText output_rast = parameters[4].valueAsText shapeFieldName = arcpy.Describe(wireless_pts).shapeFieldName #Create expression if network_freq == "2.4 GHz": hertz=2400000000 else: hertz=5000000000 if units == "Feet": distmod=0.3048 else: distmod=1 #equationLINE 108 fspl= (4 * math.pi * distmod * dist_rast * hertz)/(2.99792458 * (10**8)) output_rast = fspl return I am fairly new to using python and there could be something very basic that I am not grasping. This all seemed a little to easy for someone without much python experience to produce, and so I am skeptical that I am forgetting something big. If anyone has any ideas on how I can implement what I want to produce I would be very happy to hear them.



أكثر...
 
أعلى