CUAHSI / HydroDesktop

HydroDesktop is a free and open source GIS enabled desktop application that helps you search for, download, visualize, and analyze hydrologic and climate data registered with the CUAHSI Hydrologic Information System. HydroDesktop is part of the legacy CUAHSI toolkit and is not under active development. Click the "releases" link below to download the latest installer for Microsoft Windows.
73 stars 20 forks source link

NRE Exception in SearchLayerModifier #43

Open xhqiao89 opened 7 years ago

xhqiao89 commented 7 years ago

jirikadlec2[CodePlex]
I was testing the data export and selection functionality and found the following exception:

Steps to duplicate:

In search, select area - countries - USA and Data Sources - Christina River Critical Zone Observatory select some sites and download data Use the Map tab select tool to select one site with downloaded data in the map Right - click on the Christina River Basin Critical Zone Observatory and choose Data - Export Data in the context menu In the dialog choose quotSelecte featuresquot option, click OK Click OK in the Do you want to load the shapefile? message The unhandled exception is shown:

** Exception Text ** System.NullReferenceException: Object reference not set to an instance of an object.

at HydroDesktop.DataDownload.SearchLayersProcessing.SearchLayerModifier.UpdateSymbolizing(IFeatureLayer layer) in F:\dev\HydroDesktop\Source\DataDownload\DataDownload\SearchLayersProcessing\SearchLayerModifier.cs:line 262

at HydroDesktop.DataDownload.SearchLayersProcessing.SearchLayerModifier.AddCustomFeaturesToSearchLayer(IFeatureLayer layer) in F:\dev\HydroDesktop\Source\DataDownload\DataDownload\SearchLayersProcessing\SearchLayerModifier.cs:line 81

at HydroDesktop.DataDownload.DataDownloadPlugin.AttachLayerToPlugin(ILayer layer) in F:\dev\HydroDesktop\Source\DataDownload\DataDownload\DataDownloadPlugin.cs:line 201

at HydroDesktop.DataDownload.DataDownloadPlugin.Map_LayerAdded(Object sender, LayerEventArgs e) in F:\dev\HydroDesktop\Source\DataDownload\DataDownload\DataDownloadPlugin.cs:line 190

at DotSpatial.Symbology.Group.OnLayerAdded(Object sender, LayerEventArgs e) in F:\dev\DotSpatial\DotSpatial.Symbology\Group.cs:line 602

at DotSpatial.Symbology.Group.Layers_LayerAdded(Object sender, LayerEventArgs e) in F:\dev\DotSpatial\DotSpatial.Symbology\Group.cs:line 592

at DotSpatial.Symbology.LayerEventList1.OnLayerAdded(Object sender, LayerEventArgs e) in F:\dev\DotSpatial\DotSpatial.Symbology\LayerEventList.cs:line 305

at DotSpatial.Symbology.LayerEventList1.OnIncludeComplete(T item) in F:\dev\DotSpatial\DotSpatial.Symbology\LayerEventList.cs:line 186

