This project has moved. For the latest updates, please go here.

Shapefile picks wrong ring for ExteriorRing

Nov 17, 2006 at 5:37 PM
I am working with some Tiger files for Virginia. It looks like ShapeFile.cs arbitrarily picks rings0 as the exterior ring. I looked in ESRI's Shapefile reference and could not find any support for this choice. It appears you need to consider the rotation of each ring to determine which are interior and which is the exterior. I have a county with two cities in it. Sharpmap is picking one of the interior rings (cities) as the exterior ring. My quick hack was to change at line 772 of V09:

for (int i = 0; i < rings.Count; i++)
if (IsCounterClockWisei)
poly.ExteriorRing = ringsi;
Nov 18, 2006 at 5:22 PM
This is the first time I've ever heard that the first ring isn't the exterior ring for a single polygon feature. Although the Shapefile definition is a bit vague, it sound a bit like your shapefile was made with a proprietary shapefilewriter that does things a bit loosely. Have you tried opening the shapefile in ArcView, and resaving it? That usually cleans up these small issues.
Nov 18, 2006 at 10:54 PM
I will play with it more next week. But the data is the US Census Bureaus Tiger county data that I downloaded from the ESRI site. I took all of the counties in Virginia, USA and merged them using ArcGIS Desktop 9.1. I think the orginal county file and the merged file had the same issue.

I think the winding of the ring is more important than the position of the ring in the shapefile. Just checked ESRI's online help. Here is a blurb from the ArgGIS 9.1 help file:
"A clockwise ring is an exterior ring, and a counterclockwise ring defines an interior ring."

Of course they are not talking about the actual format of the shapefile.