Using shpchk to fix damaged shapefiles

While I was working on this week’s blog entry, I opened an old MXD, and noticed that one of the layers in the table of contents had “gone bad.” The checkbox had grayed out and there was a red exclamation point beside it. This is a normal occurrence when a dataset gets renamed or moved to a different location, and can be repaired by updating the link. But in this case, I hadn’t been moving any files around. I attempted to “refresh” the link, by re-pointing it to the same data source, but was stopped in my tracks by this error message.

Detour! I know a way to solve this problem, so this week, instead, I will be blogging about shapechk.exe

Problem: You get a cryptic error message when trying to load a shapefile.

Shapefiles sometimes get corrupted. The errors they produce as a result used to be even less descriptive than what you see above. But as that message states, it has something to do with there being more or less entries in the attribute table (dbf) than there are in the index of spatial geometries (shp). I don’t know how it happens, but I can tell you that it does happen often enough that you will encounter it eventually.

A long time ago, Andrew Williamson wrote a utility that he doesn’t support anymore, but still offers on the web at http://www.geocities.com/SiliconValley/Haven/2295/howto_shapechk.html Note: GeoCities is closing on Oct 26th (tomorrow). After that, you can get it at ArcScripts.

It still works. It may not solve all your shapefile problems, but, up to now, it has solved all of mine. It’s a standalone executable that you simply unzip and run. Then, you press the buttons starting with Shapefile… on the left.

Browse to your damaged shapefile, then press Build Shx. Shx is the shapefile index. It will generate a new one in case your old one was the problem. Next, Check DBF.

This is the part where where it checks if the number of records in the dbf matches the number of records in the shp. If you lost your dbf entirely, it will build you a new empty one. You won’t have attributes but at least you will be able to see your shapes. In my case, the utility needed to insert 28 empty records into my dbf table to fix my shapefile.

When I opened my MXD back up, everything was working again.

Tags: ,

One Response to “Using shpchk to fix damaged shapefiles”

  1. Ted Scheckler Says:

    Great job on the site, it looks wonderful. I am going to bookmark it and will make sure to visit weekly

Leave a Reply

Bad Behavior has blocked 46 access attempts in the last 7 days.