/// <summary> /// Creates a FeatureDataTable from arrays of x, y and z components /// </summary> /// <param name="xcomponents">an array of doubles representing the x ordinate values</param> /// <param name="ycomponents">an array of doubles representing the y ordinate values</param> /// <param name="zcomponents">an array of doubles representing the z ordinate values</param> /// <returns></returns> public static SharpMap.Data.FeatureDataTable CreatePointFeatureDataTableFromArrays(double[] xcomponents, double[] ycomponents, double[] zcomponents) { bool threedee = false; if (zcomponents != null) { if (!(zcomponents.Length == ycomponents.Length && zcomponents.Length == xcomponents.Length)) throw new System.ApplicationException("Mismatched Array Lengths"); threedee = true; } else { if (ycomponents.Length != xcomponents.Length) throw new System.ApplicationException("Mismatched Array Lengths"); } SharpMap.Data.FeatureDataTable fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add("TimeStamp", typeof (System.DateTime)); // add example timestamp attribute for (int i = 0; i < xcomponents.Length; i++) { SharpMap.Data.FeatureDataRow fdr = fdt.NewRow(); fdr.Geometry = threedee ? new SharpMap.Geometries.Point3D(xcomponents[i], ycomponents[i], zcomponents[i]) : new SharpMap.Geometries.Point(xcomponents[i], ycomponents[i]); fdr["TimeStamp"] = System.DateTime.Now; //set the timestamp property fdt.AddRow(fdr); } return fdt; }
/// <summary> /// Returns the data associated with all the geometries that are intersected by 'geom'. /// Please note that the ShapeFile provider currently doesn't fully support geometryintersection /// and thus only BoundingBox/BoundingBox querying are performed. The results are NOT /// guaranteed to lie withing 'geom'. /// </summary> /// <param name="geom"></param> /// <param name="ds">FeatureDataSet to fill data into</param> public void ExecuteIntersectionQuery(IGeometry geom, FeatureDataSet ds) { SharpMap.Data.FeatureDataTable dt = (SharpMap.Data.FeatureDataTable)dbaseFile.NewTable; IEnvelope bbox = geom.EnvelopeInternal; //Get candidates by intersecting the spatial index tree Collection <uint> objectlist = tree.Search(bbox); if (objectlist.Count == 0) { return; } for (int j = 0; j < objectlist.Count; j++) { for (uint i = (uint)dt.Rows.Count - 1; i >= 0; i--) { FeatureDataRow fdr = GetFeature(objectlist[j], dt); if (fdr.Geometry != null) { if (fdr.Geometry.Intersects(geom)) { if (FilterDelegate == null || FilterDelegate(fdr)) { dt.AddRow(fdr); } } } } } ds.Tables.Add(dt); }
/// <summary> /// Returns the data associated with all the geometries that are intersected by 'geom'. /// Please note that the ShapeFile provider currently doesn't fully support geometryintersection /// and thus only BoundingBox/BoundingBox querying are performed. The results are NOT /// guaranteed to lie withing 'geom'. /// </summary> /// <param name="geom"></param> /// <param name="ds">FeatureDataSet to fill data into</param> public void ExecuteIntersectionQuery(SharpMap.Geometries.Geometry geom, FeatureDataSet ds) { SharpMap.Data.FeatureDataTable dt = (SharpMap.Data.FeatureDataTable)dbaseFile.NewTable; SharpMap.Geometries.BoundingBox bbox = geom.GetBoundingBox(); //Get candidates by intersecting the spatial index tree List <uint> objectlist = tree.Search(bbox); if (objectlist.Count == 0) { return; } for (int j = 0; j < objectlist.Count; j++) { for (uint i = (uint)dt.Rows.Count - 1; i >= 0; i--) { FeatureDataRow fdr = GetFeature(objectlist[j], dt); if (fdr.Geometry != null) { if (fdr.Geometry.GetBoundingBox().Intersects(bbox)) { //replace above line with this: if(fdr.Geometry.Intersects(bbox)) when relation model is complete if (FilterDelegate == null || FilterDelegate(fdr)) { dt.AddRow(fdr); } } } } } ds.Tables.Add(dt); }
/// <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> /// Creates a FeatureDataTable from arrays of x, y and z components /// </summary> /// <param name="xcomponents">an array of doubles representing the x ordinate values</param> /// <param name="ycomponents">an array of doubles representing the y ordinate values</param> /// <param name="zcomponents">an array of doubles representing the z ordinate values</param> /// <returns></returns> public static SharpMap.Data.FeatureDataTable CreatePointFeatureDataTableFromArrays(double[] xcomponents, double[] ycomponents, double[] zcomponents, double[] data = null) { var factory = new NetTopologySuite.Geometries.GeometryFactory(); var threedee = false; if (zcomponents != null) { if (!(zcomponents.Length == ycomponents.Length && zcomponents.Length == xcomponents.Length)) { throw new System.ApplicationException("Mismatched Array Lengths"); } threedee = true; } else { if (ycomponents.Length != xcomponents.Length) { throw new System.ApplicationException("Mismatched Array Lengths"); } } var fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add("TimeStamp", typeof(System.DateTime)); // add example timestamp attribute if (data != null) { fdt.Columns.Add("Data", typeof(System.Double)); // add example timestamp attribute } for (var i = 0; i < xcomponents.Length; i++) { SharpMap.Data.FeatureDataRow fdr = fdt.NewRow(); fdr.Geometry = factory.CreatePoint(threedee ? new GeoAPI.Geometries.Coordinate(xcomponents[i], ycomponents[i], zcomponents[i]) : new GeoAPI.Geometries.Coordinate(xcomponents[i], ycomponents[i])); fdr["TimeStamp"] = System.DateTime.Now; //set the timestamp property if (data != null) { fdr["Data"] = data[i]; } fdt.AddRow(fdr); } return(fdt); }
public void GetItemByID() { var fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add(new DataColumn("ID", typeof(uint))); var gf = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(); for (var i = 0; i < 5; i++) { var row = fdt.NewRow(); row[0] = (uint)i; row.Geometry = gf.CreatePoint(new GeoAPI.Geometries.Coordinate(i, i)); fdt.AddRow(row); } var layer = new SharpMap.Layers.VectorLayer("TMP", new SharpMap.Data.Providers.GeometryFeatureProvider(fdt)); var res = layer.DataSource.GetFeature(0); NUnit.Framework.Assert.IsNotNull(res); }
/// <summary> /// Creates a FeatureDataTable from arrays of x, y and z components /// </summary> /// <param name="xcomponents">an array of doubles representing the x ordinate values</param> /// <param name="ycomponents">an array of doubles representing the y ordinate values</param> /// <param name="zcomponents">an array of doubles representing the z ordinate values</param> /// <returns></returns> public static SharpMap.Data.FeatureDataTable CreatePointFeatureDataTableFromArrays(double[] xcomponents, double[] ycomponents, double[] zcomponents, double[] data = null) { var factory = new NetTopologySuite.Geometries.GeometryFactory(); var threedee = false; if (zcomponents != null) { if (!(zcomponents.Length == ycomponents.Length && zcomponents.Length == xcomponents.Length)) throw new System.ApplicationException("Mismatched Array Lengths"); threedee = true; } else { if (ycomponents.Length != xcomponents.Length) throw new System.ApplicationException("Mismatched Array Lengths"); } var fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add("TimeStamp", typeof (System.DateTime)); // add example timestamp attribute if (data != null) fdt.Columns.Add("Data", typeof(System.Double)); // add example timestamp attribute for (var i = 0; i < xcomponents.Length; i++) { SharpMap.Data.FeatureDataRow fdr = fdt.NewRow(); fdr.Geometry = factory.CreatePoint(threedee ? new GeoAPI.Geometries.Coordinate(xcomponents[i], ycomponents[i], zcomponents[i]) : new GeoAPI.Geometries.Coordinate(xcomponents[i], ycomponents[i])); fdr["TimeStamp"] = System.DateTime.Now; //set the timestamp property if (data != null) fdr["Data"] = data[i]; fdt.AddRow(fdr); } return fdt; }
public void TestFindGeoNearPoint() { var fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add(new DataColumn("ID", typeof(uint))); var gf = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(); for (var i = 0; i < 5; i++) { var row = fdt.NewRow(); row[0] = (uint)i; row.Geometry = gf.CreatePoint(new GeoAPI.Geometries.Coordinate(i, i)); fdt.AddRow(row); } var layer = new SharpMap.Layers.VectorLayer("TMP", new SharpMap.Data.Providers.GeometryFeatureProvider(fdt)); var res = FindGeoNearPoint(gf.CreatePoint(new GeoAPI.Geometries.Coordinate(0.1, 0.1)), layer, 0.2d); NUnit.Framework.Assert.IsNotNull(res); NUnit.Framework.Assert.AreEqual(0, (uint)res[0]); }
public SharpMap.Layers.VectorLayer CreateGeometryLayer() { SharpMap.Data.FeatureDataTable fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add(new DataColumn("Name", typeof(String))); SharpMap.Data.FeatureDataRow fdr; fdr = fdt.NewRow(); fdr["Name"] = "Mayence"; fdr.Geometry = (Geometry)new Point(8.1, 50.0); fdt.AddRow(fdr); SharpMap.Layers.VectorLayer vLayer = new SharpMap.Layers.VectorLayer("GeometryProvider"); vLayer.DataSource = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt); vLayer.SRID = 4326; return vLayer; }
/// <summary> /// Creates a FeatureDataTable from arrays of x, y and z components /// </summary> /// <param name="xcomponents">an array of doubles representing the x ordinate values</param> /// <param name="ycomponents">an array of doubles representing the y ordinate values</param> /// <param name="zcomponents">an array of doubles representing the z ordinate values</param> /// <returns></returns> public static SharpMap.Data.FeatureDataTable CreatePointFeatureDataTableFromArrays(double[] xcomponents, double[] ycomponents, double[] zcomponents) { bool threedee = false; if (zcomponents != null) { if (!(zcomponents.Length == ycomponents.Length && zcomponents.Length == xcomponents.Length)) { throw new System.ApplicationException("Mismatched Array Lengths"); } threedee = true; } else { if (ycomponents.Length != xcomponents.Length) { throw new System.ApplicationException("Mismatched Array Lengths"); } } SharpMap.Data.FeatureDataTable fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add("TimeStamp", typeof(System.DateTime)); // add example timestamp attribute for (int i = 0; i < xcomponents.Length; i++) { SharpMap.Data.FeatureDataRow fdr = fdt.NewRow(); fdr.Geometry = threedee ? new SharpMap.Geometries.Point3D(xcomponents[i], ycomponents[i], zcomponents[i]) : new SharpMap.Geometries.Point(xcomponents[i], ycomponents[i]); fdr["TimeStamp"] = System.DateTime.Now; //set the timestamp property fdt.AddRow(fdr); } return(fdt); }
private static SharpMap.Data.FeatureDataTable TransformedFeatureDataTable( System.Drawing.Drawing2D.Matrix matrix, SharpMap.Data.FeatureDataTable fdt) { SharpMap.Data.FeatureDataTable fdtClone = new SharpMap.Data.FeatureDataTable(fdt); fdtClone.Clear(); foreach (SharpMap.Data.FeatureDataRow row in fdt) { SharpMap.Data.FeatureDataRow newRow = fdtClone.NewRow(); for (System.Int32 i = 0; i < fdtClone.Columns.Count; i++) newRow[i] = row[i]; GeoAPI.Geometries.IPoint smpt = (GeoAPI.Geometries.IPoint)row.Geometry; System.Drawing.PointF[] pts = new System.Drawing.PointF[] { new System.Drawing.PointF((float)smpt.X, (float)smpt.Y) }; matrix.TransformPoints(pts); newRow.Geometry = new NetTopologySuite.Geometries.Point(pts[0].X, pts[0].Y); fdtClone.AddRow(newRow); } return fdtClone; }
/// <summary> /// Returns all objects whose boundingbox intersects bbox. /// </summary> /// <remarks> /// <para> /// Please note that this method doesn't guarantee that the geometries returned actually intersect 'bbox', but only /// that their boundingbox intersects 'bbox'. /// </para> /// </remarks> /// <param name="bbox"></param> /// <param name="ds"></param> /// <returns></returns> public void ExecuteIntersectionQuery(SharpMap.Geometries.BoundingBox bbox, SharpMap.Data.FeatureDataSet ds) { //Use the spatial index to get a list of features whose boundingbox intersects bbox List <uint> objectlist = GetObjectIDsInView(bbox); SharpMap.Data.FeatureDataTable dt = dbaseFile.NewTable; for (int i = 0; i < objectlist.Count; i++) { SharpMap.Data.FeatureDataRow fdr = dbaseFile.GetFeature(objectlist[i], dt); fdr.Geometry = ReadGeometry(objectlist[i]); if (fdr.Geometry != null) { if (fdr.Geometry.GetBoundingBox().Intersects(bbox)) { if (FilterDelegate == null || FilterDelegate(fdr)) { dt.AddRow(fdr); } } } } ds.Tables.Add(dt); }
private void LoadParcels(List <PointD> pt, Color color, string labelname) { SharpMap.Map map = new SharpMap.Map(); List <GeoAPI.Geometries.Coordinate> vertices = new List <GeoAPI.Geometries.Coordinate>(); foreach (PointD i in pt) { GeoAPI.Geometries.Coordinate p = new GeoAPI.Geometries.Coordinate(); p.X = i.X; p.Y = i.Y; vertices.Add(p); } GeoAPI.Geometries.Coordinate l = new GeoAPI.Geometries.Coordinate(); l.X = pt[0].X; l.Y = pt[0].Y; vertices.Add(l); //Collection<GeoAPI.Geometries.IGeometry> geom = new Collection<GeoAPI.Geometries.IGeometry>(); GeometryFactory gf = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILinearRing shell = gf.CreateLinearRing(vertices.ToArray()); GeoAPI.Geometries.IPolygon polygon = gf.CreatePolygon(shell, null); SharpMap.Data.Providers.GeometryProvider geomProvider = new SharpMap.Data.Providers.GeometryProvider(polygon); SharpMap.Layers.VectorLayer layerParcels = new SharpMap.Layers.VectorLayer("Parcels"); SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Fill = new SolidBrush(Color.FromArgb(200, color)); style.Outline = new Pen(new SolidBrush(color)); layerParcels.Style = style; layerParcels.Style.EnableOutline = true; layerParcels.DataSource = geomProvider; layerParcels.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; var fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add(new System.Data.DataColumn("id", typeof(uint))); fdt.Columns.Add(new System.Data.DataColumn("label", typeof(string))); var fdr = (SharpMap.Data.FeatureDataRow)fdt.NewRow(); fdr.ItemArray = new object[] { 1, labelname }; fdr.Geometry = polygon; fdt.AddRow(fdr); var dataprovider = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt); var ll = new SharpMap.Layers.LabelLayer("llayer"); ll.DataSource = dataprovider; ll.LabelColumn = "label"; ll.Style.Font = new Font("Eurostile Extended", 16, FontStyle.Bold); mapBox1.Map.Layers.Add(layerParcels); mapBox1.Map.Layers.Add(ll); mapBox1.Map.ZoomToExtents(); mapBox1.Refresh(); }
private void LoadParcels(List<PointD> pt, Color color, string labelname) { SharpMap.Map map = new SharpMap.Map(); List<GeoAPI.Geometries.Coordinate> vertices = new List<GeoAPI.Geometries.Coordinate>(); foreach (PointD i in pt) { GeoAPI.Geometries.Coordinate p = new GeoAPI.Geometries.Coordinate(); p.X = i.X; p.Y = i.Y; vertices.Add(p); } GeoAPI.Geometries.Coordinate l = new GeoAPI.Geometries.Coordinate(); l.X = pt[0].X; l.Y = pt[0].Y; vertices.Add(l); //Collection<GeoAPI.Geometries.IGeometry> geom = new Collection<GeoAPI.Geometries.IGeometry>(); GeometryFactory gf = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILinearRing shell = gf.CreateLinearRing(vertices.ToArray()); GeoAPI.Geometries.IPolygon polygon = gf.CreatePolygon(shell, null); SharpMap.Data.Providers.GeometryProvider geomProvider= new SharpMap.Data.Providers.GeometryProvider(polygon); SharpMap.Layers.VectorLayer layerParcels = new SharpMap.Layers.VectorLayer("Parcels"); SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Fill = new SolidBrush(Color.FromArgb(200,color)); style.Outline = new Pen(new SolidBrush(color)); layerParcels.Style = style; layerParcels.Style.EnableOutline = true; layerParcels.DataSource = geomProvider; layerParcels.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; var fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add(new System.Data.DataColumn("id", typeof(uint))); fdt.Columns.Add(new System.Data.DataColumn("label", typeof(string))); var fdr = (SharpMap.Data.FeatureDataRow)fdt.NewRow(); fdr.ItemArray = new object[] { 1, labelname }; fdr.Geometry = polygon; fdt.AddRow(fdr); var dataprovider = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt); var ll = new SharpMap.Layers.LabelLayer("llayer"); ll.DataSource = dataprovider; ll.LabelColumn = "label"; ll.Style.Font = new Font("Eurostile Extended", 16,FontStyle.Bold); mapBox1.Map.Layers.Add(layerParcels); mapBox1.Map.Layers.Add(ll); mapBox1.Map.ZoomToExtents(); mapBox1.Refresh(); }
private static SharpMap.Data.FeatureDataTable TransformedFeatureDataTable( System.Drawing.Drawing2D.Matrix matrix, SharpMap.Data.FeatureDataTable fdt) { SharpMap.Data.FeatureDataTable fdtClone = new SharpMap.Data.FeatureDataTable(fdt); fdtClone.Clear(); foreach (SharpMap.Data.FeatureDataRow row in fdt) { SharpMap.Data.FeatureDataRow newRow = fdtClone.NewRow(); for (System.Int32 i = 0; i < fdtClone.Columns.Count; i++) newRow[i] = row[i]; SharpMap.Geometries.Point smpt = (SharpMap.Geometries.Point)row.Geometry; System.Drawing.PointF[] pts = new System.Drawing.PointF[] { new System.Drawing.PointF((float)smpt.X, (float)smpt.Y) }; matrix.TransformPoints(pts); newRow.Geometry = new SharpMap.Geometries.Point(pts[0].X, pts[0].Y); fdtClone.AddRow(newRow); } return fdtClone; }