AnsweredAssumed Answered

ArcPy- iterating through select by location, adding values to table

Question asked by cjachelski on Apr 3, 2017
I have 2 layers-- polygons of isochrones for bike share stations and land use parcels. I am calculating square footage of residential parcels (as well as non-residential parcels in another layer) that are within each isochrone. There are overlaps in the shapes, so I can't do a spatial join, as I am interested in the total parcels in each shape
For each bike share station, I need to:
1. select the parcels that have their centroid within the isochrone
2. get the sum of building square footage from a column in the parcels layer
3. assign that sum value to the station in the isochrone layer
My code keeps failing because I need the outstats table to append a row for each station/iteration, or to just directly have the summed value go into the SF_Res field in the "rows" variable/table. SF_Res is an existing field in the rows table and I want to add the Stats output value to that field for each row.
Here is what I have:
import arcpy
from arcpy import env

env.workspace = "C:\Users\folder"
env.overwriteOutput = True

rows = "C:\Users\folder\bikeshare.shp"
layername = "res_parcels5"
outtable = "C:\Users\folder\bikes.gdb\statsout

arcpy.MakeFeatureLayer_management("C:\Users\folder\Parcels_Res.shp", layername)

#for each Station in rows
for row in rows:
# select all parcels with centroid in rows
arcpy.SelectLayerByLocation_management(layername, "have_their_center_in", rows)
# sum bldg_area field in parcels layer
expression = arcpy.Statistics_analysis(layername, outtable, [["bldg_area", "SUM"]])
arcpy.CalculateField_management (rows, "SF_Res", expression, "PYTHON")

This is an example of the selection that I want to iterate through