Script to take attributes from joined field and move into another

2633
9
10-15-2015 01:48 PM
GeorgePapamihalakis
New Contributor III

I am trying to figure out how to take certain attributes from a joined field and paste them into another field in the same layer. The joined field names never change so it something I would like to automate in the future but first I want to try to figure out the code. I am unsure of what commands to use, I have been looking through the ArcGIS help but I cant seem to find anything that will help me. Can anyone help?

0 Kudos
9 Replies
DanPatterson_Retired
MVP Esteemed Contributor

like calculate field ? Calculate Field—Help | ArcGIS for Desktop

DarrenWiens2
MVP Honored Contributor
how to take certain attributes from a joined field

Just curious about this phrasing. Do you mean "how to take certain values from a joined field", or "how to copy entire fields from a joined feature class"? If values, you can do so by first selecting those values and running the field calculator. If entire fields, then as Dan says, just use the field calculator.

GeorgePapamihalakis
New Contributor III

Its to copy the entire contents of one field and copy to another. For example,  One field is called Block1 and the joined field is called BCK1. I want to copy the contents of BCK1 to Block1. I have a bunch of fields this way and want to write the code once so every time I need to do it, I can just run the script and let it be till its done.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

If there is a one-to-one relationship between the rows, could you just not complete the join, export the layer to a new one making the joins permanent? then keep/hide/delete the old fields as desired. 

GeorgePapamihalakis
New Contributor III

I could but there is about 30 fields that I would have to do that to every time. I know its not too hard, but trying to save time where I can.

0 Kudos
RebeccaStrauch__GISP
MVP Esteemed Contributor

George, I'm not sure if I follow exactly what you are trying to do, as far as repeating this process.  Are the input tables and/or the fields changing? Or are you just adding new records that require this step to be repeated on the same layer?  Answer to those question will help with figuring out what parameters you would need in a script.

But one method that could be written into the script would require a common field between the layerfile and the table, and then you can use the Join Field command, copying only those fields you need....Calculate Field....and then Drop Field (to get rid of the temporary added field).  There are other ways to do this, like creating a Join, but the Join Field will actually append the selected field so you can stop and do other manual selections or review if you want too.  You can append one, multiple, or all fields, from the join table....that is a selectible option

The commands below are the three I mention above.  I'm joining on a common field (uniqid) and only appending the BLK1 field from my join table.

# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script
# The following inputs are layers or table views: "testPoints", "ptIntersect"
arcpy.JoinField_management(in_data="testPoints",in_field="uniqid",join_table="ptIntersect",join_field="uniqid",fields="BLK1")


# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script
# The following inputs are layers or table views: "testPoints"
arcpy.CalculateField_management(in_table="testPoints",field="BLOCK",expression="!BLK1!",expression_type="PYTHON_9.3",code_block="#")

# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script
# The following inputs are layers or table views: "testPoints"
arcpy.DeleteField_management(in_table="testPoints",drop_field="BLK1")
GeorgePapamihalakis
New Contributor III

I have a common field that I am joining currently. The input fields that have the new data always have the same field names, but the data changes.

0 Kudos
WesMiller
Regular Contributor III

If the fields and tables are constant. You could do this easily with model builder.What is ModelBuilder?—ArcGIS Pro | ArcGIS for Desktop Once completed you could then export as a python script and run the script as needed or schedule as a task to run at a given time.

LancasterGIS
New Contributor III

I realize this is a very old thread, but I am looking to do this very thing - take a layer and a table - join the table to the layer - the table has updated information that needs updated in the layer. The field names are the same in the table and the layer. What would be great is if the join command had an option like - "overide field values", then choose which to use as the new value - the layer or the table. Just wondering if you ever came up with a solution besides - join - calculate field - for all 30 or whatever fields you needed. This would not really be a join but more of a batch update field values tool. 

0 Kudos