Я работаю над созданием набора инструментов python для решения для свойств сигнала WiFi на основе различных входных данных, и для конечного результата я хотел бы получить результат в виде растра. Мне нужно, чтобы этот растровый сигнал принимал значение уравнения (FSPL) для каждой ячейки на основе стоимостного растра (растрового) и числовых входов (тип частоты в ГГц и коэффициент преобразования футов). Ниже приведен код, который я пытался, но я получаю ошибку чтение:Проблема с Python Toolbox
Traceback (most recent call last):
File "<string>", line 108, in execute
TypeError: can't multiply sequence by non-int of type 'float'.
Failed to execute (FSPL).
Вот код ниже (с линией 108 с пометкой письменной формы в самом коде вблизи дна):
import arcpy
import math
class 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
#equation
LINE 108 fspl= (4 * math.pi * distmod * dist_rast * hertz)/(2.99792458 * (10**8))
output_rast = fspl
return
Я довольно новичок в использовании python, и может быть что-то очень основное, что я не понимаю. Все это казалось немного легким для кого-то, у кого не было опыта работы на питоне, и поэтому я скептически отношусь к тому, что забываю что-то большое. Если у кого-нибудь есть идеи о том, как я могу реализовать то, что хочу, я был бы очень рад их услышать.
Вы пытаетесь распечатать всю переменную до строки 108? – Clodion
Перекрестные ссылки как http://gis.stackexchange.com/questions/156016/how-to-build-a-raster-populated-with-an-equation-in-a-python-toolbox – PolyGeo