[GIS] How to copy attribute table values from one feature class to another

arcgis-desktoparcpy

I am looking for a way to copy attribute values from one attribute table to another. I am mainly looking to do this using python, so would prefer a way to do this with a tool or a a stand-alone python script.

A little background about my problem. I have a collection of polylines situated within a collection of polygons (a watercourse network). The crux of what I want to do is identify, spatially, which polygons hold which polylines and record this in the relevant field. The script below shows how far I have got. I have used python to select the relevant polygon and highlight the polylines that are situated inside it (selected features). However, I have so far been unable to copy these selected features into a particular field of another feature class. I have tried using both the Append (got 'warning' 000597) and Join tools but neither have worked.

import arcpy

reachesBoundaries = "C:\Users\maureen\Documents\ArcGIS\EDRN\Catchments\MainRiversCatchmentsPolygonMarch2013.shp"
edrnLink = "C:\Users\maureen\Documents\ArcGIS\EDRN\EDRN_LINK.shp"
reachField = "CATCHNAME"
reachName = "Aire - Lady Beck Catchment"

arcpy.MakeFeatureLayer_management(edrnLink, "edrnLayers9")
arcpy.MakeFeatureLayer_management(reachesBoundaries, "boundaryLayer8", '"' + str(reachField) + '" =' + "'" + str(reachName) + "'")

arcpy.SelectLayerByLocation_management("edrnLayer9", "WITHIN", "boundaryLayers8")

The script works up the point mentioned above, if anyone has any ideas on how to progress it, please let me know.

Best Answer

This is typically something that you can do with a spatial join. However, you should be aware that you cannot have several lines copied in a single feature : one feature can only store one line. With the spatial join, you can use "one-to-many" in order to duplicate your records when there are several relationships.

Related Question