Where i'm wrong ?

Topics: SharpMap v2.0
Sep 5, 2008 at 12:54 PM
Hi, please tell me where i' wrong ?
I'm trying to draw stringLine in MapView control
the code is this .


{
            ICoordinateSequenceFactory<BufferedCoordinate2D> coordSeqFactory = new BufferedCoordinate2DSequenceFactory();           
            IGeometryFactory<BufferedCoordinate2D> geometryFactory = new GeometryFactory<BufferedCoordinate2D>(coordSeqFactory);
            SharpMap.Map maps = new SharpMap.Map(geometryFactory);


            ICoordinateSequenceFactory coordinateSequenceFactory = geometryFactory.CoordinateSequenceFactory;
            ICoordinateFactory coordinateFactory = geometryFactory.CoordinateFactory;
            ICoordinateSequence coords = coordinateSequenceFactory.Create(CoordinateDimensions.Two);
           
           
            ICoordinate points = coordinateFactory.Create(20,30);
            coords.Add(points);
            points = coordinateFactory.Create(10,60);
            coords.Add(points);
            points = coordinateFactory.Create(40,50);
            coords.Add(points);

            ILineString line = geometryFactory.CreateLineString(coords);

            Collection<IGeometry> geometry = new Collection<IGeometry>();
            geometry.Add(line);

            List<DataColumn> columns = new List<DataColumn>();
           
            DataColumn cl = new DataColumn("Column1");
            columns.Add(cl);
            FeatureProvider provider = new FeatureProvider(geometryFactory,columns.ToArray());

            GeometryLayer layer = new GeometryLayer("ime na sloi", provider);
            maps.AddLayer(layer);
            mapViewControl1.Map = maps;
            mapViewControl1.ZoomToExtents();

        }

I have no problems with compile.
When I start the project  get this error message -

An unhandled exception of type 'System.ArgumentException' occurred in SharpMap.dll

Additional information: newEnvelope cannot be empty.


It hapens when i call ZoomToExtents() function.
I can't understand what i'm missing.

Thank you in advance Faxy.
Coordinator
Sep 6, 2008 at 7:56 AM
Hi Faxy, are you using the june21st drop or the svn, also can you post the stacktrace cheers jd
Sep 8, 2008 at 8:15 AM
Hi John Diss , I'm using the last from svn

the call stack is :

>    SharpMap.dll!SharpMap.Presentation.Presenters.MapPresenter2D.setViewEnvelopeInternal(GeoAPI.Geometries.IExtents2D newEnvelope = {Extents [NaN - NaN, NaN - NaN]}) Line 1271    C#
     SharpMap.dll!SharpMap.Presentation.Presenters.MapPresenter2D.ZoomToWorldBoundsInternal(GeoAPI.Geometries.IExtents2D zoomBox = {Extents [NaN - NaN, NaN - NaN]}) Line 609 + 0x9 bytes    C#
     SharpMap.dll!SharpMap.Presentation.Presenters.MapPresenter2D.ZoomToExtentsInternal() Line 563 + 0x2b bytes    C#
     SharpMap.dll!SharpMap.Presentation.Presenters.MapPresenter2D.handleViewZoomToExtentsRequested(object sender = {SharpMap.Presentation.WinForms.MapViewControl}, System.EventArgs e = {System.EventArgs}) Line 1134 + 0x7 bytes    C#
     SharpMap.Presentation.WinForms.dll!SharpMap.Presentation.WinForms.MapViewControl.onRequestZoomToExtents() Line 1013 + 0x12 bytes    C#
     SharpMap.Presentation.WinForms.dll!SharpMap.Presentation.WinForms.MapViewControl.ZoomToExtents() Line 390 + 0x7 bytes    C#
     SharpMap2Demo.exe!SharpMap2Demo.Form1.shape_Click(object sender = {Text = "Shape"}, System.EventArgs e = {X = 68 Y = 12 Button = Left}) Line 177 + 0x11 bytes    C#
     System.Windows.Forms.dll!System.Windows.Forms.Control.OnClick(System.EventArgs e) + 0x6a bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Button.OnClick(System.EventArgs e) + 0x49 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs mevent = {X = 68 Y = 12 Button = Left}) + 0xc8 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks) + 0x2f7 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x526 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.ButtonBase.WndProc(ref System.Windows.Forms.Message m) + 0xc7 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Button.WndProc(ref System.Windows.Forms.Message m) + 0x2b bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0xd bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x36 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 514, System.IntPtr wparam, System.IntPtr lparam) + 0x57 bytes   
     [Native to Managed Transition]   
     [Managed to Native Transition]   
     System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = -1, int pvLoopData = 0) + 0x2f1 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x17d bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x53 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x2e bytes   
     SharpMap2Demo.exe!SharpMap2Demo.Program.Main() Line 17 + 0x1a bytes    C#
     [Native to Managed Transition]   
     [Managed to Native Transition]   
     mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x39 bytes   
     Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2b bytes   
     mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x3b bytes   
     mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x81 bytes   
     mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x40 bytes   


