Errors reading Shapefile in V2

Topics: Data Access, SharpMap v2.0, WinForms Controls
Sep 22, 2008 at 11:57 AM
I´m writing a simple application with V2.0 rev397 that opens and displays a shapefile.

First Case :

      ShapeFileProvider shapeFileData = new ShapeFileProvider(@"E:\dados\maqueteOeiras\DadosVectoriais\pdm_co_m.shp", _geometryFactory, _CSFactory, true);
      GeometryLayer gl = new GeometryLayer("xx" + (idx++), shapeFileData);
      gl.Style.AreFeaturesSelectable = true;
      gl.Style.Enabled = true;
      gl.Style.EnableOutline = true;
     .... define the style
     .... add layer to map
The application throws this exception : An attempt was made to access a closed data source.

Second Case :
      ShapeFileProvider shapeFileData = new ShapeFileProvider(@"E:\dados\maqueteOeiras\DadosVectoriais\pdm_co_m.shp", _geometryFactory, _CSFactory, true);
      shapeFileData.Open();
      shapeFileData.Close();
      GeometryLayer gl = new GeometryLayer("xx" + (idx++), shapeFileData);
      gl.Style.AreFeaturesSelectable = true;
      gl.Style.Enabled = true;
      gl.Style.EnableOutline = true;
     .... define the style
     .... add layer to map
The layer draws correctly but when the map is clicked to zoomin, the following exception occurs :

Can't open another ShapeFileDataReader on this ShapeFile, since another reader is already active.

   at SharpMap.Data.Providers.AsyncResult.EndInvoke() in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Data\Providers\AsyncResult.cs:line 104
   at SharpMap.Data.Providers.AsyncResult`1.EndInvoke() in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Data\Providers\AsyncResult`1.cs:line 38
   at SharpMap.Data.Providers.AsyncFeatureProviderAdapter.EndExecuteQuery(IAsyncResult asyncResult) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Data\Providers\AsyncFeatureProviderAdapter.cs:line 69
   at SharpMap.Layers.Layer.LoadLayerData(QueryExpression query) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Layers\Layer.cs:line 582
   at SharpMap.Layers.FeatureLayer.handleFeaturesSelectRequested(Object sender, SelectRequestedEventArgs e) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Layers\FeatureLayer.cs:line 305
   at SharpMap.Data.FeatureDataTable.OnSelectRequested(FeatureQueryExpression query) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Data\FeatureDataTable.cs:line 785
   at SharpMap.Data.FeatureDataTable.<Select>d__f.MoveNext() in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Data\FeatureDataTable.cs:line 692
   at SharpMap.Presentation.Presenters.MapPresenter2D.RenderFeatureLayer(IFeatureLayer layer, RenderPhase phase) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Presentation\Presenters\MapPresenter2D.cs:line 932
   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.Presenters.MapPresenter2D.RenderAllLayers() in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Presentation\Presenters\MapPresenter2D.cs:line 822
   at SharpMap.Presentation.Presenters.MapPresenter2D.setViewMetricsInternal(Size2D newViewSize, ICoordinate newCenter, Double newWorldWidth) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Presentation\Presenters\MapPresenter2D.cs:line 1385
   at SharpMap.Presentation.Presenters.MapPresenter2D.setViewEnvelopeInternal(IExtents2D newEnvelope) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Presentation\Presenters\MapPresenter2D.cs:line 1302
   at SharpMap.Presentation.Presenters.MapPresenter2D.ZoomToViewBoundsInternal(Rectangle2D viewBounds) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Presentation\Presenters\MapPresenter2D.cs:line 589
   at SharpMap.Presentation.Presenters.MapPresenter2D.handleViewZoomToViewBoundsRequested(Object sender, MapViewPropertyChangeEventArgs`1 e) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Presentation\Presenters\MapPresenter2D.cs:line 1141
   at SharpMap.Presentation.WinForms.MapViewControl.onRequestZoomToViewBounds(Rectangle2D viewBounds) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap.Presentation\WinForms\MapViewControl.cs:line 1027
   at SharpMap.Presentation.WinForms.MapViewControl.ZoomToViewBounds(Rectangle2D viewBounds) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap.Presentation\WinForms\MapViewControl.cs:line 395
   at SharpMap.Tools.StandardMapView2DMapTools.zoomByFactor(ActionContext`2 context, Double zoomFactor) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Tools\StandardMapTools2D.cs:line 419
   at SharpMap.Tools.StandardMapView2DMapTools.EndZoomIn(ActionContext`2 context) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Tools\StandardMapTools2D.cs:line 168
   at SharpMap.Presentation.Presenters.MapPresenter2D.handleViewEndAction(Object sender, MapActionEventArgs`1 e) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap\Presentation\Presenters\MapPresenter2D.cs:line 1075
   at SharpMap.Presentation.WinForms.MapViewControl.onEndAction(Point2D actionLocation) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap.Presentation\WinForms\MapViewControl.cs:line 890
   at SharpMap.Presentation.WinForms.MapViewControl.OnMouseUp(MouseEventArgs e) in E:\_projs\comum\dotNet\SharpMapV2\SharpMap\SharpMap.Presentation\WinForms\MapViewControl.cs:line 517
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.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 TesteV2a.Program.Main() in E:\_projs\comum\dotNet\SharpMapV2\testes\TesteV2a\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()

Thanks in advance
Pedro Duarte
Coordinator
Sep 22, 2008 at 12:43 PM
Please look in this thread:
http://www.codeplex.com/SharpMap/Thread/View.aspx?ThreadId=19211&ANCHOR#Post114097
HTH
FObermaier