public SharpMap.Data.FeatureDataRow FindGeoNearPoint(SharpMap.Geometries.Point pos, double amountGrow, ref double DistanceToSelected) { SharpMap.Geometries.BoundingBox bbox = pos.GetBoundingBox().Grow(amountGrow); SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet(); DataSource.ExecuteIntersectionQuery(bbox, ds); System.Data.DataTable tbl = ds.Tables[0] as SharpMap.Data.FeatureDataTable; GisSharpBlog.NetTopologySuite.IO.WKTReader reader = new GisSharpBlog.NetTopologySuite.IO.WKTReader(); GeoAPI.Geometries.IGeometry point = reader.Read(pos.ToString()); if (tbl.Rows.Count == 0) return null; double distance = point.Distance(reader.Read((tbl.Rows[0] as SharpMap.Data.FeatureDataRow).Geometry.ToString())); SharpMap.Data.FeatureDataRow selectedFeature = tbl.Rows[0] as SharpMap.Data.FeatureDataRow; if (tbl.Rows.Count > 1) for (int i = 1; i < tbl.Rows.Count; i++) { GeoAPI.Geometries.IGeometry line = reader.Read((tbl.Rows[i] as SharpMap.Data.FeatureDataRow).Geometry.ToString()); if (point.Distance(line) < distance) { distance = point.Distance(line); selectedFeature = tbl.Rows[i] as SharpMap.Data.FeatureDataRow; } } DistanceToSelected = distance; return selectedFeature; }
void mapBox1_GeometryDefined(SharpMap.Geometries.Geometry geometry) { MessageBox.Show("Geometry defined!\r\n"+geometry.ToString()); geoProvider.Geometries.Add(geometry); this.mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; this.mapBox1.Refresh(); }