Setting geometry type of a python toolbox output

653
0
03-25-2019 10:42 AM
GrantHaynes
Occasional Contributor

I have a python toolbox that I want to publish as a geoprocessing service, the problem is I can't set the geometry type of the output so it's failing when I try to use it as a GP service. Does anyone know how to set the geometry type of a python toolbox out put? Tool was published from arcmap 10.6, running on arcserver 10.5.

import arcpy
import os

# Tool initialization
#-----------------------------------------------------------------------------
class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Value_Extraction_Tool"
        self.alias = "Value Extraction Tool"

        # List of tool classes associated with this toolbox
        self.tools = [Tool]

class Tool(object):
    def __init__(self):
        #Define the tool (tool name is the name of the class)
        self.label = "Value Extraction Tool"
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo(self):
        DataSource = arcpy.Parameter(
		    displayName="DataSource",
		    name="DataSource",
		    datatype="DEWorkspace",
		    parameterType="Required",
		    direction="Input")

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

        OutputFC = arcpy.Parameter(
            displayName="OutputFC",
		    name="OutputFC",
		    datatype="DEFeatureClass",
		    parameterType="Output",
		    direction="Output")

        #OutputFC.schema.geometryType = "Point"
        params = [DataSource, InputPoint, OutputFC]
        return params

    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.
        parameters[2].schema.geometryType = "Point"
        parameters[2].schema.geometryTypeRule = "As Specified"
        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):
        arcpy.env.overwriteOutput = True

        # User input arguments
        DataSource = parameters[0].valueAsText
        InputPoint = parameters[1].valueAsText
        OutputFC = parameters[2].valueAsText 

        # Handle all input point procesing
        arcpy.CopyFeatures_management(InputPoint, OutputFC)
        
        # Add fields to hold temporal data
        arcpy.AddField_management(OutputFC, "LABEL", "TEXT")
        arcpy.AddField_management(OutputFC, "VALUE", "SHORT")

        # Loop through geometry attributes and get the x and y
        with arcpy.da.SearchCursor(InputPoint,['SHAPE@X', 'SHAPE@Y']) as cursor:
            PointIndex = 1
            for row in cursor:
                X = row[0]
                Y = row[1]

                # Get rasters and extract data at an X and Y        
                index = 0
                for (path, dirs, files) in os.walk(DataSource):
                    for ThisFile in files:
                        fName,fExt = os.path.splitext(ThisFile)
                        if fExt.upper() == ".IMG" or fExt.upper() == ".TIF":
                            RasterPath = path + "\\" + ThisFile      
                            data = (arcpy.GetCellValue_management(RasterPath, str(X) + " " + str(Y), "").getOutput(0))
                            aquisition_date = arcpy.GetRasterProperties_management(in_raster = RasterPath, property_type = "ACQUISITIONDATE")

                            if str(aquisition_date).upper() == "UNKNOWN":
                                insertcursor = arcpy.InsertCursor(OutputFC)
                                row = insertcursor.newRow()
                                row.setValue("LABEL", "{}, Point: {}".format(index, PointIndex))
                                if data.isdigit() == True:
                                    row.setValue("VALUE", int(data))
                                insertcursor.insertRow(row)
                                del insertcursor
                                index += 1

                PointIndex += 1
        return‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Here is the results of when I publish it

Task: Value Extraction Tool
Display Name: Value Extraction Tool 

Description: 

Category: 

Help URL: https://localhost:6443/arcgis/rest/directories/arcgisoutput/Test/WA_VE_Tool_GPServer/Test_WA_VE_Tool/Tool.htm 

Execution Type: esriExecutionTypeAsynchronous 

Parameters: 
Parameter: InputPoint 
Data Type: GPFeatureRecordSetLayer 
Display Name InputPoint 
Description: ESRS 
Direction: esriGPParameterDirectionInput 
Default Value:
Geometry Type: esriGeometryPoint 
HasZ: false 
HasM: false 
Spatial Reference: 4326  (4326) 

Fields:
OBJECTID ( type: esriFieldTypeOID , alias: OBJECTID )
Features: None.


Parameter Type: esriGPParameterTypeRequired 
Category: 

Parameter: OutputFC 
Data Type: GPFeatureRecordSetLayer 
Display Name OutputFC 
Description: ESRS 
Direction: esriGPParameterDirectionOutput 
Default Value:
Geometry Type: 
HasZ: false 
HasM: false 
Spatial Reference: N/A 
Fields: None

Features: None.


Parameter Type: esriGPParameterTypeRequired 
Category: ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
0 Replies