Search code examples
c#.netbing-mapssqlgeographysqlgeometry

Issue with SQLGeography STUnion & inner rings for drawing polygons on Bing Maps WPF control


I am writing an app using Bing API Spatial Data services to take of list of zip codes and combine them into one region. I have it mostly working but it seems to have issues with inner rings. Instead of a) deeming the inner region too small and just squashing it or b) properly drawing the inner ring, it seems to want to connect them, picture example below:

enter image description here

That interrior polygon should have been just a "hole" in the region, but instead it tries to connect them.

I currently have 2 relevent methods. One that decrypts the API response for the zip code, translates it to SqlGeography and STUnion()s any additional rings. and a second parent method which STUnions the results of the first method to a master SqlGeography object that contains all zip codes together when its done for a region.

Let me know if you need any more information.


Solution

  • I suspect the issue is with how the hole is being created in the WPF map control since polygons in that control don't support holes by default. Instead the common practice for creating holes in a polygon in the WPF control is to draw a line connecting all rings. You would choose a point on the outer ring, draw a line to the first inner ring, draw the inner ring and then draw a line back to outer ring. For this to work the rings must be closed and the lines must backtrack over themselves. The polygon's stroke is then hidden and polylines are used to draw the outline.

    Looking at your image it looks like the one inner ring is trying to do the above to create a second inner ring, but isn't back tracking to the first inner ring, but instead to the outer ring.