This project is read-only.

Problem with Dotspatial tutorial 4: error generated

Jul 21, 2013 at 2:27 PM
Hello dear reader

I am working my way into tutorial 4 to digitize lines and such when i use the exact code an error is generated point array must contain 0 or > 1 elements

Any of you have an idea? I have no clue where the error is generated... to make it even more complex.... when i use a breakpoint now and then it works so my nooby guess would be that he misses or gets additional mouseclicks where it shouldnt....

the error also appears most of the time when i digitise a polygon....
System.ArgumentException was unhandled
  Message=point array must contain 0 or > 1 elements
       at DotSpatial.Topology.LineString..ctor(IBasicLineString lineStringBase) in E:\dev\dotSpatial\DotSpatial.Topology\LineString.cs:line 100
       at DotSpatial.Topology.Geometry.FromBasicGeometry(IBasicGeometry geom) in E:\dev\dotSpatial\DotSpatial.Topology\Geometry.cs:line 1262
       at DotSpatial.Data.FeatureSetExt.Intersects(IFeature self, IEnvelope env) in E:\dev\dotSpatial\DotSpatial.Data\FeatureSetExt.cs:line 158
       at DotSpatial.Data.FeatureSet.Select(Extent region, Extent& affectedRegion) in E:\dev\dotSpatial\DotSpatial.Data\FeatureSet.cs:line 995
       at DotSpatial.Data.FeatureSet.Select(Extent region) in E:\dev\dotSpatial\DotSpatial.Data\FeatureSet.cs:line 949
       at DotSpatial.Controls.MapLineLayer.DrawRegions(MapArgs args, List`1 regions) in E:\dev\dotSpatial\DotSpatial.Controls\MapLineLayer.cs:line 143
       at DotSpatial.Controls.MapFrame.Initialize(List`1 regions) in E:\dev\dotSpatial\DotSpatial.Controls\MapFrame.cs:line 294
       at DotSpatial.Controls.MapFrame.Initialize() in E:\dev\dotSpatial\DotSpatial.Controls\MapFrame.cs:line 325
       at DotSpatial.Controls.MapFrame.ResetBuffer() in E:\dev\dotSpatial\DotSpatial.Controls\MapFrame.cs:line 262
       at DotSpatial.Controls.MapFrame.set_ViewExtents(Extent value) in E:\dev\dotSpatial\DotSpatial.Controls\MapFrame.cs:line 773
       at DotSpatial.Controls.MapFrame.ResetExtents() in E:\dev\dotSpatial\DotSpatial.Controls\MapFrame.cs:line 249
       at DotSpatial.Controls.MapFunctionPan.OnMouseUp(GeoMouseArgs e) in E:\dev\dotSpatial\DotSpatial.Controls\MapFunctionPan.cs:line 116
       at DotSpatial.Controls.MapFunction.DoMouseUp(GeoMouseArgs e) in E:\dev\dotSpatial\DotSpatial.Controls\MapFunction.cs:line 157
       at DotSpatial.Controls.Map.OnMouseUp(MouseEventArgs e) in E:\dev\dotSpatial\DotSpatial.Controls\Map.cs:line 1516
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at SWINGviewer.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
Jul 23, 2013 at 5:34 PM
part of the code where it goes wrong..... it doesnt give me the exact location but strangly as well i must click 3 times to get the first single line
 Case "Line"
                    If e.Button = MouseButtons.Left Then
                        'left click - fill array of coordinates
                        'coordinate of clicked point
                        Dim coord As Coordinate = myVenster.PixelToProj(e.Location)
                        If Not coord.IsEmpty Then
                            If DIGIlinemouseClick = True Then
                                'first time left click - create empty line feature
                                If DIGIfirstClick = True Then
                                    'Create a new List called lineArray.
                                    'In List we need not define the size and also 
                                    'Here this list will store the Coordinates
                                    'We are going to store the mouse click coordinates into this array.
                                    Dim DIGIlineArray As New List(Of Coordinate)
                                    'Create an instance for LineString class.
                                    'We need to pass collection of list coordinates
                                    Dim DIGIlineGeometry As New LineString(DIGIlineArray)
                                    'Add the linegeometry to line feature
                                    Dim DIGIlineFeature As IFeature = DIGIlineF.AddFeature(DIGIlineGeometry)
                                    'add first coordinate to the line feature
                                    'set the line feature attribute
                                    DIGIlineID = DIGIlineID + 1
                                    DIGIlineFeature.DataRow("LineID") = DIGIlineID
                                    DIGIfirstClick = False
                                ElseIf DIGIfirstClick = False And DIGIdoorsnede = False Then
                                    'second or more clicks - add points to the existing feature
                                    Dim existingFeature As IFeature = DIGIlineF.Features(DIGIlineF.Features.Count - 1)
                                    'refresh the map if line has 2 or more points
                                    If existingFeature.Coordinates.Count >= 2 Then
                                    End If

                                ElseIf DIGIfirstClick = False And DIGIdoorsnede = True Then
                                    'second or more clicks - add points to the existing feature
                                    Dim existingFeature As IFeature = DIGIlineF.Features(DIGIlineF.Features.Count - 1)
                                    'refresh the map if line has 2 or more points
                                    If existingFeature.Coordinates.Count = 3 Then
                                        DIGIdoorsnede = False
                                        DIGIshapeType = ""
                                        myVenster.FunctionMode = DotSpatial.Controls.FunctionMode.None
                                        myVenster.Cursor = Cursors.Default
                                    End If
                                End If
                            End If

                            'right click - reset first mouse click
                            DIGIfirstClick = True
                            DIGIlinemouseClick = False
                        End If
                    End If
Jul 23, 2013 at 11:22 PM
i am pretty confident it happends now and then.... some how the second click is not always registrated