POST
|
thanks, i will work on that. one other thing i am wondering about is this part of the code 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 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
... View more
04-21-2014
09:33 PM
|
0
|
0
|
135
|
POST
|
thank you for the explanations. I def understand it better now. I spent last few days going through some tutorials and lessons I found online to better understand python and GIS coding. seems like this project of mine is much more complex than most tutorials. i appreciate your help. so I am moving the table that should be outputted to a geodatabase. so i haven't added .dbf, i did at one point but it still generated the same error 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. let me know if it looks like i am mis-understanding any function. you said there is still some polishing. not sure where things need to be changed/added. it looks done, but obviously is not. (my moderate experience is showing here). what are the final steps i need to complete. thank you so much for your help already. 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)
... View more
04-16-2014
10:44 AM
|
0
|
0
|
135
|
POST
|
thank you for the info boost! I am still getting used to python so this definitely helped. I do have a few quick questions. i am getting an error (message below) regarding the "Point_Tbl" part of the code. And indeed I am little confused there as well. Is the Point_tbl supposed to be the eventual output of distances, (called distance.dbf). does another MakeFeatureLayer code need to be written to create the Point_tbl layer? 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. However, a searchcursor is never established for that shapefile. How does the code know that 'PrecinctNa' is referencing the field in Voters and not a field in PollingPlace? Sorry if this is an obvious answer, just a little confused. again thank you for the help, I feel like I am much closer 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).
... View more
04-09-2014
10:14 AM
|
0
|
0
|
432
|
POST
|
thanks. the error I keep getting at this point is AttributeError: 'Cursor' object has no attribute 'PrecinctNa' I cannot understand why I get that vote the second cursor object, but not the first
... View more
04-08-2014
09:36 PM
|
0
|
0
|
432
|
POST
|
the indents dont show up in the copy paste, but they are indented as needed. i get no errors on that
... View more
04-03-2014
06:41 PM
|
0
|
0
|
432
|
POST
|
thanks! I am trying to write the loop but having a few problems. Have had trouble getting it right before. my code is below, if anyone can give any guidance it would be appreciated it 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)
... View more
04-03-2014
06:40 PM
|
0
|
0
|
432
|
POST
|
Simple geographic distance is good for me. Just not sure how to proceed
... View more
04-02-2014
10:50 AM
|
0
|
0
|
432
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|