Problem with Sample app in V2

Topics: SharpMap Project, SharpMap v2.0, WinForms Controls
Sep 16, 2008 at 11:34 AM
I´m trying to make a simple test application using SharpMap V2 rev r392, and i get a exception when adding a layer.
The exception is:
Value cannot be null.
Parameter name: extents
Stack Trace:
   at SharpMap.Expressions.ExtentsExpression..ctor(IExtents extents) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Expressions\ExtentsExpression.cs:line 33
   at SharpMap.Expressions.SpatialBinaryExpression.Intersects(IExtents extents) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Expressions\SpatialBinaryExpression.cs:line 35
   at SharpMap.Presentation.Presenters.MapPresenter2D.RenderFeatureLayer(IFeatureLayer layer, RenderPhase phase) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Presentation\Presenters\MapPresenter2D.cs:line 928
   at SharpMap.Presentation.WinForms.MapPresenter.RenderFeatureLayer(IFeatureLayer layer, RenderPhase phase) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap.Presentation\WinForms\MapPresenter.cs:line 103
   at SharpMap.Presentation.Presenters.MapPresenter2D.RenderLayer(ILayer layer, RenderPhase phase) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Presentation\Presenters\MapPresenter2D.cs:line 878
   at SharpMap.Presentation.Presenters.MapPresenter2D.RenderAllLayers(RenderPhase phase) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Presentation\Presenters\MapPresenter2D.cs:line 845
   at SharpMap.Presentation.WinForms.MapPresenter.RenderFeatureLayer(IFeatureLayer layer, RenderPhase phase) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap.Presentation\WinForms\MapPresenter.cs:line 107
   at SharpMap.Presentation.Presenters.MapPresenter2D.RenderLayer(ILayer layer, RenderPhase phase) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Presentation\Presenters\MapPresenter2D.cs:line 878
   at SharpMap.Presentation.Presenters.MapPresenter2D.RenderLayer(ILayer layer) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Presentation\Presenters\MapPresenter2D.cs:line 832
   at SharpMap.Presentation.Presenters.MapPresenter2D.NotifyLayersChanged(ListChangedType listChangedType, Int32 oldIndex, Int32 newIndex, PropertyDescriptor propertyDescriptor) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Presentation\Presenters\MapPresenter2D.cs:line 667
   at SharpMap.Presentation.Presenters.MapLayersListenerPresenter`1.handleLayersChanged(Object sender, ListChangedEventArgs e) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Presentation\Presenters\MapLayersListenerPresenter.cs:line 59
   at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)
   at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
   at SharpMap.Layers.LayerCollection.OnListChanged(ListChangedEventArgs e) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Layers\LayerCollection.cs:line 284
   at System.ComponentModel.BindingList`1.InsertItem(Int32 index, T item)
   at SharpMap.Layers.LayerCollection.InsertItem(Int32 index, ILayer item) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Layers\LayerCollection.cs:line 256
   at System.Collections.ObjectModel.Collection`1.Add(T item)
   at SharpMap.Map.AddLayer(ILayer layer) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Map.cs:line 253
   at TesteV2.Form1.button1_Click(Object sender, EventArgs e) in E:\_projs\comum\dotNet\SharpMapV2\testes\TesteV2\Form1.cs:line 44
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.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(Int32 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 System.Windows.Forms.Application.Run(Form mainForm)
   at TesteV2.Program.Main() in E:\_projs\comum\dotNet\SharpMapV2\testes\TesteV2\Program.cs:line 15
   at System.AppDomain._nExecuteAssembly(Assembly 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)
   at System.Threading.ThreadHelper.ThreadStart()


My code is:
    Map _map;
    IGeometryFactory<BufferedCoordinate2D> _geometryFactory;
    ICoordinateSystemFactory _CSFactory;
    int idx = 0;

    public Form1() {
      InitializeComponent();
      ICoordinateSequenceFactory<BufferedCoordinate2D> coordSeqFactory =
          new BufferedCoordinate2DSequenceFactory();
      _geometryFactory = new GeometryFactory<BufferedCoordinate2D>(coordSeqFactory);
      _map = new Map(_geometryFactory);
      mapViewControl1.Map = _map;

      _CSFactory = new CoordinateSystemFactory<BufferedCoordinate2D>(_geometryFactory.CoordinateFactory, _geometryFactory);
    }

    private void button1_Click(object sender, EventArgs e) {
      ShapeFileProvider shapeFileData = new ShapeFileProvider(@"E:\DadosOeiras\Shapes\ALocInt.shp", _geometryFactory, _CSFactory, true);
      GeometryLayer shapeFileLayer = new GeometryLayer("xx"+(idx++), shapeFileData);
      shapeFileLayer.Enabled = true;
      shapeFileLayer.Style.Fill.Color = StyleColor.Blue;
      _map.AddLayer(shapeFileLayer);
    }

Please give some hint on what is wrong.

Thanks in Advace.
Pedro Duarte
Coordinator
Sep 16, 2008 at 12:11 PM
try adding at least one layer to the map before assigning the map to the mapviewcontrol
HTH FObermaier