0

I am getting a rather unclear type error, and after searching online I cannot find any solutions that help. I am trying to create my own python toolbox for wifi router signal loss, and I am trying to create a raster based on a few inputs that will populate from an equation. The error that I am getting lies on line 107, which is the equation line

fspl= (4 * math.pi * distmod * dist_float * hertz)/(2.99792458 * (10**8))
output_rast = fspl

I cannot figure out what is causing this error, initially it did not like me trying to use a raster instead of a float, so I changed the distance raster into a float, and now it does not seem to like the float being part of the equation. Here is the rest of my code incase the error stems from an earlier mistake. I cannot find anything that relates to my specific error, and I have not been able to find any way to to work around this issue. Any suggestions?

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 Float",
    name="dist_float",
    datatype="GPLayer",
    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].value
    network_freq = parameters[1].value
    dist_float = parameters[2].value
    units = parameters[3].value
    output_rast = parameters[4].value

    #Create expression

    if network_freq == "2.4 GHz":
        hertz=2400000000
    else:
        hertz=5000000000

    if units == "Feet":
        distmod=0.3048
    else:
        distmod=1

    #equation

    fspl= (4 * math.pi * distmod * dist_float * hertz)/(2.99792458 * (10**8))
    output_rast = fspl



    return 
2

Raster Calculator is an option but limits what you can do. When using arcpy, you must convert your raster dataset to a raster object to perform map algebra.

When defining the parameters in a python toolbox, it may be sufficient to change the data type to GPRasterLayer or GPRasterDataset. Otherwise, just cast the path of the raster to a raster object with Raster().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.