How to add attribute data to polygons from a shapefile?

4126
7
Jump to solution
03-28-2022 01:59 PM
JamesBrisbane
New Contributor

Hello there,

I'm a brand new user of ArcGIS pro and I have a map with grid squares from a shapefile. 

I also have a separate file of ship density data, with 1 numeric value for each grid square, and I am trying to show the size of this ship density number for each square on the map, using shading. 

I don't know how to tell the software what the ship density number is for each square, so that it can display a corresponding colour on the map.  That is my problem.

I can display an attribute table for the grid squares, with 1 record per square, but the object ID column (OID_) of the table  is filled with only zeros in all the rows.  Do I need to have an object ID somehow?  There is a column called "PageName" which has a label for each square (square A1, A2, B1, B2, etc) and that is how I know which square each record is for. 

I also have those same labels for the squares in my file of ship density data.  In my data file of ship density values for each square, there must be some fields that I have to use to tell ArcGIS which square each record refers to.  Does anyone know what those should be?

In general, does anyone know what steps I should take to add the ship density data to the attributes of the squares on the map, so I can display it in colours?

Thanks,

Jim

 

 

 

0 Kudos
1 Solution

Accepted Solutions
KimGarbade
Occasional Contributor III

Thank you.  The FID is the unique ID of your shapefile (the file you received was indeed a shapefile, it has a single name (I.E. shapefile) but is really made up of multiple files that make up the whole).

First you'll have to right click the shapefile again and select "Joins and Relates" and then "Remove All Joins".

Then I would make a copy of the shapefile (just in case) by right clicking and choosing "Data" > "Export Features" 

KimGarbade_0-1648660856904.png

 

I would export the features to the default database created with your ArcGIS Pro project (It will be in the Catalog Pane; under databases and will have the same name as your project).  Make sure you don't have any selected features or you will only get those in the exported feature class.

This will export your grid shapefile to a feature class in that database.  If it doesn't automatically get added to your map add it and remove the shapefile.

Then I would similarly right click your .csv file in your Table of Contents and select "Data" > "Export Table" into the same file geodatabse (the default one).

Then I would add that to the map.  Right click the newly created Grid layer (now coming from your file geodatabase) and select "Open Attribute Table".  Find the OID in the table that opens right click it and delete it.

Now try your join again using these two sources both contained in the same geodatabase.

If that works you can export the features from the joined grid feature class to a new GridWithDensity feature class and Density will be written to that feature class without requiring a join the next time.

The only thing that worries me is that Domain error message... but hopefully that goes away.

View solution in original post

7 Replies
KimGarbade
Occasional Contributor III

If you have a column that contains the GridID in both tables (I.E A1, A2, etc) you can do one of either two things. 

1) right click the name of the polygon grid layer in your table of contents.  Click "Joins and Relates" and click "Add Join".  This will open a dialog that will allow you to see the attributes of the Ship Density layer or table as if they were attributes of the Grid Square.

KimGarbade_0-1648521305239.png

When you click on Add Join this dialog will open with the input table already populated. For input join field pick the field in your polygon layer that contains the GridID.  For "Join Table" pick the density table and for "Join Table Field" pick the attribute that contains your GridID in that table.

KimGarbade_1-1648521504765.png

The next time you open the table for the grid polygons you will see a column containing your ship density counts. You can symbolize on this.

2) you can add a column to your grid polygons called "ShipDensity".  The perform the join as described above. Once the join is complete you can open the attribute table of the grid polygon shapefile and right click the column header for the new row.  Select "Calculate field" and use the dialog that open to copy the ship density data into the grid polygons attribute table.  You can then remove the join (by right clicking the poly layer and selecting remove all joins) and the ship density data will be in your polygon table.

0 Kudos
JamesBrisbane
New Contributor

I had some work to do to prepare the data, before I could try the join.  Then I tried the option 1), and in the add join dialog, I clicked the "Validate Join" button, and I got this:

Checking for OIDs...
Only a one-to-one join can be done because a unique object Id does not exist.
WARNING 003253: No join was possible

Then when I clicked the ok button I got this:

ERROR 160090: A persisted domain record with the specified name does not exist.

A column named "density" was added to the grid_25km2 table, which is what I wanted, but all the cell values are null.  The real density data is in the table I was joining to (a csv text file).  Maybe this density column filled with nulls is stopping the join from working now?  

I specified the input join field as PageName and PageName is a column of grid_25km2 with values that match the cellid column of the density data table, and I specified the join table field as cellid.  When I look here: https://pro.arcgis.com/en/pro-app/latest/tool-reference/tool-errors-and-warnings/160001-170000/tool-...

