So, i am tryinrg to solve this problem!
"You are given a feature class called parcels.shp that contains the following fields: FID, Shape, Landuse, and
Value. You need to write a script that determines the property tax and writes these values to the same feature
class in a new field called Tax."
i am stuck when it comes to adding and updating the Tax field. this is what i have so far. any hint would be very helpful. thanks
self.landuse = landuse
self.value = value
if self.landuse == "SFR":
rate = 0.05
elif self.landuse == "MFR":
rate = 0.04
rate = 0.02
assessment = self.value*rate
arcpy.env.workspace = "C:/Lab8"
fc = "parcels.shp"
arcpy.AddField_management(fc, "Tax", "LONG", "", "", 10)
cursor = arcpy.da.UpdateCursor(fc, ["FID","Landuse","Value"])
for row in cursor:
myparcel = parcelclass.parcel(row,row,row)
mytax = myparcel.assessment()
It would be best if you format your code so we can see the indentation and explain what you mean by being "stuck". Without putting a lot of thought into it (since it seems the objective is for you to figure it out) I would try something along these lines, in terms of writing out the calculated tax value :
cursor = arcpy.da.UpdateCursor(fc, ["FID","Landuse","Value", "Tax"]) for row in cursor: myparcel = parcelclass.parcel(row,row,row) # This doesn't look right mytax = myparcel.assessment() # This call appears to only return the rate, not the assessment cursor.updateRow(row,row,row, mytax)
Hi , so below is the formatted code pic
when i run the code i get the following error.
myparcel = parcelclass.Parcel(row,row,row)
TypeError: __init__() takes 3 positional arguments but 4 were given
You should only pass 2 parameters to the init function - 'self' is sort of implied, which I find confusing coming from a C++ background. Anyway - here is how I would do it which I think is a bit clearer. It didn't look like you were using the FID field so I got rid of it - and I now see how you calculate the assessment. Using a class to calculate the assessment seems like overkill, but you must have a reason to use it .....
cursor = arcpy.da.UpdateCursor(fc, ["Landuse","Value", "Tax"]) for land_use, value, tax in cursor: myparcel = parcelclass.parcel(land_use, value) mytax = myparcel.assessment() cursor.updateRow([land_use, value, mytax])
thank you! but for some reason, I think the code isn;t working for line 3.