Thank you in advance, Faxy

Coordinator
Sep 8, 2008 at 12:42 PM
Edited Sep 8, 2008 at 12:43 PM
Hi Faxy, in your code :

            DataColumn cl = new DataColumn("Column1");
            columns.Add(cl);
            FeatureProvider provider = new FeatureProvider(geometryFactory,columns.ToArray());

you do not assign any rows to the FeatureProvider. You probably need to call provider.Insert or there may be another way of populating the rows collection..

The end result is that when you call ZoomToExtents the layers extents are unknown and the error occurs..
hth jd
Sep 9, 2008 at 12:10 PM
Edited Sep 10, 2008 at 8:02 AM
JohnDiss thank you for your advice :).

But i ' ve tried this code:

{
            ICoordinateSequenceFactory<BufferedCoordinate2D> coordSeqFactory = new BufferedCoordinate2DSequenceFactory();           
            IGeometryFactory<BufferedCoordinate2D> geometryFactory = new GeometryFactory<BufferedCoordinate2D>(coordSeqFactory);
            SharpMap.Map maps = new SharpMap.Map(geometryFactory);


            ICoordinateSequenceFactory coordinateSequenceFactory = geometryFactory.CoordinateSequenceFactory;
            ICoordinateFactory coordinateFactory = geometryFactory.CoordinateFactory;
            ICoordinateSequence coords = coordinateSequenceFactory.Create(CoordinateDimensions.Two);
           
           
            ICoordinate points = coordinateFactory.Create(20,30);
            coords.Add(points);
            points = coordinateFactory.Create(10,60);
            coords.Add(points);
            points = coordinateFactory.Create(40,50);
            coords.Add(points);

            ILineString line = geometryFactory.CreateLineString(coords);

            Collection<IGeometry> geometry = new Collection<IGeometry>();
            geometry.Add(line);

            SharpMap.Data.FeatureDataTable table = new FeatureDataTable("Table",geometryFactory);
          
            FeatureDataRow row = table.NewRow();

            row.Geometry = geometry[0];
            table.ImportRow(row);

            GeometryProvider provider1 = new GeometryProvider(row);
           
            GeometryLayer layer = new GeometryLayer("ime na sloi",provider1);

            maps.AddLayer(layer);
           
            mapViewControl1.Map = maps;
            mapViewControl1.ZoomToExtents();

        }

 in this case The Map object has extents but i recieved this error :


An unhandled exception of type 'System.NotSupportedException' occurred in SharpMap.dll

Additional information: Specified method is not supported.

the Call stack is :

