I am trying to create a python toolbox with the following function: I want to select points or lines within a polygon and save the selected feautres as a temporarily Feature. (That works)

Then I want to use SQL-Queries for example to count all Features of the Point-Feature-Class or the total length of a Line-Feature-Class. The result of the queries should be written into an existing Table. For example the result of the total length of a Line-Feature-Class, should be written into the Field: TOTAL_LENGTH.

At the end, the Table should be exported as an excel-file (Should be no problem)

I don't want to get the complete finished code. Just an Idea how to do the query and saving the result into a different existing table.

Does somebody has an idea?


1 Answer 1


I think Richard is right about Summary Statistics being your best bet, but if for some reason you don't want to do that:

1: Select by location (you say this already works)

2: For point feature class:

    count = int(str(arcpy.GetCount_management))

2: For line feature class:

    total_len = 0
    for row in arcpy.da.SearchCursor(line_fc, "SHAPE_Length"):


    with arcpy.da.InsertCursor(output_fc, "StatField") as inserter:
        #StatField will be count or length dep on point or line fc
        inserter.insertRow([count]) #Or total_len if line fc

4: TableToExcel_conversion tool


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.