def test_table_to_polyline_UTM_BANDS(self): '''Test Table To Polyline for ArcGIS Desktop_UTM_BANDS''' Configuration.Logger.info( ".....TableToPolylineTestCase.test_table_to_polyline_UTM_BANDS") # Delete the output feature class if already exists if arcpy.Exists(self.outputPolylines): arcpy.Delete_management(self.outputPolylines) arcpy.TableToPolyline_mt(self.inputSingleTable, "UTM_BANDS", "UTM", None, self.outputPolylines) self.assertTrue(arcpy.Exists(self.outputPolylines), "Output features do not exist or were not created") polylineCount = int( arcpy.GetCount_management(self.outputPolylines).getOutput(0)) expectedFeatures = int(1) self.assertEqual( polylineCount, expectedFeatures, "Expected %s features, but got %s" % (str(expectedFeatures), str(polylineCount))) # TODO: Needs correct known good results featureclass # self.assertFeatureClassEqual(self.baseFC, self.outputPolylines, \ # "OBJECTID") return
def test_table_to_polyline_check_vertex_count(self): '''Test Table To Polyline to verify that a last vertex is not being added to close the line to a polygon''' # Test for issue 254 Configuration.Logger.info( ".....TableToPolylineTestCase.test_table_to_polyline_check_vertex_count" ) # Delete the output feature class if already exists if arcpy.Exists(self.outputPolylines): arcpy.Delete_management(self.outputPolylines) toolOutput = arcpy.TableToPolyline_mt(self.inputTable, "DD_2", "POINT_X", "POINT_Y", \ self.outputPolylines, "Group_") # 1: Check the expected return value self.assertIsNotNone(toolOutput, "No output returned from tool") outputOut = toolOutput.getOutput(0) self.assertEqual(self.outputPolylines, outputOut, "Unexpected return value from tool") # 2: Count the number of vertices in the output to see that it matches the number of rows in input table # Set counter to 0 vertex_count = 0 # Enter for loop for each feature for row in arcpy.da.SearchCursor(outputOut, ["OID@", "SHAPE@"]): partnum = 0 # Step through each part of the feature for part in row[1]: # Step through each vertex in the feature for pnt in part: if pnt: # Increment the vertex count vertex_count += 1 else: # If pnt is None, this represents an interior ring print("Interior Ring:") partnum += 1 # 3: Check if this count matches the number of input table rows input_table_row_count = int( arcpy.GetCount_management(self.inputTable).getOutput(0)) self.assertEqual( vertex_count, input_table_row_count, "Expected %s vertices, but got %s" % (str(input_table_row_count), str(vertex_count))) return
def test_table_to_polyline(self): '''Test Table To Polyline for ArcGIS Desktop''' Configuration.Logger.info( ".....TableToPolylineTestCase.test_table_to_polyline") # Delete the output feature class if already exists if arcpy.Exists(self.outputPolylines): arcpy.Delete_management(self.outputPolylines) toolOutput = arcpy.TableToPolyline_mt(self.inputTable, "DD_2", "POINT_X", "POINT_Y", \ self.outputPolylines, "Group_") # 1: Check the expected return value self.assertIsNotNone(toolOutput, "No output returned from tool") outputOut = toolOutput.getOutput(0) self.assertEqual(self.outputPolylines, outputOut, "Unexpected return value from tool") self.assertTrue(arcpy.Exists(self.outputPolylines), "Output features do not exist or were not created") # Process to check tool results for grouping # Step 1: Make in_memory table to get frequency of inMemTable = arcpy.TableToTable_conversion( self.inputTable, "in_memory", "TableToPolyline_single_In_Mem") # Step 2: Get the frequency of unique "group values" in the input table # Get Frequency of the unique names in the input table freqInputTable = arcpy.Frequency_analysis( inMemTable, "in_memory\\CountOfUniqueNames", "Group_", "") # Get Count of the unique names freqTableCount = arcpy.GetCount_management(freqInputTable) expectedFeatureCount = int(freqTableCount.getOutput(0)) polylineCount = int( arcpy.GetCount_management(self.outputPolylines).getOutput(0)) self.assertEqual( polylineCount, expectedFeatureCount, "Expected %s features, but got %s" % (str(expectedFeatureCount), str(polylineCount))) # Tool is not producing correct output - commented out check for now # See: https://github.com/Esri/military-tools-geoprocessing-toolbox/issues/254 # self.assertFeatureClassEqualSimple(self.baseFC, self.outputPolylines, \ # "OBJECTID", 0.0001) return
def test_table_to_polyline_desktop_GARS(self): '''Test Table To Polyline for ArcGIS Desktop_GARS''' runToolMessage = ".....TableToPolylineTestCase.test_table_to_polyline_desktop_GARS" arcpy.ImportToolbox(Configuration.military_DesktopToolboxPath, "mt") arcpy.AddMessage(runToolMessage) Configuration.Logger.info(runToolMessage) arcpy.TableToPolyline_mt(self.inputSingleTable, "GARS", "GARS", None, self.outputPolylines) self.assertTrue(arcpy.Exists(self.outputPolylines), "Output features do not exist or were not created") polylineCount = int(arcpy.GetCount_management(self.outputPolylines).getOutput(0)) expectedFeatures = int(1) self.assertEqual(polylineCount, expectedFeatures, "Expected %s features, but got %s" % (str(expectedFeatures), str(polylineCount))) compareFeatures = arcpy.FeatureCompare_management(self.BaseFC, self.outputPolylines, "Shape_Length") # identical = 'true' means that there are no differences between the base and the output feature class identical = compareFeatures.getOutput(1) self.assertEqual(identical, "true", "Feature compare failed: \n %s" % arcpy.GetMessages()) return