Calculate geometry deletes any feature classes NOT in the parameters

318
1
09-13-2019 06:11 AM
JakeJohnson
New Contributor III

I'm writing four tools to calculate X and Y coordinates in Northing/Easting then create a spatial ID based off of those coordinates. Each one will be stormpoint, stormline, sewerpoint, sewerline. So far, everything works exactly as planned except the part where CalculateGeometryAttributes_management deletes any layer that it doesn't work on. So if I have 5 stormwater point feature classes and input two it will delete the other three entirely. And just as a sanity check, I made sure that no other part of this code deletes entire feature classes when the tool runs. It produces this error since it can  no longer find any data in the tables:

class StormPointAttribution(object):

    def __init__(self):
        self.label = "Stormwater Point Attribution"
        self.description = "Calculates geo-spatial coordinates and spatial/facility IDs where applicable"
        self.category = "Attribution"
        self.canRunInBackground = True

    def getParameterInfo(self):

        input_storm_points = arcpy.Parameter(
            displayName="Input Storm Point Features",
            name="input_storm_points",
            datatype="GPFeatureLayer",
            parameterType="Required",
            direction="Input",
            multiValue=True,
        )

        input_storm_points.filter.list = ["Point"]

        params = [input_storm_points, ]

        return params

    def execute(self, parameters, messages):

        # Define input parameters as a list
        input_layers = parameters[0].valueAsText.split(";")

        # Loop through every input layer
        for input_layer in input_layers:
            if input_layer:

                # Variables
                arcpy.env.workspace = r"C:\Users\jtjohnson\Documents\ArcGIS\Projects\City of Springfield -  Sewer Network\City of Springfield -  Sewer " \
                                                       r"Network.gdb"
                spatial_id_point = r"str(int(!NAD83X!))[2:4] + str(int(!NAD83Y!))[2:4] + '-' + str(int(!NAD83X!))[4] + str(int(!NAD83Y!))[4] + '-' + " \
                                   r"str(int(!NAD83X!))[-2:] + str(int(!NAD83Y!))[-2:]"

                # Takes the input layer and separates it into a usable string for calculation input
                messages.addMessage("{0}".format(input_layer))
                input_layer = input_layer.split("\\")[1].replace("'", "", )
                messages.addMessage("{0}".format(input_layer))

                # TODO: Select only newer data
                selected = arcpy.SelectLayerByAttribute_management(input_layer, "NEW_SELECTION", )

                # Calculate geometrical attributes
                # TODO: Make this not delete everything
                arcpy.CalculateGeometryAttributes_management(selected, "NAD83X POINT_X;NAD83Y POINT_Y")
                messages.addMessage("GEO COMPLETE")

                # Calculate Spatial ID and Facility ID
                # TODO: Add the rest of the fields
                arcpy.CalculateField_management(selected, "FACILITYID", spatial_id_point, )
                messages.addMessage("ATT COMPLETE")
            else:
                return messages.addMessage("Finished")
Tags (3)
0 Kudos
1 Reply
JakeJohnson
New Contributor III

Update: Progress is slow but I have figured out the reason for this issue. arcpy.CalculateGeometryAttributes_management does not play well with multivalue inputs. No matter what I do it will not accept any parameters with multiValue=True. For now, I created a separate tool and removed multivalue functionality. That leads me to an entirely other issue... I have a dozen layers I want to programmatically attribute.

0 Kudos