<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python coding for point distance in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546074#M42578</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Simple geographic distance is good for me. Just not sure how to proceed&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 02 Apr 2014 17:50:08 GMT</pubDate>
    <dc:creator>MattI</dc:creator>
    <dc:date>2014-04-02T17:50:08Z</dc:date>
    <item>
      <title>Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546072#M42576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am a bit stuck and hoping someone can help.&amp;nbsp;&amp;nbsp; I have some python experience, but am getting stuck on the best rout forward for a specific function I am trying to run.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have two point shapefiles.&amp;nbsp; The first is a list of polling locations for the county I live, with the precinct number that corresponds to that location.&amp;nbsp; the second shapefile is a geocode of all the voters in that county.&amp;nbsp; Each voter has their precinct number in the attribute table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I am hoping to do is run a code that will calculate the distance each voter is from their designated polling spot.&amp;nbsp; I am assuming Ishould use point distance and a combination of an IF or/and FOR loop to run the function when the precinct numbers from the two distinct shapefiles match.&amp;nbsp; However, I am unsure how to move forward in writing that code.&amp;nbsp; If anyone has any suggestions, or a better method, the help would be appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matthew&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Mar 2014 17:18:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546072#M42576</guid>
      <dc:creator>MatthewIsbell</dc:creator>
      <dc:date>2014-03-31T17:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546073#M42577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you looking for a simple geographic distance or using a transportation network of some kind?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Mar 2014 21:30:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546073#M42577</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2014-03-31T21:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546074#M42578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Simple geographic distance is good for me. Just not sure how to proceed&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Apr 2014 17:50:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546074#M42578</guid>
      <dc:creator>MattI</dc:creator>
      <dc:date>2014-04-02T17:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546075#M42579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;in a loop&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;create a feature layer of each polling place and &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;another of the voters associated with that place.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Run GenerateNearTable_analysis with the ALL option&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will give you a table of the distances of each voter to his polling place.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PointDistance_analysis might also do the trick for you&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Of course, you need an Advanced license to run either of these tools.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Apr 2014 18:21:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546075#M42579</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2014-04-02T18:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546076#M42580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;thanks!&amp;nbsp; I am trying to write the loop but having a few problems.&amp;nbsp; Have had trouble getting it right before.&amp;nbsp; my code is below, if anyone can give any guidance it would be appreciated it&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;env.workspace = "C:\work"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env.overwriteOutput = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Local variables:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Voters = "Voters.shp"&amp;nbsp; # these are the voters, point file&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PollingSite = "Polling.shp"&amp;nbsp; # this is the point file of the voter sites&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;distance = "distance.DBF" # this will be the output of the distance table&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#need to define rows, updatecursor seems to be required&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;rows = arcpy.UpdateCursor(PollingSite)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;rows2 = arcpy.UpdateCursor(Voters)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#run a for loop to go to each row in attribute table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for row in rows:&amp;nbsp; #rows is the PollingSite shapefile&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; p_precinct = row.Pre #this is the precinct column for PollingSite&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; v_precinct = rows2.PrecinctNa # this is the precinct column for Voters&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if p_precinct == v_precinct:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PointDistance_analysis(Voters, PollingSite, distance)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Apr 2014 01:40:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546076#M42580</guid>
      <dc:creator>MattI</dc:creator>
      <dc:date>2014-04-04T01:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546077#M42581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;the indents dont show up in the copy paste, but they are indented as needed.&amp;nbsp; i get no errors on that&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Apr 2014 01:41:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546077#M42581</guid>
      <dc:creator>MattI</dc:creator>
      <dc:date>2014-04-04T01:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546078#M42582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;the indents dont show up in the copy paste, but they are indented as needed.&amp;nbsp; i get no errors on that&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Use the "#" Code Wrap function on the toolbar when you make a post&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import arcpy
from arcpy import env
 
env.workspace = "C:\work"
env.overwriteOutput = True
 

# Local variables
Voters = "Voters.shp" # these are the voters, point file
PollingSite = "Polling.shp" # this is the point file of the voter sites
distance = "distance.DBF" # this will be the output of the distance table
 