at DotSpatial.Serialization.BaseList`1.DoInsert(Int32 index, T item) in F:\dev\DotSpatial\DotSpatial.Serialization\BaseList.cs:line 122

at DotSpatial.Controls.MapLayerCollection.Insert(Int32 index, IMapLayer item) in F:\dev\DotSpatial\DotSpatial.Controls\MapLayerCollection.cs:line 297

at DotSpatial.Controls.MapGroup.Insert(Int32 index, ILayer layer) in F:\dev\DotSpatial\DotSpatial.Controls\MapGroup.cs:line 181

at DotSpatial.Symbology.Forms.FeatureLayerEventReceiver.LoadFeatureSetAsLayer(FeatureLayerEventArgs e, FeatureSet fs, String newLayerName) in F:\dev\DotSpatial\DotSpatial.Symbology.Forms\FeatureLayerEventReceiver.cs:line 113

at DotSpatial.Symbology.Forms.FeatureLayerEventReceiver.ExportDataClicked(Object sender, FeatureLayerEventArgs e) in F:\dev\DotSpatial\DotSpatial.Symbology.Forms\FeatureLayerEventReceiver.cs:line 152

at DotSpatial.Symbology.FeatureLayerEventSender.Raise_ExportData(Object sender, FeatureLayerEventArgs e) in F:\dev\DotSpatial\DotSpatial.Symbology\FeatureLayerEventSender.cs:line 138

at DotSpatial.Symbology.FeatureLayer.OnExportData() in F:\dev\DotSpatial\DotSpatial.Symbology\FeatureLayer.cs:line 2086

at DotSpatial.Symbology.Layer.ExportDataClick(Object sender, EventArgs e) in F:\dev\DotSpatial\DotSpatial.Symbology\Layer.cs:line 425

at System.Windows.Forms.MenuItem.OnClick(EventArgs e) at System.Windows.Forms.MenuItem.MenuItemData.Execute() at System.Windows.Forms.Command.Invoke() at System.Windows.Forms.Command.DispatchID(Int32 id) at System.Windows.Forms.Control.WmCommand(Messageamp m) at System.Windows.Forms.Control.WndProc(Messageamp m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Messageamp m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Messageamp m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr

xhqiao89 commented 7 years ago

cuylerfris[CodePlex]
marking as active

xhqiao89 commented 7 years ago

jirikadlec2[CodePlex]
DotSpatial bug, still present in DotSpatial 1.2. Using Export data menu is not a common task, therefore moving this item to version 2.0

The workaround is not to add the exported layer to the map, but to save it as a shapefile and then add the shapefile to the map.

xhqiao89 commented 7 years ago

jirikadlec2[CodePlex]
More detailed testing has shown that this is a bug in HydroDesktop. occurring when calling SelectByAttribute() LayerAdded event handler of the DataDownload plugin. When DataDownload plugin is deactivated, this exception doesn't occur. Detailed examination is required to find out which method or property is being accessed by HydroDesktop.

xhqiao89 commented 7 years ago

jirikadlec2[CodePlex]
attached is the file searchresult_czo_udel. To duplicate this bug: Add searchresult_czo_udel to the map, select all features and choose Data - Export Data with Selected Features option.

xhqiao89 commented 7 years ago

jirikadlec2[CodePlex]
Testing with HydroDesktop 1.3.247. KeyNotFound exception occurs:

** Exception Text ** System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

at System.Collections.Generic.Dictionary2.get_Item(TKey key) at DotSpatial.Data.FeatureSet.SelectByAttributeb__3(DataRow dr) at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() at System.Collections.Generic.List1.InsertRange(Int32 index, IEnumerable1 collection)

at DotSpatial.Data.FeatureSet.SelectByAttribute(String filterExpression) at DotSpatial.Symbology.LabelLayer.CreateLabels() at DotSpatial.Controls.Map.AddLabels(IFeatureLayer featureLayer, String expression, String filterExpression, ILabelSymbolizer symbolizer, String name)

at HydroDesktop.DataDownload.SearchLayersProcessing.SearchLayerModifier.SetUpLabeling(IFeatureLayer layer, IMap map) in g:\TeamCity\buildAgent\work\f7ff7e4eb69f4f40\Source\DataDownload\DataDownload\SearchLayersProcessing\SearchLayerModifier.cs:line 256

at HydroDesktop.DataDownload.SearchLayersProcessing.SearchLayerModifier.AddCustomFeaturesToSearchLayer(IFeatureLayer layer) in g:\TeamCity\buildAgent\work\f7ff7e4eb69f4f40\Source\DataDownload\DataDownload\SearchLayersProcessing\SearchLayerModifier.cs:line 70

at HydroDesktop.DataDownload.DataDownloadPlugin.AttachLayerToPlugin(ILayer layer, Boolean addCustomFeatures) in g:\TeamCity\buildAgent\work\f7ff7e4eb69f4f40\Source\DataDownload\DataDownload\DataDownloadPlugin.cs:line 212

at HydroDesktop.DataDownload.DataDownloadPlugin.Map_LayerAdded(Object sender, LayerEventArgs e) in g:\TeamCity\buildAgent\work\f7ff7e4eb69f4f40\Source\DataDownload\DataDownload\DataDownloadPlugin.cs:line 192

at System.EventHandler1.Invoke(Object sender, TEventArgs e) at DotSpatial.Symbology.Group.OnLayerAdded(Object sender, LayerEventArgs e) at DotSpatial.Symbology.Group.Layers_LayerAdded(Object sender, LayerEventArgs e) at DotSpatial.Symbology.LayerEventList1.OnLayerAdded(Object sender, LayerEventArgs e)

at DotSpatial.Symbology.LayerEventList1.OnIncludeComplete(T item) at DotSpatial.Serialization.BaseList1.DoInsert(Int32 index, T item) at DotSpatial.Controls.MapLayerCollection.Insert(Int32 index, IMapLayer item) at DotSpatial.Controls.MapGroup.Insert(Int32 index, ILayer layer) at DotSpatial.Symbology.Forms.FeatureLayerEventReceiver.LoadFeatureSetAsLayer(FeatureLayerEventArgs e, FeatureSet fs, String newLayerName)

at DotSpatial.Symbology.Forms.FeatureLayerEventReceiver.ExportDataClicked(Object sender, FeatureLayerEventArgs e)

at DotSpatial.Symbology.FeatureLayerEventSender.Raise_ExportData(Object sender, FeatureLayerEventArgs e)

at DotSpatial.Symbology.FeatureLayer.OnExportData() at DotSpatial.Symbology.Layer.ExportDataClick(Object sender, EventArgs e) at System.Windows.Forms.MenuItem.OnClick(EventArgs e) at System.Windows.Forms.MenuItem.MenuItemData.Execute() at System.Windows.Forms.Command.Invoke() at System.Windows.Forms.Command.DispatchID(Int32 id) at System.Windows.Forms.Control.WmCommand(Message m) 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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

xhqiao89 commented 7 years ago

jirikadlec2[CodePlex]
Tested with DotSpatial 20b9dcec9edc. This is still an issue. The NRE exception is no longer thrown, but no points are shown on the map (I can only see the new layer in the legend) and when I view attribute table the exported shapefile doesn't have any rows.

xhqiao89 commented 7 years ago

mudnug[CodePlex]
Please verify DotSpatial changeset 20b9dcec9edc fixes your issue.

xhqiao89 commented 7 years ago

mogikanin[CodePlex]
Reproduced by steps from issue. In this case property DotSpatial.Data.FeatureSet.FeatureLookup is null, and exception thrown.

Looks like DS bug (in DotSpatial.Data.FeatureSet).

Probably this instance of DotSpatial.Data.FeatureSet is created using one of constructors: FeatureSet(IListIFeature inFeatures) or FeatureSet(DataTable wkbTable, int wkbColumnIndex, bool indexed, FeatureType type)

In these cases DotSpatial.Data.FeatureSet.Configure() method doesn't executes.