1

I have a Point Feature Class with 2 million records with 35 fields. I have another csv file (contain 25 fields) which have around 4000 records to update certain records of the Point Feature Class . Within these 4000 records, only around 70 are matched with the common field which is the Account ID and among these records the fields are needed to be updated. There are more than 20 fields that will be needed to update. I am trying to automate this process of updating the fields of the match records.

Currently, I am trying to use write Python Script to update the fields. I am still very new to Python and have no programming background thus I am having problems with my script.

My workflow is this:

  1. Convert the csv file to Table in gdb
  2. Join (AddJoin) the Table to Point Feature Class.

Then, I am trying to use UpdateCursor which has failed ever since I tried.

If I am using ModelBuilder, I can use Field Calculator tools to change each of the field but I think it will take a long time and it does not seem to be a very nice way of updating the fields.

I am not sure if there is easier way of updating the fields in the Point Feature Class from the given csv files.

  • 2
    You should probably publish a piece of your code where you get an error or the results you think are wrong. Your workflow makes sense; you convert a .csv file into a file gdb table but then you don't need to do a join - you can use the arcpy.da.UpdateCursor while having two objects - your fc and the table. When you publish the code, I could post a piece of code that should work for you. – Alex Tereshenkov Mar 2 '15 at 10:41
  • Hi Alex, thank you for your reply. The reason why i did the join was to filter the records. I am wondering if the update cursor will work like Field calculate tool. My idea was to do the join then filter the out only those records that are joined but instead of using the field calculate the change the fields I am wondering if i can use update cursor. thanks. – user45979 Mar 4 '15 at 9:31
1

First, let it be known there are a number of ways someone could go about accomplishing roughly the same goal in this case. For me personally, especially for someone less experienced with arcpy, it would likely be simplest to do roughly the following workflow

  1. Convert the CSV file to Table in GDB
  2. Join the Table to Point Feature Class
  3. Make Feature Layer (geoprocessing tool, allows for selections to be applied)
  4. Select by attribute against layer to select only those features that need updating (ex: select where JoinTable.OID IS NOT NULL)
  5. Calculate field against the selected layer for each field needing updated.

By first making sure you have a selection applied, it shouldn't take too long to run through 70 or so records. I will admit, yes, it would be quicker and more efficient to use cursors to accomplish this, assuming you are at 10.1 or higher and have access to the arcpy.da cursors. But, for simplicity sake and ease of use, calculate field isn't a terrible option.

  • Thank you, John for your answer. Yes I could have use the field calculator to do change the fields but I have more than 20 fields to change. If I do the join and select layer, can I use arcpy.da cursors? My script will be something like: rows = Point_Feature_Class ##fields = arcpy.ListDatasets ##fieldsinfo = arcpy.FieldInfo () for rows2 in rows: rows2[0]=rows2[jointable.field1] rows2[1]=rows2[jointable.field2] arcpy.UpdateCursor(rows2) – user45979 Mar 4 '15 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.