#need to define rows, updatecursor seems to be required
rows = arcpy.UpdateCursor(PollingSite)
rows2 = arcpy.UpdateCursor(Voters)
 

#run a for loop to go to each row in attribute table.
for row in rows: #rows is the PollingSite shapefile
&amp;nbsp;&amp;nbsp; p_precinct = row.Pre #this is the precinct column for PollingSite
&amp;nbsp;&amp;nbsp; v_precinct = rows2.PrecinctNa # this is the precinct column for Voters
&amp;nbsp;&amp;nbsp; if p_precinct == v_precinct:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PointDistance_analysis(Voters, PollingSite, distance) 

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:38:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546078#M42582</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T23:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546079#M42583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;thanks.&amp;nbsp; the error I keep getting at this point is &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;AttributeError: 'Cursor' object has no attribute 'PrecinctNa'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I cannot understand why I get that vote the second cursor object, but not the first&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Apr 2014 04:36:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546079#M42583</guid>
      <dc:creator>MattI</dc:creator>
      <dc:date>2014-04-09T04:36:55Z</dc:date>
    </item>
    <item>
      <title>Re: Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546080#M42584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Well, there is no PrecinctNa in row2&amp;nbsp; because&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;rows2 is a cursor, and contains the table, not an individual row.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You don't really want to use cursors to do this&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and you need layers to drive PointDistance&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env

env.workspace = "C:\work"
env.overwriteOutput = True

# Local variables:
Voters = "Voters.shp" # these are the voters, point file
PollingSite = "Polling.shp" # this is the point file of the voter sites
distance = "distance.DBF" # this will be the output of the distance table

rows = arcpy.SearchCursor(PollingSite)

##&amp;nbsp; build a list of sites with a search cursor
sitesList = []
for row in rows: #rows is the PollingSite shapefile
&amp;nbsp;&amp;nbsp;&amp;nbsp; p_precinct = row.Pre #this is the precinct column for PollingSite

&amp;nbsp;&amp;nbsp;&amp;nbsp; if p_precinct not in sitesList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sitesList.append(p_precinct)

for site in sitesList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Votewhere = '"PrecinctNa" = %s' % (site)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Sitewhere = '"Pre" = %s' % (site)

