How do I copy attribute data to an existing shapefile?

9169
13
Jump to solution
12-02-2015 07:26 AM
DianneBoisvert
New Contributor

I have an existing table containing attribute data about crosswalks with no geometry.  I also have a polyline layer for crosswalks that I want have the attribute data attached to.  How do I get the data from the .dbf into the empty crosswalk feature class?  Merge doesn't work b/c they're different data types.  I can't do a join b/c there is no spatial reference yet.  I figured once the data was in the shapefile I could use the "replace geometry" tool to draw in the lines depicting crosswalks but I'm not sure if that will work.  Am I going about this all wrong?
Thanks,

Tags (2)
0 Kudos
13 Replies
DarrenWiens2
MVP Honored Contributor

You've already found the "right" way to do this (digitize the lines, keeping track of a unique ID to join back to the attributes), but here is a spectacularly wrong way to do it.

1.) Make a note of how many records are in your table.

2.) If you table isn't in DBF format, make it so.

3.) Create a new line shapefile (mine is called "bad_idea.shp")

4.) We need to make as many null geometries as there are records in your table. You can do so with the following Python code:

>>> insCursor = arcpy.da.InsertCursor("bad_idea","SHAPE@")
... for i in range(7):# change to the number of null geometries you want to make
...    myArray = arcpy.Array()
...    myPoint = arcpy.Point()
...    myArray.add(myPoint)
...    myLine = arcpy.Polyline(myArray)
...    insCursor.insertRow([myLine])

5.) Close down ArcGIS to release any locks on bad_idea.shp

6.) Delete "bad_idea.dbf" in file explorer

7.) Rename your original table (the one with the attributes you want to keep) to "bad_idea.dbf"

8.) ArcGIS won't open "bad_idea.shp" anymore (I'm not exactly sure why), but QGIS is more liberal with that sort of thing. Bring this diseased shapefile into QGIS and save a copy, say "bad_idea_copy.shp"

9.) Bring "bad_idea_copy.shp" into ArcGIS. It should have your original attribute table associated with null polyline geometries.

10.) Start editing.

11.) Select the feature from the attribute table for which you want to update the existing null geometry to a real geometry

12.) Start editing vertices (editing toolbar)

13.) From the edit vertices toolbar, select Continue Feature Tool

14.) Draw your new feature. This geometry is associated with the selected record in the attribute table.

15.) Repeat.

Have fun. I take no responsibility for any damage this method may cause.

DavidBollinger
New Contributor III

$0.02 fwiw, if you're already in python... and already inserting records into a fc... then why not go one tiny step further and build something valid?  iow, read the source attribute records, for each copy fields and create new fully attributed record into an empty fc, using some "dummy" (but valid) line segment that you can later edit.

0 Kudos
DarrenWiens2
MVP Honored Contributor

Hmmm... Yes, all valid points.

edit: although, any workflow that includes creating null geometries is somewhat debatable as being "valid".

0 Kudos
AlexandraDubovis
New Contributor II

Eliza_J

I didn't see if you reply to Elizabeth Jarvie.

If you have a street segment feature class or shape file it can save you a lot of manual work.