コード例 #1
0
        /// <summary>
        /// Gets the feature at the specified Object ID
        /// </summary>
        /// <param name="oid"></param>
        /// <param name="table"></param>
        /// <returns></returns>
        internal SharpMap.Data.FeatureDataRow GetFeature(uint oid, SharpMap.Data.FeatureDataTable table)
        {
            if (!_isOpen)
            {
                throw (new ApplicationException("An attempt was made to read from a closed DBF file"));
            }
            if (oid >= _NumberOfRecords)
            {
                throw (new ArgumentException("Invalid DataRow requested at index " + oid.ToString()));
            }
            fs.Seek(_HeaderLength + oid * _RecordLength, 0);

            SharpMap.Data.FeatureDataRow dr = table.NewRow();

            if (br.ReadChar() == '*')             //is record marked deleted?
            {
                return(null);
            }

            for (int i = 0; i < DbaseColumns.Length; i++)
            {
                DbaseField dbf = DbaseColumns[i];
                dr[dbf.ColumnName] = ReadDbfValue(dbf);
            }
            return(dr);
        }
コード例 #2
0
ファイル: CreatingData.cs プロジェクト: lishxi/_SharpMap
        /// <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;
        }
コード例 #3
0
 /// <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);
 }
コード例 #4
0
        /// <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);
        }
コード例 #5
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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
ファイル: CreatingData.cs プロジェクト: geobabbler/SharpMap
        /// <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;
        }
コード例 #8
0
        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]);
        }
コード例 #9
0
        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);
        }
コード例 #10
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;
    }
コード例 #11
0
ファイル: CreatingData.cs プロジェクト: cugkgq/Project
        /// <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);
        }
コード例 #12
0
        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]);
        }
コード例 #13
0
        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;
        }
コード例 #14
0
            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;
            }
コード例 #15
0
ファイル: NtsProvider.cs プロジェクト: lishxi/_SharpMap
 /// <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);
     foreach (string columnName in feature.Attributes.GetNames())
         dataRow[columnName] = feature.Attributes[columnName];
     return dataRow;
 }
コード例 #16
0
        private void readFromCSVToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog file = new OpenFileDialog();

            file.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            file.Filter           = "Csv File |*.csv";
            file.Multiselect      = false;

            if (file.ShowDialog() == DialogResult.OK)
            {
                string FileName = file.SafeFileName.Replace(".csv", "");
                string FilePath = file.FileName;

                string encoding  = "UTF-8";
                string seperator = "##";
                int    index     = 0;

                using (StreamReader reader = new StreamReader(FilePath, Encoding.GetEncoding(encoding)))
                {
                    DataTable dt = new DataTable();

                    var dtFeature = new SharpMap.Data.FeatureDataTable();

                    WKTReader wktreader = new WKTReader();

                    while (!reader.EndOfStream)
                    {
                        var line = reader.ReadLine();
                        var data = line.Split(new string[] { seperator }, StringSplitOptions.None);

                        if (index == 0)
                        {
                            for (int i = 0; i < data.Length; i++)
                            {
                                dtFeature.Columns.Add(data[i], typeof(string));
                                dt.Columns.Add(data[i], typeof(string));
                            }
                        }
                        else
                        {
                            DataRow dr = dt.NewRow();
                            SharpMap.Data.FeatureDataRow drFeature = dtFeature.NewRow();

                            for (int i = 0; i < dt.Columns.Count; i++)
                            {
                                dr[i] = data[i];

                                if (dt.Columns[i].Caption == "geom_wkt")
                                {
                                    drFeature[i] = data[i];
                                    if (!string.IsNullOrEmpty(data[i]))
                                    {
                                        IGeometry geom = wktreader.Read(data[i]);

                                        drFeature.Geometry = geom;
                                    }
                                }
                                else
                                {
                                    drFeature[i] = data[i];
                                }
                            }
                            dt.Rows.Add(dr);
                            dtFeature.Rows.Add(drFeature);
                        }

                        index++;
                    }

                    //Collection<IGeometry> geometry = new Collection<IGeometry>();
                    //VectorLayer layer = new VectorLayer(FileName);

                    //for (int i = 0; i < dt.Rows.Count; i++)
                    //{
                    //    if (!string.IsNullOrEmpty(dt.Rows[i]["geom_wkt"].ToString()))
                    //    {
                    //        IGeometry geom = wktreader.Read(dt.Rows[i]["geom_wkt"].ToString());

                    //        geometry.Add(geom);
                    //    }
                    //}

                    var gfp = new GeometryFeatureProvider(dtFeature);

                    var layer = new SharpMap.Layers.VectorLayer(FileName, gfp);
                    layer.DataSource.SRID = 3857;

                    mapBox1.Map.Layers.Add(layer);

                    listBoxLayerList.Items.Add(FileName);

                    var labelLayer = new LabelLayer(FileName + "-Label");
                    labelLayer.DataSource  = gfp;
                    labelLayer.LabelColumn = "kapi_kodu";

                    //mapBox1.Map.Layers.Add(labelLayer);

                    //var provider = new GeometryProvider(geometry);
                    //layer.DataSource = provider;
                    //layer.DataSource.SRID = 3857;

                    //mapBox1.Map.Layers.Add(layer);

                    mapBox1.Map.ZoomToExtents();
                    mapBox1.Refresh();
                }
            }
        }
コード例 #17
0
        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();
        }
コード例 #18
0
ファイル: FormViewer.cs プロジェクト: gerie-tanabe/rubix
        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();
        }