&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; don't depend on env.overwriteOutput
&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists("PollPlace_Lyr"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management("PollPlace_Lyr")
&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists("Voter_Lyr"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management("Voter_Lyr")
&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists("Point_Tbl"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management("Point_Tbl")

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(Voters, "Voter_Lyr", Votewhere)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PollingSite, "PollPlace_Lyr", Sitewhere)

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.PointDistance_analysis("Voter_Lyr",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "PollPlace_Lyr",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Point_Tbl")

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Append_management("Point_Tbl", distance)
&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp; this assumes distance.DBF exists and has the
&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp; correct schema
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;untested: for illustration only: no warranties expressed or implied&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:38:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546080#M42584</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2021-12-11T23:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546081#M42585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;thank you for the info boost!&amp;nbsp; I am still getting used to python so this definitely helped.&amp;nbsp; I do have a few quick questions.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;i am getting an error (message below) regarding the "Point_Tbl" part of the code.&amp;nbsp; And indeed I am little confused there as well.&amp;nbsp; Is the Point_tbl supposed to be the eventual output of distances, (called distance.dbf).&amp;nbsp; does another MakeFeatureLayer code need to be written to create the Point_tbl layer?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;one other question, further up in the code, in the for site in siteList loop, the Votewhere = PrecinctNa is referencing the field from the Voters shapefile.&amp;nbsp; However, a searchcursor is never established for that shapefile.&amp;nbsp; How does the code know that 'PrecinctNa' is referencing the field in Voters and not a field in PollingPlace?&amp;nbsp; Sorry if this is an obvious answer, just a little confused.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;again thank you for the help, I feel like I am much closer&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Traceback (most recent call last):
&amp;nbsp; File "C:\Work\Code.py", line 43, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Point_Tbl")
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\analysis.py", line 941, in PointDistance
&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e
ExecuteError: ERROR 999999: Error executing function.
Failed to execute (PointDistance).&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:38:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546081#M42585</guid>
      <dc:creator>MattI</dc:creator>
      <dc:date>2021-12-11T23:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546082#M42586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;&amp;gt;&amp;gt; getting an error (message below) regarding the "Point_Tbl" part of the code. &amp;lt;&amp;lt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; Point_tbl should likely be named "Point_tbl.dbf" because it is is to be placed in a directory rather than a geodatabase.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If the destination was a gdb, arc would know that name was for a table..&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, Point_tbl is the direct output from PointDistance, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;but since you are running PointDistance multiple times in a loop,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(and destroying any existing instance at the start of the loop; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;but you had set the environment to overwrite each new output anyway, eh?),&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;you will want to save the outputs in a dbf compendium of all the outputs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That is why you append each iteration to distance.dbf.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;other question&amp;lt;&amp;lt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;By the time MakeFeatureLayer runs, the search cursor is played out: over and done.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The cursor only builds the list of unique precinct ids, then finishes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There should likely be a&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del rows&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;just before the &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for site in sitesList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;in order to kill the cursor dead.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The loop is through sitesList, which is a list of the values from the Pre field of PollingSite,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and not through a cursor. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Don't think of a cursor as a way to run geoprocessing tools on a single row: it is not.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I assume the values in Pre are the link to the values in PrecinctNa in Voters&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That is why the where clauses are set up to reference the same value in the differently named fields in each shp/layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What you are (or, I guess, I am) doing is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt; make a list of precinct values common to both shp files (by grabbing it from just one)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt; loop through that list to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;nbsp; make where statements appropriate to each shp file&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;nbsp; delete all intermediate layers and tables&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;nbsp; make a layer from Voters of the voters in precinct A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;nbsp; make a layer of the polling places in precinct A from PollingSite&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;nbsp; make a (temporary, on-disk) point distance table of the point distances between &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&amp;nbsp; the voter points and their polling place(s)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;nbsp; append the results to the final results table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;nbsp; continue to the end of the list of polling places, then stop&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This code does leave the final batch of ephemeral layer files and the final on-disk Point_Tbl.dbf behind...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It is not a polished bit of code, just an illustration&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2014 10:54:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546082#M42586</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2014-04-10T10:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546083#M42587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;thank you for the explanations.&amp;nbsp; I def understand it better now.&amp;nbsp; I spent last few days going through some tutorials and lessons I found online to better understand python and GIS coding.&amp;nbsp; seems like this project of mine is much more complex than most tutorials.&amp;nbsp; i appreciate your help.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so I am moving the table that should be outputted to a geodatabase.&amp;nbsp; so i haven't added .dbf,&amp;nbsp;&amp;nbsp; i did at one point but it still generated the same error&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;this is my code as it is now. which isn't much changed form before, but has comments next to each function where I explain what is going on.&amp;nbsp; let me know if it looks like i am mis-understanding any function.&amp;nbsp; you said there is still some polishing.&amp;nbsp; not sure where things need to be changed/added.&amp;nbsp; it looks done, but obviously is not.&amp;nbsp; (my moderate experience is showing here).&amp;nbsp; what are the final steps i need to complete.&amp;nbsp;&amp;nbsp; thank you so much for your help already.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env

env.workspace = "C:\work"
env.overwriteOutput = True

# Local variables:
Voters = "Voters.shp"&amp;nbsp; # this is the point file for the voter geocode
PollingSite = "Polling.shp"&amp;nbsp; # this is the point file of the voter sites
distance = "List.gdb\\distance" # output of distance, must be geodatabase

#need to define rows, use SearchCursor
rows = arcpy.SearchCursor(PollingSite)

##&amp;nbsp; define a feature class
sitesList = []

#run a for loop to go to each row in attribute table.
for row in rows:&amp;nbsp; #rows is the PollingSite shapefile
&amp;nbsp;&amp;nbsp;&amp;nbsp; p_precinct = row.Pre #this is the precinct column for PollingSite

&amp;nbsp;&amp;nbsp;&amp;nbsp; if p_precinct not in sitesList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sitesList.append(p_precinct) #adds p_precinct to sitesList, does this for each precinct row

del row #ends the searchcursor loop

for site in sitesList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Votewhere = '"PrecinctNa" = %s' % (site) #loops to grab one precinct at a time
&amp;nbsp;&amp;nbsp;&amp;nbsp; Sitewhere = '"Pre" = %s' % (site) #loops to grab voters of one precinct at a time

&amp;nbsp;&amp;nbsp;&amp;nbsp; ##deletes the layers that will be created again and again on loop
&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists("PollPlace_Lyr"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management("PollPlace_Lyr")
&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists("Voter_Lyr"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management("Voter_Lyr")
&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists("Point_Tbl"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management("Point_Tbl")

&amp;nbsp;&amp;nbsp;&amp;nbsp; #make a layer for the voters of one precinct at a time
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(Voters, "Voter_Lyr", Votewhere)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #make a layer for the voting site of one precinct at a time
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PollingSite, "PollPlace_Lyr", Sitewhere)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #run point distance analysis for each precinct/voter distance
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.PointDistance_analysis("Voter_Lyr",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "PollPlace_Lyr",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Point_Tbl")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #append point distance results as they add up
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Append_management("Point_Tbl", distance)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:38:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546083#M42587</guid>
      <dc:creator>MattI</dc:creator>
      <dc:date>2021-12-11T23:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546084#M42588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your Point_Tbl is still just a string ("Point_Tbl"); it needs to be a path to a table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You should make a variable:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Point_Tbl = "List.gdb\\Point_Tbl"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and then, after that, refer to Point_Tbl instead of "Point_Tbl".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Similarly, I would make the layers variables too:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PollPlace_Lyr = "PollPlace_Lyr"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Voter_Lyr = "Voter_Lyr"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The tool output has to be a real table, with a path.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The layers just float in memory, so thay can get by with just a string name,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But it is just easier and clearer to set all the explicit names to variables.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As I mentioned before, you may want to delete at least the last Point_Tbl at the end of the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Otherwise it will be left behind; the temp layers will vaporize with the ending arcpy session.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Apr 2014 18:13:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546084#M42588</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2014-04-17T18:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546085#M42589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;thanks, i will work on that.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;one other thing i am wondering about is this part of the code&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Votewhere = '"PrecinctNa" = %s' % (site) #loops to grab one precinct at a time
&amp;nbsp;&amp;nbsp;&amp;nbsp; Sitewhere = '"Pre" = %s' % (site) #loops to grab voters of one precinct at a time&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;could you explain how it is looping and grabbing one precinct at a time, i get the concept, but am unfamiliary with the %s' % stuff, just want to be sure i understand the logic better for future uses&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:38:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546085#M42589</guid>
      <dc:creator>MattI</dc:creator>
      <dc:date>2021-12-11T23:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: Python coding for point distance</title>
      <link>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546086#M42590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The&amp;nbsp;&amp;nbsp; "%s " % (var)&amp;nbsp;&amp;nbsp;&amp;nbsp; business is python string formatting.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The %s is a place holder for a string (there are other codes too, but %s is the standby)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the % after the string tells python to do the format substitution&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and the strings, numbers or variables in parentheses after the % is the list of values to insert.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You have to have the same number of openings (the %s flags) and values in the list or python gets peeved.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are other ways to insert variables and do string formatting in python,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;but I generally use this as it seems less confusing than some of the others&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and it is a whole lot neater than using lots of pluses and quoted spaces and whatnot...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It loops becasue it is in a loop:&lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for site in sitesList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Votewhere = '"PrecinctNa" = %s' % (site) #loops to grab one precinct at a time
&amp;nbsp;&amp;nbsp;&amp;nbsp; Sitewhere = '"Pre" = %s' % (site) #loops to grab voters of one precinct at a time
&lt;/PRE&gt;&lt;SPAN&gt;each time the loop goes round, site has a different value&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:38:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-coding-for-point-distance/m-p/546086#M42590</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2021-12-11T23:38:29Z</dc:date>
    </item>
  </channel>
</rss>

