>> getting an error (message below) regarding the "Point_Tbl" part of the code. <<
Point_tbl should likely be named "Point_tbl.dbf" because it is is to be placed in a directory rather than a geodatabase.
If the destination was a gdb, arc would know that name was for a table..
Yes, Point_tbl is the direct output from PointDistance,
but since you are running PointDistance multiple times in a loop,
(and destroying any existing instance at the start of the loop;
but you had set the environment to overwrite each new output anyway, eh?),
you will want to save the outputs in a dbf compendium of all the outputs.
That is why you append each iteration to distance.dbf.
>>other question<<
By the time MakeFeatureLayer runs, the search cursor is played out: over and done.
The cursor only builds the list of unique precinct ids, then finishes.
There should likely be a
del rows
just before the
for site in sitesList:
in order to kill the cursor dead.
The loop is through sitesList, which is a list of the values from the Pre field of PollingSite,
and not through a cursor.
Don't think of a cursor as a way to run geoprocessing tools on a single row: it is not.
I assume the values in Pre are the link to the values in PrecinctNa in Voters
That is why the where clauses are set up to reference the same value in the differently named fields in each shp/layer.
What you are (or, I guess, I am) doing is:
> make a list of precinct values common to both shp files (by grabbing it from just one)
> loop through that list to:
>> make where statements appropriate to each shp file
>> delete all intermediate layers and tables
>> make a layer from Voters of the voters in precinct A
>> make a layer of the polling places in precinct A from PollingSite
>> make a (temporary, on-disk) point distance table of the point distances between
... the voter points and their polling place(s)
>> append the results to the final results table.
>> continue to the end of the list of polling places, then stop
This code does leave the final batch of ephemeral layer files and the final on-disk Point_Tbl.dbf behind...
It is not a polished bit of code, just an illustration