Help with Map Reprojection and OverFlow Exception in Drawing.DLL

Topics: SharpMap v0.9 / v1.x
Apr 15 at 3:40 PM
Hello,

To begin I have read the following post and applied the try-catch fix and recompiled but still doesn't solve the issue. https://sharpmap.codeplex.com/discussions/10331

I am using SharpMap 1.0

The issue is with a map that is displaying about a dozen Vector and Label layers derived from shapefiles. The map is displayed fine originally and is using a NAD8315N projected coordinate system. Some of the vectorlayers have visibility settings that don't become visible until the user zooms down in. The user is able to switch to a Geographic coordinate system with a click of a button. The reprojection is accomplished by iterating through the mapBox layers, retrieving the existing coordinate system from the shapefile provider and then performing the coordinate transformation to WGS84 coordinate system. This works fine and the map is displayed in the new Geographic system until I zoom down in when it encounters one of the layers that has a lower maxvisibility setting. This is when the "OverFlowException in System.Drawing.DLL' occurs and the map displays a red X.

If leave out the visibility settings in the original NAD8315N map and then reproject to WGS the zooming works fine. Here is my code that executes when the user clicks the WGS projection buton.
                for (int i = 0; i != mapBox1.Map.Layers.Count; i++)
                {
                    if (mapBox1.Map.Layers[i].GetType() == typeof(SharpMap.Layers.VectorLayer))
                    {
                        if (((SharpMap.Layers.VectorLayer)mapBox1.Map.Layers[i]).DataSource.ToString() == "SharpMap.Data.Providers.ShapeFile")
                        {
                            try
                            {
                                GeoAPI.CoordinateSystems.ICoordinateSystem icShapeFile = (((SharpMap.Layers.VectorLayer)mapBox1.Map.Layers[i]).DataSource as SharpMap.Data.Providers.ShapeFile).CoordinateSystem;
                                if (icShapeFile != null)
                                {
                                    GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation transFactoryShapeTo4326 = ctfac.CreateFromCoordinateSystems(icShapeFile, ic4326);
                                    GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation transFactory4326ToShape = ctfac.CreateFromCoordinateSystems(ic4326, icShapeFile);
                                    ((SharpMap.Layers.VectorLayer)mapBox1.Map.Layers[i]).CoordinateTransformation = transFactoryShapeTo4326;
                                    ((SharpMap.Layers.VectorLayer)mapBox1.Map.Layers[i]).ReverseCoordinateTransformation = transFactory4326ToShape;
                                }
                                else
                                {
                                    ((SharpMap.Layers.VectorLayer)mapBox1.Map.Layers[i]).CoordinateTransformation = transFactory26915to4326;
                                    ((SharpMap.Layers.VectorLayer)mapBox1.Map.Layers[i]).ReverseCoordinateTransformation = transFactory4326to26915;
                                }
                                ((SharpMap.Layers.VectorLayer)mapBox1.Map.Layers[i]).SRID = 4326;
                            }
                            catch
                            {
                                mapBox1.Map.Layers.RemoveAt(i);
                                i--;
                            }
                        }
                    }

                    if (mapBox1.Map.Layers[i].GetType() == typeof(SharpMap.Layers.LabelLayer))
                    {
                        if (((SharpMap.Layers.LabelLayer)mapBox1.Map.Layers[i]).DataSource.ToString() == "SharpMap.Data.Providers.ShapeFile")
                        {
                            try
                            {
                                GeoAPI.CoordinateSystems.ICoordinateSystem icShapeFile = (((SharpMap.Layers.LabelLayer)mapBox1.Map.Layers[i]).DataSource as SharpMap.Data.Providers.ShapeFile).CoordinateSystem;
                                if (icShapeFile != null)
                                {
                                    GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation transFactoryShapeTo4326 = ctfac.CreateFromCoordinateSystems(icShapeFile, ic4326);
                                    GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation transFactory4326ToShape = ctfac.CreateFromCoordinateSystems(ic4326, icShapeFile);
                                    ((SharpMap.Layers.LabelLayer)mapBox1.Map.Layers[i]).CoordinateTransformation = transFactoryShapeTo4326;
                                    ((SharpMap.Layers.LabelLayer)mapBox1.Map.Layers[i]).ReverseCoordinateTransformation = transFactory4326ToShape;
                                }
                                else
                                {
                                    ((SharpMap.Layers.LabelLayer)mapBox1.Map.Layers[i]).CoordinateTransformation = transFactory26915to4326;
                                    ((SharpMap.Layers.LabelLayer)mapBox1.Map.Layers[i]).ReverseCoordinateTransformation = transFactory4326to26915;
                                }
                                ((SharpMap.Layers.LabelLayer)mapBox1.Map.Layers[i]).SRID = 4326;
                            }
                            catch
                            {
                                mapBox1.Map.Layers.RemoveAt(i);
                                i--;
                            }
                        }
                    }
                }
                mapBox1.Map.ZoomToBox(mapBox1.Map.Layers[0].Envelope);
                mapBox1.Refresh();
Coordinator
Apr 18 at 7:23 AM
Can you isolate the error by posting the full stack trace?
It would be helpful if you could set up a testcase (create map object, create layer, set reprojection, set zoom window, call getmap) along with any data needed that proves your issue and provide that on https://github.com/SharpMap/SharpMap/issues
Apr 18 at 3:05 PM
Thanks FObermaier I can surely do that. But before I do that I was able to catch the error inside VectorRender in the DrawLineString at the g.DrawPath() method. I noticed that in my VectorRenderer class all the LimitValues and ExtremValue were commented out. When I enabled these Limit value functions the map zooms fine.

For instance inside DrawLineString I changed the following
gp.AddLines(/LimitValues(/points/, ExtremeValueLimit)/);

to

gp.AddLines(LimitValues(points, ExtremeValueLimit));

I did this everywhere inside VectorRenderer.
Coordinator
Apr 20 at 10:05 AM
Please do as I have never encountered this situation.
I'd like to see where it comes from and maybe avoid it beforehand so the LimitValues/ExtermeValueLimit can be avoided or at least be used more efficient.
Apr 25 at 5:38 PM
Sounds good - I will work on this and get back to you with some more information.
Apr 27 at 9:26 PM
I tried this again with a test project and only a few layers and could not duplicate the error.