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?
-
If I understand the ask, Summary Statistics could help (though not via SQL): pro.arcgis.com/en/pro-app/tool-reference/analysis/…Richard Morgan– Richard Morgan2019年01月29日 12:11:44 +00:00Commented Jan 29, 2019 at 12:11
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"):
total_len+=row[0]
3:
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
-
The SearchCursor can have a SQL query as a parameter in case you need to select certain records: pro.arcgis.com/en/pro-app/arcpy/data-access/…flintlockspecial– flintlockspecial2019年01月29日 18:32:43 +00:00Commented Jan 29, 2019 at 18:32
-
Great! Glad it worked for you!flintlockspecial– flintlockspecial2019年02月01日 13:02:36 +00:00Commented Feb 1, 2019 at 13:02