for site in sitesList: Votewhere = '"PrecinctNa" = %s' % (site) #loops to grab one precinct at a time Sitewhere = '"Pre" = %s' % (site) #loops to grab voters of one precinct at a time
Votewhere = '"PrecinctNa" = %s' % (site) #loops to grab one precinct at a time Sitewhere = '"Pre" = %s' % (site) #loops to grab voters of one precinct at a time
import arcpy from arcpy import env env.workspace = "C:\work" env.overwriteOutput = True # Local variables: Voters = "Voters.shp" # this is the point file for the voter geocode PollingSite = "Polling.shp" # 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) ## define a feature class sitesList = [] #run a for loop to go to each row in attribute table. for row in rows: #rows is the PollingSite shapefile p_precinct = row.Pre #this is the precinct column for PollingSite if p_precinct not in sitesList: 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: Votewhere = '"PrecinctNa" = %s' % (site) #loops to grab one precinct at a time Sitewhere = '"Pre" = %s' % (site) #loops to grab voters of one precinct at a time ##deletes the layers that will be created again and again on loop if arcpy.Exists("PollPlace_Lyr"): arcpy.Delete_management("PollPlace_Lyr") if arcpy.Exists("Voter_Lyr"): arcpy.Delete_management("Voter_Lyr") if arcpy.Exists("Point_Tbl"): arcpy.Delete_management("Point_Tbl") #make a layer for the voters of one precinct at a time arcpy.MakeFeatureLayer_management(Voters, "Voter_Lyr", Votewhere) #make a layer for the voting site of one precinct at a time arcpy.MakeFeatureLayer_management( PollingSite, "PollPlace_Lyr", Sitewhere) #run point distance analysis for each precinct/voter distance arcpy.PointDistance_analysis("Voter_Lyr", "PollPlace_Lyr", "Point_Tbl") #append point distance results as they add up arcpy.Append_management("Point_Tbl", distance)
Traceback (most recent call last): File "C:\Work\Code.py", line 43, in <module> "Point_Tbl") File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\analysis.py", line 941, in PointDistance raise e ExecuteError: ERROR 999999: Error executing function. Failed to execute (PointDistance).
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) ## build a list of sites with a search cursor sitesList = [] for row in rows: #rows is the PollingSite shapefile p_precinct = row.Pre #this is the precinct column for PollingSite if p_precinct not in sitesList: sitesList.append(p_precinct) for site in sitesList: Votewhere = '"PrecinctNa" = %s' % (site) Sitewhere = '"Pre" = %s' % (site) ## don't depend on env.overwriteOutput if arcpy.Exists("PollPlace_Lyr"): arcpy.Delete_management("PollPlace_Lyr") if arcpy.Exists("Voter_Lyr"): arcpy.Delete_management("Voter_Lyr") if arcpy.Exists("Point_Tbl"): arcpy.Delete_management("Point_Tbl") arcpy.MakeFeatureLayer_management(Voters, "Voter_Lyr", Votewhere) arcpy.MakeFeatureLayer_management( PollingSite, "PollPlace_Lyr", Sitewhere) arcpy.PointDistance_analysis("Voter_Lyr", "PollPlace_Lyr", "Point_Tbl") arcpy.Append_management("Point_Tbl", distance) ## this assumes distance.DBF exists and has the ## correct schema
the indents dont show up in the copy paste, but they are indented as needed. i get no errors on that
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 p_precinct = row.Pre #this is the precinct column for PollingSite v_precinct = rows2.PrecinctNa # this is the precinct column for Voters if p_precinct == v_precinct: PointDistance_analysis(Voters, PollingSite, distance)
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.