It says the solution for that error is to specify an existing domain.  Do you know what that means?

Thanks for any help.

0 Kudos
KimGarbade
Occasional Contributor III

Are both files Shapefiles? Feature classes? One Shapefile and one database table?  Can you let me know the combo?  

Also, if you look at the "fields" for each table (right click in table of contents > click Design > then click "Fields") is there a Domain populated in any of your fields?

KimGarbade_0-1648655939123.png

One last ask.  Can you share an image of your blank OID's in your shapefile table?  Do you have an other ID field... maybe FID or ObjectID?

 

0 Kudos
JamesBrisbane
New Contributor

I was given a zip file, that people were calling a shapefile, and I unzipped it to get a folder with many different file types in it.  They weren't text files, just binary of some kind.  One of them was a .shp file.  The grid came from that data.   It has FID values that go 0,1,2,3, and so on., but the oid values are all zero.  The data looks like this in arcgis:

JamesBrisbane_2-1648658808858.png

So FID, Shape, PageName, shape_leng, shape_area have data, but oid is all zeros and cellid and density are null.  The last 2 columns of nulls (cellid and density) were added during my failed join to the csv text data.

So the density data came from a csv text file that I created.  It has only the 2 columns cellid and density, where cellid has text that matches PageName in the shapefile (for the join), and density is a numeric value.

Here is what the table design for the grid looks like

JamesBrisbane_0-1648658503141.png

And here is what the table design for the density data looks like:

JamesBrisbane_1-1648658557497.png

  

 

0 Kudos
KimGarbade
Occasional Contributor III

Thank you.  The FID is the unique ID of your shapefile (the file you received was indeed a shapefile, it has a single name (I.E. shapefile) but is really made up of multiple files that make up the whole).

First you'll have to right click the shapefile again and select "Joins and Relates" and then "Remove All Joins".

Then I would make a copy of the shapefile (just in case) by right clicking and choosing "Data" > "Export Features" 

KimGarbade_0-1648660856904.png

 

I would export the features to the default database created with your ArcGIS Pro project (It will be in the Catalog Pane; under databases and will have the same name as your project).  Make sure you don't have any selected features or you will only get those in the exported feature class.

This will export your grid shapefile to a feature class in that database.  If it doesn't automatically get added to your map add it and remove the shapefile.

Then I would similarly right click your .csv file in your Table of Contents and select "Data" > "Export Table" into the same file geodatabse (the default one).

Then I would add that to the map.  Right click the newly created Grid layer (now coming from your file geodatabase) and select "Open Attribute Table".  Find the OID in the table that opens right click it and delete it.

Now try your join again using these two sources both contained in the same geodatabase.

If that works you can export the features from the joined grid feature class to a new GridWithDensity feature class and Density will be written to that feature class without requiring a join the next time.

The only thing that worries me is that Domain error message... but hopefully that goes away.

JamesBrisbane
New Contributor

Hi Kim, I was able to follow that.  I got the grid and the density data both in my project (gdb) file, and I did the join and there were no error messages this time.  But when I look at the attribute table for the grid, only a few of the rows received a density number.   A lot more of them should have been linked to a row in the density data.  Maybe I had some rows selected in one of the tables and that caused it not to do the complete join of all rows in both tables.  I saw that happen once and I had to re-do it.   I thought I had fixed it but maybe not.   

But you have helped me a lot.  I think I'm going to give up on this now, because I don't know enough about what I'm doing.  It seems the action of a given menu item can change depending what is selected elsewhere, which makes it confusing.    If I could figure out how to do as much as possible of the data prep outside of the arcgis software, with script code, and then just tell it where the files are and have it draw the map I want with the minimum amount of messing around with the graphical interface, that might be the easier approach for me, I think.   I bought the book "Getting to know ArcGIS Pro 2.8" from Amazon and its coming tomorrow, so I'm hoping to learn from that, and maybe follow some examples.  Thanks for your help!  

 

0 Kudos
KimGarbade
Occasional Contributor III

If you are expecting more matches maybe it is a formatting problem (commonly blank space before or after; or embedded in, the ID).  Try adding a new column to your newly created tables.  Make the columns Text and make sure they have a reasonable length (something longer than your longest ID by a few characters).  Now you can use the  below code using "Calculate Field" in your attribute table to calc the new rows to the IDs without any hidden spaces.  These row now become the ID for your join (don't forget to remove all joins from you polygon grid feature class first)

return Trim(Replace($feature.IDWithSpaces, " ", ""))

KimGarbade_0-1648731396680.png

 

0 Kudos