2

Why when I try to save my layer in destination gdb (I pass path) does it save in default.gdb?

def getParameterInfo(self):
    """Define parameter definitions"""

    param0 = arcpy.Parameter(
        name="Input Features",
        displayName="Area",
        direction="Input",
        datatype="DEFeatureClass",
        parameterType="Required")

    param1 = arcpy.Parameter(
        name="Output Features",
        displayName="Output Features Class",
        direction="Output",
        datatype="DEFeatureClass",
        parameterType="Required")

    param2 = arcpy.Parameter(
        name="Input Number0",
        displayName="Cell Size Width",
        direction="Input",
        datatype="Double",
        parameterType="Required")

    param3 = arcpy.Parameter(
        name="Input Number1",
        displayName="Cell Size Height",
        direction="Input",
        datatype="Double",
        parameterType="Required")

    param4 = arcpy.Parameter(
        name="O",
        displayName="O",
        direction="Input",
        datatype="DEFeatureClass",
        parameterType="Required")

    parameters = [param0, param1, param2, param3, param4]

    return parameters

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."""

    reload(sys)
    sys.setdefaultencoding('utf8')

    # teritory
    inputFeatureClass = parameters[0].valueAsText

    # my output
    outputFeatureClass = parameters[1].valueAsText 
    outPath = os.path.basename(outputFeatureClass)

    arcpy.AddMessage(outputFeatureClass)

    cellWidth = parameters[2].value

    cellHeight = parameters[3].value

    o = parameters[4].valueAsText

    # my workspace require to fishnet
    # arcpy.env.workspace = outputFeatureClass

    # when I will be save file, each of them will be overwriting existing file about same name
    arcpy.env.overwriteOutput = True

    origin, yAxis, opposite = coordinates(inputFeatureClass)

    # create fishnet
    fishnet = arcpy.CreateFishnet_management("in_memory/Fishnet", origin, yAxis, cellWidth, cellHeight, '0', '0',
                                             opposite, 'LABELS', inputFeatureClass, 'POLYGON')
    # add field for id
    arcpy.AddField_management(fishnet, 'idField', 'LONG')

    # add id sequence
    with arcpy.da.UpdateCursor(fishnet, ['idField']) as cursor:
        i = 1
        for row in cursor:
            row[0] = i
            cursor.updateRow(row)
            i += 1
    del cursor

    # clip a final fishnet
    finalFishnet = arcpy.Clip_analysis(fishnet, inputFeatureClass,
                                       outPath)  

    # create dict for results
    score = {}

    # adding every key value equal 0
    with arcpy.da.SearchCursor(finalFishnet, ['idField']) as cursor:
        for row in cursor:
            score[row[0]] = 0
    del cursor

    oFunction(o, finalFishnet, score)

    addResultFunction(finalFishnet, score)

    return

enter image description here

After execute

enter image description here

1 Answer 1

3

Your code does not specify the output correctly. You extract outPath from parameter 1. Your fishnet is sent to in_memory but it is the final Clip that is creating the output. If you look at the syntax section of the clip tool, it's third parameter is a FEATURECLASS but you provide only a BASENAME (but rather confusingly called it outPath) to the clip tool. This tool also does NOT honour workspace as it does not appear in the environment setting of this tools. So you need to provide a full path to the FeatureClass which is you parameter 1. If you review the code section of this tool help you will see how to call this tool correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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