/// <summary> /// This method takes a pre-populated FeatureDataTable and removes rows that do not truly intersect testGeometry /// </summary> /// <param name="featureDataTable">The FeatureDataTable instance to filter</param> /// <param name="testGeometry">the geometry to compare against</param> public void PostFilterExistingFeatureDataTable(FeatureDataTable featureDataTable, SMGeometry testGeometry) { //first we create a new GeometryFactory. var geometryFactory = new GeometryFactory(); //then we convert the testGeometry into the equivalent NTS geometry GeoAPI.Geometries.IGeometry testGeometryAsNtsGeom = GeometryConverter.ToNTSGeometry(testGeometry, geometryFactory); //now we loop backwards through the FeatureDataTable for (int i = featureDataTable.Rows.Count - 1; i > -1; i--) { //we get each row FeatureDataRow featureDataRow = featureDataTable.Rows[i] as FeatureDataRow; //and get the rows' geometry SMGeometry compareGeometry = featureDataRow.Geometry; //convert the rows' geometry into the equivalent NTS geometry GeoAPI.Geometries.IGeometry compareGeometryAsNts = GeometryConverter.ToNTSGeometry(compareGeometry, geometryFactory); //now test for intesection (note other operations such as Contains, Within, Disjoint etc can all be done the same way) bool intersects = testGeometryAsNtsGeom.Intersects(compareGeometryAsNts); //if it doesn't intersect remove the row. if (!intersects) { featureDataTable.Rows.RemoveAt(i); } } }
/// <summary> /// Builds from the given provider. /// </summary> /// <param name="provider"> /// The base <see cref="SharpMap.Data.Providers.IProvider"/> /// from witch initialize the <see cref="NtsProvider"/> instance. /// </param> private void BuildFromProvider(IProvider provider) { // Features list initialization _features = new List <Feature>(provider.GetFeatureCount()); try { // Load all features from the given provider provider.Open(); Collection <uint> ids = provider.GetObjectIDsInView(provider.GetExtents()); foreach (uint id in ids) { FeatureDataRow dataRow = provider.GetFeature(id); GeoAPI.Geometries.IGeometry geometry = GeometryConverter.ToNTSGeometry(dataRow.Geometry, _geometryFactory); AttributesTable attributes = new AttributesTable(); foreach (DataColumn column in dataRow.Table.Columns) { if (dataRow[column] == null || dataRow[column] is DBNull) { throw new ApplicationException("Null values not supported"); } attributes.AddAttribute(column.ColumnName, dataRow[column]); } _features.Add(new Feature(geometry, attributes)); } } finally { if (provider.IsOpen) { provider.Close(); } } }
public FrameworkElement GetCustomNode() { var textBlock = new TextBlock() { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; textBlock.SetBinding(TextBlock.TextProperty, new Binding() { Path = new PropertyPath("NodeName") }); var ui = new Path(); ui.Stroke = Brushes.Black; ui.StrokeThickness = 0.5; ui.Fill = Brushes.Pink; var converter = new GeometryConverter(); ui.Data = (Geometry)converter.ConvertFrom(NodeStyle["Geometry"]); ui.Stretch = Stretch.Uniform; var grid = new Grid(); grid.Children.Add(ui); grid.Children.Add(textBlock); return(grid); }
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes) { if (drawingContext == null) { throw new ArgumentNullException("drawingContext"); } if (null == drawingAttributes) { throw new ArgumentNullException("drawingAttributes"); } Pen pen = new Pen { StartLineCap = PenLineCap.Round, EndLineCap = PenLineCap.Round, Brush = new SolidColorBrush(drawingAttributes.Color), Thickness = drawingAttributes.Width }; BrushConverter bc = new BrushConverter(); Brush BackGround = (Brush)bc.ConvertFromString(drawingAttributes.GetPropertyData(DrawAttributesGuid.BackgroundColor).ToString()); GeometryConverter gc = new GeometryConverter(); Geometry geometry = (Geometry)gc.ConvertFromString(string.Format("M {0},{1} {2},{3} {4},{5} Z", StylusPoints[0].X, StylusPoints[1].Y, (Math.Abs(StylusPoints[1].X - StylusPoints[0].X)) / 2 + StylusPoints[0].X, StylusPoints[0].Y, StylusPoints[1].X, StylusPoints[1].Y)); GeometryDrawing gd = new GeometryDrawing(BackGround, pen, geometry); drawingContext.DrawDrawing(gd); }
/// <summary> /// Gets the geometry by ID. /// </summary> /// <param name="oid">The oid.</param> /// <returns></returns> public Geometry GetGeometryByID(uint oid) { Feature feature = _features[Convert.ToInt32(oid)]; return (GeometryConverter.ToSharpMapGeometry( feature.Geometry as NtsGeometry)); }
/// <summary> /// Gets the geometry by ID. /// </summary> /// <param name="oid">The oid.</param> /// <returns></returns> public Geometry GetGeometryByID(uint oid) { Feature feature = features[Convert.ToInt32(oid)]; return (GeometryConverter.ToSharpMapGeometry( feature.Geometry as GisSharpBlog.NetTopologySuite.Geometries.Geometry)); }
/// <summary> /// Returns the BoundingBox of the dataset. /// </summary> /// <returns>BoundingBox</returns> public SharpMap.Geometries.BoundingBox GetExtents() { GisSharpBlog.NetTopologySuite.Geometries.Envelope envelope = new GisSharpBlog.NetTopologySuite.Geometries.Envelope(); foreach (GisSharpBlog.NetTopologySuite.Features.Feature feature in features) { envelope.ExpandToInclude(feature.Geometry.EnvelopeInternal); } return(GeometryConverter.ToSharpMapBoundingBox(envelope)); }
/// <summary> /// Creates a new row in the given <see cref="SharpMap.Data.FeatureDataTable"/> <paramref name="dataTable"/> /// using data in <see cref="GisSharpBlog.NetTopologySuite.Features.Feature"/> <paramref name="feature"/>. /// </summary> /// <param name="dataTable">The <see cref="SharpMap.Data.FeatureDataTable"/> to fill.</param> /// <param name="feature">Data to insert in the <see cref="SharpMap.Data.FeatureDataTable"/>.</param> private void CreateNewRow(SharpMap.Data.FeatureDataTable dataTable, GisSharpBlog.NetTopologySuite.Features.Feature feature) { SharpMap.Data.FeatureDataRow dataRow = dataTable.NewRow(); dataRow.Geometry = GeometryConverter.ToSharpMapGeometry(feature.Geometry as GisSharpBlog.NetTopologySuite.Geometries.Geometry); foreach (string columnName in feature.Attributes.GetNames()) { dataRow[columnName] = feature.Attributes[columnName]; } dataTable.AddRow(dataRow); }
/// <summary> /// Returns the BoundingBox of the dataset. /// </summary> /// <returns>BoundingBox</returns> public BoundingBox GetExtents() { Envelope envelope = new Envelope(); foreach (Feature feature in _features) { envelope.ExpandToInclude(feature.Geometry.EnvelopeInternal); } return(GeometryConverter.ToSharpMapBoundingBox(envelope)); }
private static Style GetDefaultStyle() { Style style = new Style(typeof(MultiSliderThumb)); ControlTemplate controlTemplate = new ControlTemplate(typeof(MultiSliderThumb)); style.Setters.Add((SetterBase) new Setter(Control.TemplateProperty, (object)controlTemplate)); Brush brush = MultiSliderThumb.MakeCheckerboardBrush(MultiSliderThumb.checkerboardSize); style.Setters.Add((SetterBase) new Setter(Control.BackgroundProperty, (object)brush)); FrameworkElementFactory frameworkElementFactory = new FrameworkElementFactory(typeof(Canvas), "mainCanvas"); controlTemplate.VisualTree = frameworkElementFactory; GeometryConverter geometryConverter = new GeometryConverter(); FrameworkElementFactory child1 = new FrameworkElementFactory(typeof(Path), "outerPath"); child1.SetValue(Shape.FillProperty, (object)Brushes.White); child1.SetValue(Shape.StrokeProperty, (object)Brushes.Black); child1.SetValue(Shape.StrokeThicknessProperty, (object)1.0); child1.SetValue(Shape.StrokeLineJoinProperty, (object)PenLineJoin.Round); child1.SetValue(Path.DataProperty, geometryConverter.ConvertFromInvariantString("M 0 8 L 8 0 L 16 8 L 16 20 L 0 20 Z")); child1.SetValue(Canvas.TopProperty, (object)12.0); child1.SetValue(Canvas.LeftProperty, (object)-8.0); frameworkElementFactory.AppendChild(child1); FrameworkElementFactory child2 = new FrameworkElementFactory(typeof(Path), "innerPath"); child2.SetValue(Shape.FillProperty, (object)Brushes.Black); child2.SetValue(Shape.StrokeProperty, (object)Brushes.Black); child2.SetValue(UIElement.VisibilityProperty, (object)Visibility.Hidden); child2.SetValue(Shape.StrokeThicknessProperty, (object)1.0); child2.SetValue(Shape.StrokeLineJoinProperty, (object)PenLineJoin.Round); child2.SetValue(Path.DataProperty, geometryConverter.ConvertFromInvariantString("M 3 0 L 6 3 L 0 3 Z")); child2.SetValue(Canvas.TopProperty, (object)15.0); child2.SetValue(Canvas.LeftProperty, (object)-3.0); frameworkElementFactory.AppendChild(child2); FrameworkElementFactory child3 = new FrameworkElementFactory(typeof(Rectangle), "innerRectangle"); child3.SetValue(Shape.FillProperty, (object)new TemplateBindingExtension(Control.ForegroundProperty)); child3.SetValue(Shape.FillProperty, (object)Brushes.Blue); child3.SetValue(Shape.StrokeProperty, (object)Brushes.Black); child3.SetValue(Shape.StrokeThicknessProperty, (object)0.25); child3.SetValue(Shape.StrokeLineJoinProperty, (object)PenLineJoin.Round); child3.SetValue(FrameworkElement.WidthProperty, (object)12.0); child3.SetValue(FrameworkElement.HeightProperty, (object)8.0); child3.SetValue(Canvas.TopProperty, (object)21.0); child3.SetValue(Canvas.LeftProperty, (object)-6.0); frameworkElementFactory.AppendChild(child3); Trigger trigger = new Trigger(); trigger.Property = Selector.IsSelectedProperty; trigger.Value = (object)true; trigger.Setters.Add((SetterBase) new Setter(UIElement.VisibilityProperty, (object)Visibility.Visible, "innerPath")); trigger.Setters.Add((SetterBase) new Setter(Shape.StrokeThicknessProperty, (object)2.0, "outerPath")); controlTemplate.Triggers.Add((TriggerBase)trigger); return(style); }
private void ReprojectButton_Click(object sender, EventArgs e) { var geometryConverter = new GeometryConverter(); var sourceWkt = SourceWktTextBox.Text; var reprojectedWkt = geometryConverter.ReprojectGeometry( sourceWkt, Proj4_4326, Proj4_31462); DestinationWktTextBox.Text = reprojectedWkt; }
/// <summary> Gets the geometry from string. /// </summary> /// <param name="text">The text.</param> /// <returns></returns> public static Geometry GetGeometry(string text) { if (String.IsNullOrEmpty(text)) { return(null); } if (text.StartsWith(GeometryType.Path.ToString(), StringComparison.Ordinal)) { string content = text.Substring(GeometryType.Path.ToString().Length + 1); GeometryConverter conv = new GeometryConverter(); StreamGeometry streamGeometry = (StreamGeometry)conv.ConvertFrom(content); PathGeometry geometry = streamGeometry.GetFlattenedPathGeometry(); return(geometry); } else if (text.StartsWith(GeometryType.Rectangle.ToString(), StringComparison.Ordinal)) { string content = text.Substring(GeometryType.Rectangle.ToString().Length + 1); string[] contents = content.Split(','); RectangleGeometry geometry = new RectangleGeometry(); geometry.Rect = new Rect(Convert.ToDouble(contents[0], enUS), Convert.ToDouble(contents[1], enUS), Convert.ToDouble(contents[2], enUS), Convert.ToDouble(contents[3], enUS) ); return(geometry); } else if (text.StartsWith(GeometryType.Ellipse.ToString(), StringComparison.Ordinal)) { string content = text.Substring(GeometryType.Ellipse.ToString().Length + 1); string[] contents = content.Split(','); EllipseGeometry geometry = new EllipseGeometry(); geometry.Center = new Point(Convert.ToDouble(contents[0], enUS) + Convert.ToDouble(contents[2], enUS) / 2.0, Convert.ToDouble(contents[1], enUS) + Convert.ToDouble(contents[3], enUS) / 2.0); geometry.RadiusX = Convert.ToDouble(contents[2], enUS) / 2.0; geometry.RadiusY = Convert.ToDouble(contents[3], enUS) / 2.0; return(geometry); } else if (text.StartsWith("Text:", StringComparison.Ordinal)) { string content = text.Substring("Text:".Length); string[] contents = content.Split(','); RectangleGeometry geometry = new RectangleGeometry(); geometry.Rect = new Rect(Convert.ToDouble(contents[0], enUS), Convert.ToDouble(contents[1], enUS), Convert.ToDouble(contents[2], enUS), Convert.ToDouble(contents[3], enUS) ); return(geometry); } else { throw new InvalidOperationException("This is not a valid geometry object in string"); } }
/// <summary> /// Creates a new row in the given <see cref="SharpMap.Data.FeatureDataTable"/> <paramref name="dataTable"/> /// using data in <see cref="NetTopologySuite.Features.Feature"/> <paramref name="feature"/>. /// </summary> /// <param name="dataTable">The <see cref="SharpMap.Data.FeatureDataTable"/> to fill.</param> /// <param name="feature">Data to insert in the <see cref="SharpMap.Data.FeatureDataTable"/>.</param> private static void CreateNewRow(FeatureDataTable dataTable, Feature feature) { FeatureDataRow dataRow = dataTable.NewRow(); dataRow.Geometry = GeometryConverter.ToSharpMapGeometry(feature.Geometry as NtsGeometry); foreach (string columnName in feature.Attributes.GetNames()) { dataRow[columnName] = feature.Attributes[columnName]; } dataTable.AddRow(dataRow); }
private ModernButton GetBackButton() { GeometryConverter geomConvert = new GeometryConverter(); Geometry iconData = (Geometry)geomConvert.ConvertFromString("F1 M 57,42L 57,34L 32.25,34L 42.25,24L 31.75,24L 17.75,38L 31.75,52L 42.25,52L 32.25,42L 57,42 Z "); ModernButton buttonBack = new ModernButton(); buttonBack.EllipseDiameter = 30; buttonBack.IconHeight = 20; buttonBack.IconWidth = 20; buttonBack.ToolTip = "Atrás"; buttonBack.IconData = iconData; buttonBack.IsEnabled = false; return(buttonBack); }
/// <summary> /// /// </summary> /// <param name="geom"></param> /// <param name="ds"></param> public void ExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds) { GeoAPI.Geometries.IGeometry geometry = GeometryConverter.ToNTSGeometry(geom, _geometryFactory); FeatureDataTable dataTable = CreateFeatureDataTable(); foreach (Feature feature in _features) { if (feature.Geometry.Intersects(geometry)) { CreateNewRow(dataTable, feature); } } ds.Tables.Add(dataTable); }
/// <summary> /// Returns features within the specified bounding box. /// </summary> /// <param name="bbox"></param> /// <returns></returns> public Collection <SharpMap.Geometries.Geometry> GetGeometriesInView(SharpMap.Geometries.BoundingBox bbox) { // Identifies all the features within the given BoundingBox GisSharpBlog.NetTopologySuite.Geometries.Envelope envelope = GeometryConverter.ToNTSEnvelope(bbox); Collection <SharpMap.Geometries.Geometry> geoms = new Collection <SharpMap.Geometries.Geometry>(); foreach (GisSharpBlog.NetTopologySuite.Features.Feature feature in features) { if (envelope.Intersects(feature.Geometry.EnvelopeInternal)) { geoms.Add(GeometryConverter.ToSharpMapGeometry(feature.Geometry as GisSharpBlog.NetTopologySuite.Geometries.Geometry)); } } return(geoms); }
/// <summary> /// Gets the object IDs in the view. /// </summary> /// <param name="bbox">The bbox.</param> /// <returns></returns> public List <uint> GetObjectIDsInView(SharpMap.Geometries.BoundingBox bbox) { // Identifies all the features within the given BoundingBox GisSharpBlog.NetTopologySuite.Geometries.Envelope envelope = GeometryConverter.ToNTSEnvelope(bbox); List <uint> geoms = new List <uint>(features.Count); for (int i = 0; i < features.Count; i++) { if (envelope.Intersects(features[i].Geometry.EnvelopeInternal)) { geoms.Add(Convert.ToUInt32(i)); } } return(geoms); }
/// <summary> /// Gets the object IDs in the view. /// </summary> /// <param name="bbox">The bbox.</param> /// <returns></returns> public Collection <uint> GetObjectIDsInView(BoundingBox bbox) { // Identifies all the features within the given BoundingBox Envelope envelope = GeometryConverter.ToNTSEnvelope(bbox); Collection <uint> geoms = new Collection <uint>(); for (int i = 0; i < _features.Count; i++) { if (envelope.Intersects(_features[i].Geometry.EnvelopeInternal)) { geoms.Add(Convert.ToUInt32(i)); } } return(geoms); }
/// <summary> /// /// </summary> /// <param name="geom"></param> /// <param name="ds"></param> public void ExecuteIntersectionQuery(SharpMap.Geometries.Geometry geom, FeatureDataSet ds) { GisSharpBlog.NetTopologySuite.Geometries.Geometry geometry = GeometryConverter.ToNTSGeometry(geom, geometryFactory); SharpMap.Data.FeatureDataTable dataTable = CreateFeatureDataTable(); foreach (GisSharpBlog.NetTopologySuite.Features.Feature feature in features) { if (feature.Geometry.Intersects(geometry)) { CreateNewRow(dataTable, feature); } } ds.Tables.Add(dataTable); }
public static FrameworkElement CreateContent(FlowNode node) { var textBlock = new TextBlock() { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; var b = new Binding("Text"); b.Source = node; textBlock.SetBinding(TextBlock.TextProperty, b); if (node.Kind == NodeKinds.Start || node.Kind == NodeKinds.End) { var ui = new Border(); ui.CornerRadius = new CornerRadius(15); ui.BorderBrush = Brushes.Black; ui.BorderThickness = new Thickness(1); ui.Background = Brushes.Yellow; ui.Child = textBlock; return(ui); } else if (node.Kind == NodeKinds.Action) { var ui = new Border(); ui.BorderBrush = Brushes.Black; ui.BorderThickness = new Thickness(1); ui.Background = Brushes.Lime;; ui.Child = textBlock; return(ui); } else { var ui = new Path(); ui.Stroke = Brushes.Black; ui.StrokeThickness = 1; ui.Fill = Brushes.Pink; var converter = new GeometryConverter(); ui.Data = (Geometry)converter.ConvertFrom("M 0,0.25 L 0.5 0 L 1,0.25 L 0.5,0.5 Z"); ui.Stretch = Stretch.Uniform; var grid = new Grid(); grid.Children.Add(ui); grid.Children.Add(textBlock); return(grid); } }
/// <summary> /// 绘制线 /// </summary> /// <param name="point">数据</param> public virtual void ShowLine(ObservableCollection <Point> points) { bool isFirstPoint = true; Point lastPointPosition = new Point();//上一个点的位置 if (points != null) { foreach (Point point in points) { Ellipse p1 = new Ellipse(); p1.Height = 1; p1.Width = 1; p1.MaxHeight = 1; p1.MaxWidth = 1; p1.Fill = Brushes.Black; //位置坐标对齐圆心所以要减去0.5 Point pointPosition = DataToPrintPoint(point, 0, 0); //Canvas.SetLeft(p1, pointPosition.X); //Canvas.SetBottom(p1, pointPosition.Y); //ChartArea.DataArea.Children.Add(p1); if (!isFirstPoint) { #region create method3 Path pp3 = new Path(); //pp3.Data pp3.Stroke = new SolidColorBrush(Colors.Black); pp3.StrokeThickness = 0.8; GeometryConverter gc = new GeometryConverter(); pp3.Data = (Geometry)gc.ConvertFromString("M " + lastPointPosition.X + "," + lastPointPosition.Y + " " + pointPosition.X + "," + pointPosition.Y); ChartArea.DataArea.Children.Add(pp3); } else { isFirstPoint = false; } #endregion lastPointPosition = pointPosition; } } }
/// <summary> /// This method returns a FeatureDataTable containing all the rows from the shapefile that intersect the testGeometry. /// The ShapeFile.ExecuteIntersectionQuery method only tests bounding boxes so we use the FilterDelegate property to add a true /// intersection test using NetTopologySuite /// </summary> /// <param name="pathToShapefile">The path to the shapefile</param> /// <param name="testGeometry">The geometry that we want to test against</param> /// <returns></returns> public FeatureDataTable GetIntersectingFeaturesUsingFilterDelegate(string pathToShapefile, SMGeometry testGeometry) { //create a new shapefile provider using (ShapeFile shapefile = new ShapeFile(pathToShapefile)) { //create an nts GeometryFactory GeometryFactory geometryFactory = new GeometryFactory(); //convert the testGeometry into the equivalent NTS geometry GeoAPI.Geometries.IGeometry testGeometryAsNtsGeom = GeometryConverter.ToNTSGeometry(testGeometry, geometryFactory); SMGeometry check = GeometryConverter.ToSharpMapGeometry(testGeometryAsNtsGeom); if (!check.Equals(testGeometry)) { throw new ApplicationException("conversion error"); } //set the shapefile providers' FilterDelegate property to a new anonymous method //this delegate method will be called for each potential row shapefile.FilterDelegate = delegate(FeatureDataRow featureDataRow) { //get the geometry from the featureDataRow SMGeometry rowGeometry = featureDataRow.Geometry; //convert it to the equivalent NTS geometry GeoAPI.Geometries.IGeometry compareGeometryAsNtsGeometry = GeometryConverter.ToNTSGeometry(rowGeometry, geometryFactory); //do the test. Note that the testGeometryAsNtsGeometry is available here because it is //declared in the same scope as the anonymous method. bool intersects = testGeometryAsNtsGeom.Intersects(compareGeometryAsNtsGeometry); //return the result return(intersects); }; //create a new FeatureDataSet FeatureDataSet featureDataSet = new FeatureDataSet(); //open the shapefile shapefile.Open(); //call ExecuteIntersectionQuery. The FilterDelegate will be used to limit the result set shapefile.ExecuteIntersectionQuery(testGeometry, featureDataSet); //close the shapefile shapefile.Close(); //return the populated FeatureDataTable return(featureDataSet.Tables[0]); } }
/// <summary> /// Gets the feature identified from the given <paramref name="rowID" />. /// </summary> /// <param name="rowID">The row ID.</param> /// <returns></returns> public SharpMap.Data.FeatureDataRow GetFeature(uint rowID) { GisSharpBlog.NetTopologySuite.Features.Feature feature = features[Convert.ToInt32(rowID)]; SharpMap.Data.FeatureDataTable dataTable = new SharpMap.Data.FeatureDataTable(); foreach (string columnName in feature.Attributes.GetNames()) { dataTable.Columns.Add(new DataColumn(columnName, feature.Attributes.GetType(columnName))); } SharpMap.Data.FeatureDataRow dataRow = dataTable.NewRow(); dataRow.Geometry = GeometryConverter.ToSharpMapGeometry(feature.Geometry as GisSharpBlog.NetTopologySuite.Geometries.Geometry); foreach (string columnName in feature.Attributes.GetNames()) { dataRow[columnName] = feature.Attributes[columnName]; } return(dataRow); }
void drawWidthPath(string strPath) { if (mazeWidthPath == null || gc2 == null) { mazeWidthPath = new Path(); gc2 = new GeometryConverter(); mazeWidthPath.Stroke = Brushes.Blue; mazeWidthPath.StrokeThickness = 3; Grid.SetRowSpan(mazeWidthPath, md.Height); Grid.SetColumnSpan(mazeWidthPath, md.Width); } if (!gMaze.Children.Contains(mazeWidthPath)) { gMaze.Children.Add(mazeWidthPath); } mazeWidthPath.Data = (Geometry)gc2.ConvertFromString(strPath); }
/// <summary> /// Returns features within the specified bounding box. /// </summary> /// <param name="bbox"></param> /// <returns></returns> public Collection <Geometry> GetGeometriesInView(BoundingBox bbox) { // Identifies all the features within the given BoundingBox Envelope envelope = GeometryConverter.ToNTSEnvelope(bbox); Collection <Geometry> geoms = new Collection <Geometry>(); foreach (Feature feature in _features) { if (envelope.Intersects(feature.Geometry.EnvelopeInternal)) { geoms.Add( GeometryConverter.ToSharpMapGeometry( feature.Geometry as NtsGeometry)); } } return(geoms); }
/// <summary> /// Return a GeoJson from a datatable with column Geometry in Json format. /// </summary> /// <param name="dt">DataTable with columns properties and column geometry</param> /// <param name="GeometryColumn">Column Name of Geometry</param> /// <returns></returns> public static string fromDataset(DataTable dt, string GeometryColumn = "Geom") { var model = new FeatureCollection(); int numColumns = dt.Columns.Count; string[] keys = new string[numColumns]; for (int i = 0; i < numColumns; i++) { var columnName = dt.Columns[i].ColumnName; if (string.Compare(columnName, GeometryColumn, CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) != 0) { keys[i] = columnName; } } foreach (DataRow row in dt.Rows) { object geom = null; var geomDB = row[GeometryColumn].ToString(); var json = row[GeometryColumn].ToString(); JsonTextReader reader = new JsonTextReader(new StringReader(json)); while (reader.Read()) { geom = new GeometryConverter().ReadJson(reader, null, null, null); } Dictionary <string, object> props = new Dictionary <string, object>(); for (int j = 0; j < keys.Length; j++) { if (!string.IsNullOrEmpty(keys[j])) { props.Add(keys[j], row[j]); } } var feature = new GeoJSON.Net.Feature.Feature((IGeometryObject)geom, props); model.Features.Add(feature); } return(JsonConvert.SerializeObject(model)); }
public void DrawGeometry_Cubic_Besier_Curve() { UserControl userControl = new UserControl(); userControl.Width = 320; userControl.Height = 180; DrawGeometryControl testControl = new DrawGeometryControl(); GeometryConverter converter = new GeometryConverter(); testControl.Geometry = (Geometry)converter.ConvertFrom("M 10,100 C 10,300 300,-200 300,100"); testControl.Brush = new SolidColorBrush(Colors.Gray); testControl.Pen = new Pen(new SolidColorBrush(Colors.Black), 1); userControl.Content = testControl; this.RenderToFile(userControl); this.CompareImages(); }
/// <summary> /// Gets the feature identified from the given <paramref name="rowId" />. /// </summary> /// <param name="rowId">The row ID.</param> /// <returns></returns> public FeatureDataRow GetFeature(uint rowId) { Feature feature = _features[Convert.ToInt32(rowId)]; FeatureDataTable dataTable = new FeatureDataTable(); foreach (string columnName in feature.Attributes.GetNames()) { dataTable.Columns.Add(new DataColumn(columnName, feature.Attributes.GetType(columnName))); } FeatureDataRow dataRow = dataTable.NewRow(); dataRow.Geometry = GeometryConverter.ToSharpMapGeometry( feature.Geometry as NtsGeometry); foreach (string columnName in feature.Attributes.GetNames()) { dataRow[columnName] = feature.Attributes[columnName]; } return(dataRow); }
/// <summary> /// /// </summary> /// <param name="box"></param> /// <param name="ds"></param> public void ExecuteIntersectionQuery(SharpMap.Geometries.BoundingBox box, FeatureDataSet ds) { // Identifies all the features within the given BoundingBox GisSharpBlog.NetTopologySuite.Geometries.Envelope envelope = GeometryConverter.ToNTSEnvelope(box); List <GisSharpBlog.NetTopologySuite.Features.Feature> results = new List <GisSharpBlog.NetTopologySuite.Features.Feature>(features.Count); foreach (GisSharpBlog.NetTopologySuite.Features.Feature feature in features) { if (envelope.Intersects(feature.Geometry.EnvelopeInternal)) { results.Add(feature); } } // Fill DataSet SharpMap.Data.FeatureDataTable dataTable = CreateFeatureDataTable(); foreach (GisSharpBlog.NetTopologySuite.Features.Feature feature in results) { CreateNewRow(dataTable, feature); } ds.Tables.Add(dataTable); }
void DrawLine(FrameworkElement element, Point newpoint) { double left, top, right, bottom; if (element == null) { return; } left = newpoint.X; top = newpoint.Y; element.Margin = new Thickness(left, top, main.ActualWidth - left - element.ActualWidth, main.ActualHeight - top - element.ActualHeight); GeometryConverter gc = new GeometryConverter(); left = Math.Min(rectangleStart.Margin.Left, rectangleEnd.Margin.Left); right = Math.Min(rectangleStart.Margin.Right, rectangleEnd.Margin.Right); top = Math.Min(rectangleStart.Margin.Top, rectangleEnd.Margin.Top); bottom = Math.Min(rectangleStart.Margin.Bottom, rectangleEnd.Margin.Bottom); rectangle.Margin = new Thickness(left, top, right, bottom); }
public void DrawGeometry_Cubic_Besier_Curve() { UserControl userControl = new UserControl(); userControl.Width = 320; userControl.Height = 180; DrawGeometryControl testControl = new DrawGeometryControl(); GeometryConverter converter = new GeometryConverter(); testControl.Geometry = (Geometry)converter.ConvertFrom("M 10,100 C 10,300 300,-200 300,100"); testControl.Brush = new SolidColorBrush(Colors.Gray); testControl.Pen = new Pen(new SolidColorBrush(Colors.Black), 1); userControl.Content = testControl; this.RenderToFile(userControl); this.CompareImages(); }