I am using Dundas Maps and attempting to draw a map of the world where countries are grouped into regions that are specific to a business implementation.
I have shape data (points and segments) for each country in the world. I can combine countries into regions by adding all points and segments for countries within a region to a new region shape.
foreach(var region in GetAllRegions()){
var regionShape = new Shape { Name = region.Name };
foreach(var country in GetCountriesInRegion(region.Id)){
var countryShape = GetCountryShape(country.Id);
regionShape.AddSegments(countryShape.ShapeData.Points, countryShape.ShapeData.Segments);
}
map.Shapes.Add(regionShape);
}
The problem is that the country border lines still show up within a region and I want to remove them so that only regional borders show up.
Dundas polygons must start and end at the same point. This is the case for all the country shapes. Now I need an algorithm that can:
- Determine where country borders intersect at a regional border, so that I can join the regional border segments.
- Determine which country borders are not regional borders so that I can discard them.
- Sort the resulting regional points so that they sequentialy describe the shape boundaries.
Below is where I have gotten to so far with the map. You can see that the country borders still need to be removed. For example, the border between Mongolia and China should be discarded whereas the border between Mongolia and Russia should be retained.
The reason I need to retain a regional border is that the region colors will be significant in conveying information but adjacent regions may be the same color. The regions can change to include or exclude countries and this is why the regional shaping must be dynamic.
EDIT: I now know that I what I am looking for is a UNION of polygons. David Lean explains how to do it using the spatial functions in SQL Server 2008 which might be an option but my efforts have come to a halt because the resulting polygon union is so complex that SQL truncates it at 43,680 characters. I'm now trying to either find a workaround for that or find a way of doing the union in code.