>    SharpMap.dll!SharpMap.Data.Providers.AsyncResult.EndInvoke() Line 106    C#
     SharpMap.dll!SharpMap::Data::Providers::AsyncResult::EndInvoke() Line 38 + 0x7 bytes    C++
     SharpMap.dll!SharpMap.Data.Providers.AsyncFeatureProviderAdapter.EndExecuteQuery(System.IAsyncResult asyncResult = {SharpMap.Data.Providers.AsyncResult<SharpMap.Data.IFeatureDataReader>}) Line 69 + 0x9 bytes    C#
     SharpMap.dll!SharpMap.Layers.Layer.LoadLayerData(SharpMap.Expressions.QueryExpression query = {SharpMap.Expressions.FeatureQueryExpression}) Line 555 + 0x12 bytes    C#
     SharpMap.dll!SharpMap.Layers.FeatureLayer.handleFeaturesSelectRequested(object sender = {}, SharpMap.Data.SelectRequestedEventArgs e = {SharpMap.Data.SelectRequestedEventArgs}) Line 305 + 0x9 bytes    C#
     SharpMap.dll!SharpMap.Data.FeatureDataTable.OnSelectRequested(SharpMap.Expressions.FeatureQueryExpression query = {SharpMap.Expressions.FeatureQueryExpression}) Line 785 + 0xf bytes    C#
     SharpMap.dll!SharpMap.Data.FeatureDataTable.Select(SharpMap.Expressions.SpatialBinaryExpression query = {SharpMap.Expressions.SpatialBinaryExpression}) Line 692 + 0x3c bytes    C#
     SharpMap.dll!SharpMap.Presentation.Presenters.MapPresenter2D.RenderFeatureLayer(SharpMap.Layers.IFeatureLayer layer = {ime na sloi}, SharpMap.Presentation.RenderPhase phase = Normal) Line 932 + 0x5a bytes    C#
     SharpMap.Presentation.WinForms.dll!SharpMap.Presentation.WinForms.MapPresenter.RenderFeatureLayer(SharpMap.Layers.IFeatureLayer layer = {ime na sloi}, SharpMap.Presentation.RenderPhase phase = Normal) Line 103 + 0xa bytes    C#
     SharpMap.dll!SharpMap.Presentation.Presenters.MapPresenter2D.RenderLayer(SharpMap.Layers.ILayer layer = {ime na sloi}, SharpMap.Presentation.RenderPhase phase = Normal) Line 878 + 0x1f bytes    C#
     SharpMap.dll!SharpMap.Presentation.Presenters.MapPresenter2D.RenderAllLayers(SharpMap.Presentation.RenderPhase phase = Normal) Line 845 + 0x35 bytes    C#
     SharpMap.dll!SharpMap.Presentation.Presenters.MapPresenter2D.RenderAllLayers() Line 822 + 0xc bytes    C#
     SharpMap.dll!SharpMap.Presentation.Presenters.MapPresenter2D.setViewMetricsInternal(SharpMap.Rendering.Rendering2D.Size2D newViewSize = {Width: 803, Height: 411}, GeoAPI.Coordinates.ICoordinate newCenter = {(25, 45)}, double newWorldWidth = 58.613138686131379) Line 1385 + 0x7 bytes    C#
     SharpMap.dll!SharpMap.Presentation.Presenters.MapPresenter2D.setViewEnvelopeInternal(GeoAPI.Geometries.IExtents2D newEnvelope = {Extents [10 - 40, 30 - 60]}) Line 1302 + 0x5e bytes    C#
     SharpMap.dll!SharpMap.Presentation.Presenters.MapPresenter2D.ZoomToWorldBoundsInternal(GeoAPI.Geometries.IExtents2D zoomBox = {Extents [10 - 40, 30 - 60]}) Line 609 + 0x9 bytes    C#
     SharpMap.dll!SharpMap.Presentation.Presenters.MapPresenter2D.ZoomToExtentsInternal() Line 563 + 0x2b bytes    C#
     SharpMap.dll!SharpMap.Presentation.Presenters.MapPresenter2D.handleViewZoomToExtentsRequested(object sender = {SharpMap.Presentation.WinForms.MapViewControl}, System.EventArgs e = {System.EventArgs}) Line 1134 + 0x7 bytes    C#
     SharpMap.Presentation.WinForms.dll!SharpMap.Presentation.WinForms.MapViewControl.onRequestZoomToExtents() Line 1013 + 0x12 bytes    C#
     SharpMap.Presentation.WinForms.dll!SharpMap.Presentation.WinForms.MapViewControl.ZoomToExtents() Line 390 + 0x7 bytes    C#
     SharpMap2Demo.exe!SharpMap2Demo.Form1.shape_Click(object sender = {Text = "Shape"}, System.EventArgs e = {X = 69 Y = 16 Button = Left}) Line 158 + 0x11 bytes    C#
     System.Windows.Forms.dll!System.Windows.Forms.Control.OnClick(System.EventArgs e) + 0x6a bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Button.OnClick(System.EventArgs e) + 0x49 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs mevent = {X = 69 Y = 16 Button = Left}) + 0xc8 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks) + 0x2f7 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x526 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.ButtonBase.WndProc(ref System.Windows.Forms.Message m) + 0xc7 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Button.WndProc(ref System.Windows.Forms.Message m) + 0x2b bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0xd bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x36 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 514, System.IntPtr wparam, System.IntPtr lparam) + 0x57 bytes   
     [Native to Managed Transition]   
     [Managed to Native Transition]   
     System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = -1, int pvLoopData = 0) + 0x2f1 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x17d bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x53 bytes   
     System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x2e bytes   
     SharpMap2Demo.exe!SharpMap2Demo.Program.Main() Line 17 + 0x1a bytes    C#
     [Native to Managed Transition]   
     [Managed to Native Transition]   
     mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x39 bytes   
     Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2b bytes   
     mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x3b bytes   
     mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x81 bytes   
     mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x40 bytes   

I suppose that i'm missing something.
I couldn't use FeatureDataRow<Guid>  because there wasn't constructor about it.
Also couldn't find examples with using it.

Thank you in advance Faxy

Coordinator
Sep 10, 2008 at 10:02 AM
Look in 'SharpMap.Tests.DataSourceHelper.cs" for 'CreateFeatureDataSource' function.
There you can find how to populate a FeatureProvider with data so that it will be displayed with SharpMap.
Adding rows to the FeatureDataTable accessible via 'GeometryLayer.Features' property does not result in an adjustment of the extents of the Layer.
I don't know whether this is by design or a bug.
hth
FObermaier
Sep 10, 2008 at 2:26 PM
FObermaier thank you very much.
That solved the problem, it was with using of  FeatureDataRow<Guid> .