Shapefile: Polygon Fill


There appears to be a bug in polygon shapefile drawing such that the shape fills on the exterior of the polygon.

It is dependent on the zoom level (or more likely the scale), as it only occurs at a high zoom factor.

I have been debugging CShapefileDrawer::AddPolygonToPath assuming the issue was that the polygon was not closed or perhaps something in the Graphics::FillPath API but neither seems to be the case.

I can reproduce in MapWindow5 (5.2.0). I’m using MapWinGIS 5.0.1 built from source on Windows 7.

See attached files. Zoom to [4.135 deg, 9.755 deg]. From zoom 16 to 17 it occurs and remains such for higher zoom levels as well.

Thanks for any insight.

LT (3.4 MB)

I assume you mean this:
At scale 15:

At scale 17:

The fill color is swapped.

I’m also not sure why this happens. We need to investigate this closer.

@jerryfaust: Do you have any idea?

Yes exactly.
If @jerryfaust is familiar with the GDI stuff he hopefully will have some insight as I’ve made little progress in my debugging efforts!

I’ll step through it and see if I can figure out what’s happening.

This is a strange one. I found a much less complex layer (a single polygon, being a county in Montana).

With just this polygon, I can find a couple corners that I can zoom in to with no problem, and a couple other corners that I can recreate the problem.

So I’ll try to narrow down the differences between when it happens and when it doesn’t.

@jerryfaust can you please share your single polygon layer? thx (88.5 KB)

In my testing, areas toward the top-left had troubles, while areas toward the lower-right behaved properly.

I cannot reproduce the issue with this polygon. Do you have other layers on your map? I notice that this polygon only has one part.

Can you confirm the projection? Perhaps also if you can provide lat/lon of a trouble spot.


It’s definitely a simplified case, being the only layer, and a single (non-multipart) polygon, as compared with the oceans, being a single, huge, many-multi-part polygon.

The projection, as I recall, is one of the NAD-83 Montana State Planes (in feet).

I don’t have the lat/lon at the moment, but I remember that I could reproduce the error in the upper-most, left-most corner, but no in the lower-most, right-most corner.

I can get back to you with a lat/lon in perhaps 3 or 4 hours.


The county fill flips when the scalebar says around 50 cm.

The coordinate is 46,08,09 -113,13,21

But zooming in on the vertex at 45,44,58 -113,48,37 does not flip.

I think I know why this happens. GDI doesn’t like very big point coordinates. When we zoom in MapWinGIS scales the coordinates. As a result, on a big enough zoom level (and more quickly for large paths), the paths are not considered valid by GDI+ and drawing completely stops or for polygons swaps inside with outside.

You can test this like this: make a new in memory shapefile, add a two-point line, zoom in until it dissapears, then draw another line at that zoomlevel: you can again zoom in on this line but it will eventually dissapear as well.

I’ve been thinking about a possible fix, and I could think of two options:

  • switch to using transformations instead of manually scaling (not nice since we need to scale linewidths etc. as well - lot of work)
  • break our paths into smaller paths (interpolated between vertices), maybe this way the coordinates of the smaller paths are sufficiently small for GDI to work it out