POST
|
ahh I see what you are saying! I decided to use the old style cursor like you suggested using the "da" and I got this error: Traceback (most recent call last): File "C:/Users/ahutche1/Desktop/lol.py", line 34, in <module> part1 = row.getValue(address) AttributeError: 'list' object has no attribute 'getValue' #I will create a cursor to update the FullAddR field
with arcpy.da.UpdateCursor(env+hospitals+'.shp',[field1,address,city,state,zipcode]) as cursor:
#I will use a while loop in order to copy all the information from the
#city,state,address,and zipcode fields into the single FullAddR field.
row = cursor.next()
while row:
#I am setting the variables for the fields I want to take information from
#in order to merge it into the new field I just created.
part1 = row.getValue(address)
part2 = row.getValue(city)
part3 = row.getValue(state)
part4 = row.getValue(zipcode)
# Concatenating field values together ( str(part4) is in case zipcode is a numeric field instead of string)
row.setValue(field1, part1 + " " + part2 + " " + part3 + " " + str(part4))
cursor.updateRow(row)
... View more
08-19-2015
08:48 AM
|
0
|
1
|
1221
|
POST
|
It's a book that my older brother created for me based on some python class he had that allows me to practice different functions and objects. I got the error that said " Traceback (most recent call last): File "C:/Users/ahutche1/Desktop/lol.py", line 34, in <module> part1 = row.getValue(address) AttributeError: 'list' object has no attribute 'getValue' I edited the code you did a little because I got some errors before: #import arcpy module
import arcpy
from arcpy import env
arcpy.env.overwriteOutput = True
# I am setting the work path
env = r'S:\\376\\Summer15-2\\ahutche1\\lab07_data\\SectionB\\'
#I am setting the variable for the hospitals shapefile
hospitals = 'Hospitals'
#I will add a new "FULLAddR" field to the table in the hospitals shapefile
#arcpy.AddField_management(env+hospitals+'.shp','FullAddR', "FLOAT",20)
#I am setting the variable for the new field.
field1 = "FullAddR"
address = "ADDRESS"
city = "CITY"
state = "STATE"
zipcode = "ZIPCODE"
#I will create a cursor to update the FullAddR field
cursor = arcpy.da.UpdateCursor(env+hospitals+'.shp',[field1,address,city,state,zipcode])
#I will use a while loop in order to copy all the information from the
#city,state,address,and zipcode fields into the single FullAddR field.
row = cursor.next()
while row:
#I am setting the variables for the fields I want to take information from
#in order to merge it into the new field I just created.
part1 = row.getValue(address)
part2 = row.getValue(city)
part3 = row.getValue(state)
part4 = row.getValue(zipcode)
# Concatenating field values together ( str(part4) is in case zipcode is a numeric field instead of string)
row.setValue(field1, part1 + " " + part2 + " " + part3 + " " + str(part4))
cursor.updateRow(row)
row = cursor.next()
... View more
08-19-2015
08:04 AM
|
0
|
4
|
1221
|
POST
|
I'm working through a python book and doing different exercises. I already know how to use calculate field but its about learning different things. Is there a way to accomplish this with a while loop?
... View more
08-19-2015
07:14 AM
|
0
|
6
|
1221
|
POST
|
I have a shapefile for hospitals and in the attribute table I added a new field. My goal is to use a while loop and create a search cursor that will merge the data in the address,city,state, and zipcode fields into the new FullAddR field I successfully added. My addfield management code added the field successfully and its blank. But, I think there is something wrong with my update cursor info in the while loop. I'm not sure how to use the row.setValue to merge all the info from the different fields into one if that's even the right direction i should be going in. #import arcpy module
import arcpy
from arcpy import env
arcpy.env.overwriteOutput = True
# I am setting the work path
env = r'S:\\376\\Summer15-2\\ahutche1\\lab07_data\\SectionB\\'
#I am setting the variable for the hospitals shapefile
hospitals = 'Hospitals'
#I will add a new "FULLAddR" field to the table in the hospitals shapefile
arcpy.AddField_management(env+hospitals+'.shp','FullAddR', "FLOAT",20)
#I am setting the variable for the new field.
field1 = "FullAddR"
#I am setting the variables for the fields I want to take information from
#in order to merge it into the new field I just created.
address = "ADDRESS"
city = "CITY"
state = "STATE"
zipcode = "ZIPCODE"
#I will create a cursor to update the FullAddR field
cursor1 = arcpy.UpdateCursor(env+hospitals+'.shp') #I swill set up the update cursor
row = cursor1.next()
#I will use a while loop in order to copy all the information from the
#city,state,address,and zipcode fields into the single FullAddR field.
while row:
row.setValue(field1,row.getValue(address,city,state,zipcode))
cursor.updateRow(row)
row = cursor1.next()
... View more
08-19-2015
06:23 AM
|
0
|
8
|
5931
|
POST
|
ahh thanks since this thread is too similar to the other one I'll delete this one.
... View more
08-18-2015
07:35 PM
|
0
|
0
|
1112
|
POST
|
actually I ended up getting the answer on my own and my small script change was a lot faster and required less code. Thanks though I forgot to check the old post. I figured out the python scripting part but I was using get count management in the oddest way! I'm new this part of esri. I never knew it existed except for google. Now I've printed out the schools, but I'd rather have the total no. of records print out once.
... View more
08-18-2015
07:18 PM
|
0
|
0
|
1112
|
POST
|
I added the code you suggested and for some reason it printed out each high school like this *snippet* JOHN B CONNALLY There are 26 highschools. OPPORTUNITY CENTER There are 27 highschools. MANOR NEW TECH There are 28 highschools. OPPORTUNITY CENTER HS & MS There are 29 highschools. ############## Is there a way to just have it print out 1 sentence saying there are 29 high schools?
... View more
08-18-2015
07:15 PM
|
0
|
2
|
1112
|
POST
|
I have a schools shapefile with different facilities. I created a search cursor to only select records where the field "name" is equal to high school. Then I was to use a for loop to print out all the names of the different high schools. I managed to complete this successfully;however, I must also print out the no. of high schools that I just queried in the search cursor. So for instance I managed to use the search cursor to print out 35 high schools (or atleast their names). How would I use the search cursor to print out the no. of records or no. of highschools that I have just printed out. I can't use the selectlayer only search cursor. Here's my code below. #import arcpy module import arcpy from arcpy import env arcpy.env.overwriteOutput = True # I am setting the work path env = 'S:\\376\\Summer15-2\\ahutche1\\lab07_data\\SectionB\\' #I will set the variable for the schools shapefile schools = 'Schools' #create search cursor to loop thru schools. use where clause to return schools #that are high schools. Use loops #print out all the highschool names #print total no. of high school records sr = arcpy.SpatialReference(4326) #I will create a search cursor for the schools shapefile field = "NAME" exp1 = '"FACILITY" = \'HIGH SCHOOL\'' cursor = arcpy.SearchCursor(env+schools+'.shp',exp1) #I have now printed out all of the names of the facilities that are high schools for row in cursor: print(row.getValue(field)) #this code above was successful #I am attempting to print out the number of facilities that are highschools but this is wrong because it prints out the total no. of records and not the ones I queried above. #while cursor: #count = arcpy.GetCount_management(env+schools+'.shp') #result = int(count.getOutput(0)) #print result #break
... View more
08-18-2015
06:18 PM
|
0
|
6
|
4028
|
POST
|
I need to create a search cursor to print out the values in an attribute table for a school shapefile. I need to print out all the values that correspond to HIGH SCHOOL in the field FACILITY for the School shapefile. For some reason the search cursor won't work when I try to apply the sql expression but works without it. I don't want to print out all the values in that field just specific ones. Is there something wrong with my sql statement? #import arcpy module import arcpy from arcpy import env arcpy.env.overwriteOutput = True # I am setting the work path env = 'S:\\376\\Summer15-2\\ahutche1\\lab07_data\\SectionB\\' #I will set the variable for the schools shapefile schools = 'Schools' #create search cursor to loop thru schools. use where clause to return schools #that are high schools. Use loops #print out all the highschool names #print total no. of high school records sr = arcpy.SpatialReference(4326) #I will create a search cursor for the schools shapefile field = "FACILITY" exp1 = '"FACILITY" = "HIGH SCHOOL"' cursor = arcpy.SearchCursor(env+schools+'.shp',exp1) for row in cursor: print(row.getValue(field))
... View more
08-14-2015
08:11 PM
|
0
|
4
|
4220
|
POST
|
I tried this code and it ran in arcpy but in arcmap no triangles showed up I'm guessing thats because in line 48 you put arcpy.Point(*coords) which has no particular coordinate? Did you use a random set of coordinates or did the triangles show up on your map?
... View more
08-13-2015
09:54 AM
|
0
|
1
|
1748
|
POST
|
I came up with this code although it is buggy. I think that the triangles are supposed to be the same size. The triangles are just supposed to be random using the import random module I wasn't given specifics about the size. She just said she needs 75 of them. Based on the example problem I configured this code. I'm not sure how to configure the loop so I can set the points/coordinates for a triangle using an array import arcpy import random env = the path lol feat = 'triangles.shp' polygon_list = [] #I will create random triangles across the world shapefile using the random module for y in range (90,0,-10): for x in range(-180,180,10): cornersArray = arcpy.Array() p1 = arcpy.Point() p1.X = x p1.Y = y cornersArray.add(p1) p2 = arcpy.Point() p2.X = x + 10 p2.Y = y cornersArray.add(p2) p3 = arcpy.Point() p3.X=x+10 p3.Y = y-10 cornersArray.add(p3) poly = arcpy.Polygon(cornersArray) polygon_list.append(poly) #I will copy the features in my list to the triangle shapefile arcpy.CopyFeatures_management(polygon_list,feat) #I will define the projection for the triangles shapefile arcpy.DefineProjection_management(feat,arcpy.SpatialReference(4326)) print 'Finished created the triangles'
... View more
08-13-2015
09:12 AM
|
0
|
4
|
1748
|
POST
|
I have a shapefile of the world and I am trying to create 75 random triangles over this shapefile using the random package. I'm just not sure how to do this and use a for loop to create the lat and.
... View more
08-13-2015
04:11 AM
|
0
|
11
|
4907
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|