2

I am using ArcGIS Desktop 10.1.

I want to join a shapefile in which I stored geographical information with a CSV data file containing certain variables. However, when I try to apply the "join" command, the variable from the CSV file (6 digits zip code) to base the join on is not shown. Therefore I have exported the CSV file into a DBF file, but the variable still won't show up in the join command. For your information: The variable is shown as "Type:Long".

What is the solution to this problem?

I have read somewhere on the site to "Add a field" and then use the "Field Calculator" and simply copy the column in question with a Python command (!!). I tried this and copied the column, and now it shows "Type:String", but the join is still not functioning.

1
  • 2
    This usually boils down to one of three problems. First, as in the other place you read, is the field data types must match. You can't join a string to a long; it needs to be the same type in your shapefile and csv. Second, shapefiles have restrictions on field names including length and allowed characters. Note that's field names, not values stored in that field. Third, it's possible Arc simply isn't reading your csv file as the correct data types, which requires a format conversion or use of a schema.ini file (and possible csv cleanup). All of these are covered at other questions here.
    – Chris W
    Sep 21, 2014 at 20:28

1 Answer 1

2

I ran into a similar problem a while back and ended up writing a custom tool for merging a CSV with a shapefile's DBF file. It's within the free and open-source GIS Whitebox Geospatial Analysis Tools (for which I am the lead developer).

enter image description here


First of all, your CSV file is actually delimited by semicolons instead of commas, which the tool was not capable of using as a delimiter. I've updated it now so that it will work with semicolons (along with commas, spaces, and tabs). The second problem was that your keys did not match up. The GKZ field in the shapefile's database appears to have an '8' appended to the front of it. I created a new field in your shapefile called GKZ2 in which I removed the starting '8' then performed the Merge and it worked fine. Because the merge is sparse (i.e. there are many communities left out), there are a lot of blanks in the database. Depending on your application, you may want to fill those null values in with something (e.g. 0). Note, if you would like the altered Merge Table With CSV tool (the one that accepts semicolons as delimiters) simply right-click over the tool in Whitebox and select "Update Script From Code Repository" (see image below).

enter image description here

5
  • Thanks for the link, but this doesn't work. When I go to Database Tools-->Merge Table with CSV and then select the Input Shapefile and the Input CSV file, the program does not recognize a single Foreign Key but shows me all the columns in one field and then when I click on Run I receive the following error message: "An error has occured during operation. See log file for details." Any suggestions? Sep 21, 2014 at 17:35
  • @bobbyfisher Was there some kind of an error message? Can you select 'Report an Error' in the help and I'll see if I can find the problem. Sep 21, 2014 at 17:37
  • @bobbyfisher Thanks for sending your error log. It said that you have a field name (probably in your CVS) that is longer than the allowable 10 characters. Can you try editing your long field names to shorter alternatives and give it another go? Does your CVS have column headers? If not, you may want to put some in and try it again. Sep 21, 2014 at 17:40
  • Yes, I have location names that are >10 characters in my shapefile. How can I shorten the names? Sep 21, 2014 at 17:51
  • @bobbyfisher Open the attribute table of the shapefile, select the Field Summary tab and then click 'Change Field Title' then save. If you like, you can email me your shapefile and CVS with the name of the keys in the database and I'll see if I can find the problem. My email is here: uoguelph.ca/geography/faculty/lindsay-john Sep 21, 2014 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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