AnsweredAssumed Answered

Calculate geometry deletes any feature classes NOT in the parameters

Question asked by jake.johnson_SPIMAPS on Sep 13, 2019
Latest reply on Sep 16, 2019 by jake.johnson_SPIMAPS

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

        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 " \
                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
                input_layer = input_layer.split("\\")[1].replace("'", "", )

                # 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")
                return messages.addMessage("Finished")