Support for (geometric) networks

Apr 3, 2012 at 7:37 PM


I'm designing an app that uses DotSpatial as it's geospatial engine.  One of the things my app needs to do is create features that are connected to each other.  ESRI calls this Geometric Networks.  I've looked through the source code and I don't see anything that seems to do this, so I'm wondering if this is on the roadmap for DotSpatial?  If not, I need it so I will need to implement it.

Once I hear back, I will ask some further questions about implementation.



Apr 11, 2012 at 5:06 PM

Patch 11917 seems to have a bug in 



Did you really intend to 

 if (env.Contains(c))
                            snappedCoord = c;
// suggestion: otherwise we continue through the other layers and use the last match instead of the first.
return true;


Also, a user reported an exception:

Case #ds-pnp5pml8 - System.NullReferenceException
System.NullReferenceException: Object reference not set to an instance of an object. 
at DotSpatial.Plugins.ShapeEditor.SnappableMapFunction.ComputeSnappedLoc(GeoMouseArgs e, Coordinate& snappedCoord) 
at DotSpatial.Plugins.ShapeEditor.AddShapeFunction.OnMouseMove(GeoMouseArgs e) 
at DotSpatial.Controls.MapFunction.DoMouseMove(GeoMouseArgs e) 
at DotSpatial.Controls.Map.OnMouseMove(MouseEventArgs e) 
at System.Windows.Forms.Control.WmMouseMove(Message& m) 
at System.Windows.Forms.Control.WndProc(Message& m) 
at System.Windows.Forms.ScrollableControl.WndProc(Message& m) 
at System.Windows.Forms.UserControl.WndProc(Message& m) 
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Apr 12, 2012 at 7:29 PM

Yes, you're correct there is a bug.  The break was there from some other iteration of this feature.  ComputeSnappedLoc() should be like you modified it.

Is there any way to duplicate the exception?

Apr 12, 2012 at 11:49 PM

The bug report doesn't describe what caused the issue. My only guess is that 

Map.PixelToProj(mouseRect) or the env is null.
Apr 13, 2012 at 2:46 PM

The first 5 lines of ComputeSnappedLocation should be replaced with:

            if (this.snapLayers == null || e == null || Map == null)
                return false;

            Rectangle mouseRect = new Rectangle(e.X - this.snapTol, e.Y - this.snapTol, this.snapTol * 2, this.snapTol * 2);
            Extent pix = Map.PixelToProj(mouseRect);
            if (pix == null)
                return false;

            IEnvelope env = pix.ToEnvelope();
            if (env == null)
                return false;

Hopefully this will prevent that exception from occurring.


Apr 13, 2012 at 5:18 PM

Thanks for you work on that! I notice ToEnvelope() will always return an envelope, so we don't need that null check... I'll apply the changes.