This project has moved. For the latest updates, please go here.

Multiple Selection

Topics: SharpMap v2.0, WinForms Controls
Jun 18, 2012 at 8:52 AM


I've got a little query tool that highlights a feature when it's clicked - use a second layer to do this.   Using the UI tools MapQueried event.

I now want to have the option to add to that selection (i.e. by clicking one feature after another to build up a selection) - effectively a multiple selection tool.

Have tried various ideas but no success yet - I essentially want to copy from the featuredatatable returned in the MapQueried event to a global featuredatalayer and then apply it back to my layer but copying rows between tables does not seem possible - has any one any ideas or sample code ?


Jun 18, 2012 at 9:10 AM
Edited Jun 18, 2012 at 9:13 AM


I add FeatureDataSet _datasetSelected to MapImage ( now is Mapbox ) and in moveup add code follow: 
It support ctrl to remove or get new features to _datasetSelected.My application use old version of sharpmap 0.9



if (this.ActiveTool == Tools.MultiQuery) { _selectedRows.Clear(); if (LayerEdit != null) { SharpMap.Layers.VectorLayer layer = LayerEdit; //PIGIS.Algorithms.Algorithm al = new PIGIS.Algorithms.Algorithm(); //SharpMap.Data.FeatureDataRow row = al.FindGeoNearPoint(this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)), layer, _Map.PixelSize * _pixelSeleted); SharpMap.Geometries.BoundingBox bounding; if (mousedragging) { SharpMap.Geometries.Point lowerLeft; SharpMap.Geometries.Point upperRight; GetBounds(_Map.ImageToWorld(_dragStartPoint), _Map.ImageToWorld(_dragEndPoint), out lowerLeft, out upperRight); bounding = new SharpMap.Geometries.BoundingBox(lowerLeft, upperRight); } else { bounding = _Map.ImageToWorld(new Point(e.X, e.Y)).GetBoundingBox().Grow(_Map.PixelSize * _pixelSeleted); } SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet(); layer.DataSource.Open(); layer.DataSource.ExecuteIntersectionQuery(bounding, ds); layer.DataSource.Close(); if (ds.Tables.Count > 0) { if (_isCtrlPressed == false || _datasetSelected.Tables.Count<=0) { _datasetSelected = ds; _datasetSelected.Tables[0].TableName = layer.LayerName; } else { DataTable oldTable = _datasetSelected.Tables[0]; DataTable tb = ds.Tables[0]; // set primary key DataColumn[] keys = new DataColumn[1]; keys[0] = oldTable.Columns[layer.DataSource.ObjectIdColumn]; oldTable.PrimaryKey = keys; for (int i = 0; i < tb.Rows.Count; i++) { DataRow rowFind = oldTable.Rows.Find(tb.Rows[i][layer.DataSource.ObjectIdColumn]); if (rowFind != null) { oldTable.Rows.Remove(rowFind); } else { SharpMap.Data.FeatureDataRow fRow = tb.Rows[i] as SharpMap.Data.FeatureDataRow; SharpMap.Data.FeatureDataRow fdr = _datasetSelected.Tables[0].NewRow(); foreach (System.Data.DataColumn col in _datasetSelected.Tables[0].Columns) fdr[col.ColumnName] = fRow[col.ColumnName]; fdr.Geometry = fRow.Geometry; (oldTable as SharpMap.Data.FeatureDataTable).AddRow(fdr); } } //this.Refresh(); } if (MapQueriedDataSet != null) MapQueriedDataSet(ds); else if (MapQueriedDataSet != null) MapQueriedDataSet(null); } } else MessageBox.Show("Start edit layer to query"); }
Jun 18, 2012 at 9:58 AM

That's really helpful thank you!

I'd tried various similar things but hadn't realised that I had to explicitly copy the geometry - so this was a great pointer.

Much appreciated