diff --git a/ShapeFileViewer/MainForm.Designer.cs b/ShapeFileViewer/MainForm.Designer.cs index 1d999799daedc82b7a80445f3c003103cebc1637..62e13904a512ce1849eb0ac6bbf2d1fd0deab4df 100644 --- a/ShapeFileViewer/MainForm.Designer.cs +++ b/ShapeFileViewer/MainForm.Designer.cs @@ -32,7 +32,11 @@ this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.labelLayer = new System.Windows.Forms.Label(); this.layerManager = new System.Windows.Forms.TreeView(); + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.tabPage1 = new System.Windows.Forms.TabPage(); this.DrawPanel = new System.Windows.Forms.PictureBox(); + this.tabPage2 = new System.Windows.Forms.TabPage(); + this.dbfdataGridView = new System.Windows.Forms.DataGridView(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.文件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.打开Shape文件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -44,22 +48,22 @@ this.browseShpBtn = new System.Windows.Forms.Button(); this.shpLabel = new System.Windows.Forms.Label(); this.shpfilePath = new System.Windows.Forms.TextBox(); - this.tabControl1 = new System.Windows.Forms.TabControl(); - this.tabPage1 = new System.Windows.Forms.TabPage(); - this.tabPage2 = new System.Windows.Forms.TabPage(); - this.dbfdataGridView = new System.Windows.Forms.DataGridView(); + this.mifPath = new System.Windows.Forms.TextBox(); + this.mifLabel = new System.Windows.Forms.Label(); + this.browseMifBtn = new System.Windows.Forms.Button(); + this.saveMifBtn = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.DrawPanel)).BeginInit(); - this.menuStrip1.SuspendLayout(); - this.statusStrip1.SuspendLayout(); - this.panel1.SuspendLayout(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.DrawPanel)).BeginInit(); this.tabPage2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dbfdataGridView)).BeginInit(); + this.menuStrip1.SuspendLayout(); + this.statusStrip1.SuspendLayout(); + this.panel1.SuspendLayout(); this.SuspendLayout(); // // splitContainer1 @@ -90,13 +94,46 @@ this.layerManager.CheckBoxes = true; this.layerManager.Name = "layerManager"; // + // tabControl1 + // + resources.ApplyResources(this.tabControl1, "tabControl1"); + this.tabControl1.Controls.Add(this.tabPage1); + this.tabControl1.Controls.Add(this.tabPage2); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + // + // tabPage1 + // + this.tabPage1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.tabPage1.Controls.Add(this.DrawPanel); + resources.ApplyResources(this.tabPage1, "tabPage1"); + this.tabPage1.Name = "tabPage1"; + this.tabPage1.UseVisualStyleBackColor = true; + // // DrawPanel // resources.ApplyResources(this.DrawPanel, "DrawPanel"); - this.DrawPanel.BackColor = System.Drawing.Color.Coral; + this.DrawPanel.BackColor = System.Drawing.Color.White; this.DrawPanel.Name = "DrawPanel"; this.DrawPanel.TabStop = false; // + // tabPage2 + // + this.tabPage2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.tabPage2.Controls.Add(this.dbfdataGridView); + resources.ApplyResources(this.tabPage2, "tabPage2"); + this.tabPage2.Name = "tabPage2"; + this.tabPage2.UseVisualStyleBackColor = true; + // + // dbfdataGridView + // + this.dbfdataGridView.AllowUserToOrderColumns = true; + this.dbfdataGridView.BackgroundColor = System.Drawing.SystemColors.ActiveBorder; + this.dbfdataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + resources.ApplyResources(this.dbfdataGridView, "dbfdataGridView"); + this.dbfdataGridView.Name = "dbfdataGridView"; + this.dbfdataGridView.RowTemplate.Height = 23; + // // menuStrip1 // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -138,8 +175,12 @@ // panel1 // resources.ApplyResources(this.panel1, "panel1"); + this.panel1.Controls.Add(this.saveMifBtn); + this.panel1.Controls.Add(this.browseMifBtn); this.panel1.Controls.Add(this.openShpBtn); + this.panel1.Controls.Add(this.mifLabel); this.panel1.Controls.Add(this.browseShpBtn); + this.panel1.Controls.Add(this.mifPath); this.panel1.Controls.Add(this.shpLabel); this.panel1.Controls.Add(this.shpfilePath); this.panel1.Name = "panel1"; @@ -169,38 +210,30 @@ this.shpfilePath.Name = "shpfilePath"; this.shpfilePath.TextChanged += new System.EventHandler(this.shpfilePath_TextChanged); // - // tabControl1 + // mifPath // - resources.ApplyResources(this.tabControl1, "tabControl1"); - this.tabControl1.Controls.Add(this.tabPage1); - this.tabControl1.Controls.Add(this.tabPage2); - this.tabControl1.Name = "tabControl1"; - this.tabControl1.SelectedIndex = 0; + resources.ApplyResources(this.mifPath, "mifPath"); + this.mifPath.Name = "mifPath"; + this.mifPath.TextChanged += new System.EventHandler(this.shpfilePath_TextChanged); // - // tabPage1 + // mifLabel // - this.tabPage1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.tabPage1.Controls.Add(this.DrawPanel); - resources.ApplyResources(this.tabPage1, "tabPage1"); - this.tabPage1.Name = "tabPage1"; - this.tabPage1.UseVisualStyleBackColor = true; + resources.ApplyResources(this.mifLabel, "mifLabel"); + this.mifLabel.Name = "mifLabel"; // - // tabPage2 + // browseMifBtn // - this.tabPage2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.tabPage2.Controls.Add(this.dbfdataGridView); - resources.ApplyResources(this.tabPage2, "tabPage2"); - this.tabPage2.Name = "tabPage2"; - this.tabPage2.UseVisualStyleBackColor = true; + resources.ApplyResources(this.browseMifBtn, "browseMifBtn"); + this.browseMifBtn.Name = "browseMifBtn"; + this.browseMifBtn.UseVisualStyleBackColor = true; + this.browseMifBtn.Click += new System.EventHandler(this.browseMifBtn_Click); // - // dbfdataGridView + // saveMifBtn // - this.dbfdataGridView.AllowUserToOrderColumns = true; - this.dbfdataGridView.BackgroundColor = System.Drawing.SystemColors.ActiveBorder; - this.dbfdataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - resources.ApplyResources(this.dbfdataGridView, "dbfdataGridView"); - this.dbfdataGridView.Name = "dbfdataGridView"; - this.dbfdataGridView.RowTemplate.Height = 23; + resources.ApplyResources(this.saveMifBtn, "saveMifBtn"); + this.saveMifBtn.Name = "saveMifBtn"; + this.saveMifBtn.UseVisualStyleBackColor = true; + this.saveMifBtn.Click += new System.EventHandler(this.saveMifBtn_Click); // // MainForm // @@ -217,17 +250,17 @@ this.splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); + this.tabControl1.ResumeLayout(false); + this.tabPage1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.DrawPanel)).EndInit(); + this.tabPage2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dbfdataGridView)).EndInit(); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); - this.tabControl1.ResumeLayout(false); - this.tabPage1.ResumeLayout(false); - this.tabPage2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.dbfdataGridView)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -253,5 +286,9 @@ private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.DataGridView dbfdataGridView; + private System.Windows.Forms.Button saveMifBtn; + private System.Windows.Forms.Button browseMifBtn; + private System.Windows.Forms.Label mifLabel; + private System.Windows.Forms.TextBox mifPath; } } \ No newline at end of file diff --git a/ShapeFileViewer/MainForm.cs b/ShapeFileViewer/MainForm.cs index 0ec9a16998f7abc6992cbb442801e88ca3e89482..01b4a41e6334a84e1a4650b3aaffe07bc5f78ef5 100644 --- a/ShapeFileViewer/MainForm.cs +++ b/ShapeFileViewer/MainForm.cs @@ -3,11 +3,13 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; -using System.Data.OleDb; +using System.Data.SqlTypes; using System.Diagnostics; using System.Drawing; +using System.Drawing.Drawing2D; using System.IO; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -18,10 +20,34 @@ namespace ShapeFileViewer { // 用于管理打开的多个Shape文件 List shpList = new List(); + System.Drawing.Drawing2D.Matrix transform = new System.Drawing.Drawing2D.Matrix(); + PointF mouse_pos = new PointF(); public MainForm() { + //设置窗体的双缓冲 + SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true); + UpdateStyles(); + InitializeComponent(); + + // 利用反射设置DataGridView的双缓冲(解决DataGridView显示卡顿问题) + Type dgvType = dbfdataGridView.GetType(); + PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", + BindingFlags.Instance | BindingFlags.NonPublic); + pi.SetValue(dbfdataGridView, true, null); + this.DrawPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.DrawPanel_Paint); + this.DrawPanel.MouseClick += new MouseEventHandler(DrawPanel_MouseClick); + this.DrawPanel.MouseMove += new MouseEventHandler(DrawPanel_MouseMove); + this.DrawPanel.MouseUp += new MouseEventHandler(DrawPanel_MouseUp); + this.DrawPanel.MouseDoubleClick += new MouseEventHandler(DrawPanel_MouseDoubleClick); + + this.layerManager.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.layerManager_AfterCheck); + + this.DrawPanel.MouseWheel += new MouseEventHandler(DrawPanel_MouseWheel); + + SetStyle(ControlStyles.UserPaint, true); + SetStyle(ControlStyles.OptimizedDoubleBuffer, true); } private void MainForm_Load(object sender, EventArgs e) @@ -66,23 +92,185 @@ namespace ShapeFileViewer if (Path.GetExtension(filepath) != ".shp") return; ShapeFile shapefile = new ShapeFile(filepath); - shpList.Add(shapefile); + InitScale(); + shapefile.IsRender = true; + AddLayer(shapefile.FileName); + DrawPanel.Refresh(); dbfdataGridView.DataSource = shapefile.DataSet.Tables[0]; - - UpdataLayerManager(); } - private void UpdataLayerManager() + private void AddLayer(string layerName) { layerManager.BeginUpdate(); - layerManager.Nodes.Clear(); - foreach(var shape in shpList) + TreeNode treenode = new TreeNode(layerName); + treenode.Checked = true; + layerManager.Nodes.Add(treenode); + layerManager.EndUpdate(); + + } + + private void layerManager_AfterCheck(object sender, TreeViewEventArgs e) + { + if (e.Action != TreeViewAction.Unknown) { - layerManager.Nodes.Add(new TreeNode(shape.FileName)); + shpList[e.Node.Index].IsRender = e.Node.Checked; + DrawPanel.Refresh(); } - layerManager.EndUpdate(); + } + + private void DrawPanel_Paint(object sender, PaintEventArgs e) + { + if (shpList.Count <= 0) return; // 在没有读入数据时,不需要绘制图形 + + Graphics g = e.Graphics; + g.Clear(Color.White); + g.Transform = transform; + + for (int i = 0; i < shpList.Count; i++) + if (shpList[i].IsRender) + foreach (var shape in shpList[i]) + shape.Render(g); + + + } + + private void browseMifBtn_Click(object sender, EventArgs e) + { + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "Mif files (*.mif)|*.mif|All files (*.*)|*.*"; + saveFileDialog.Title = "选择保存文件"; + saveFileDialog.InitialDirectory = Application.StartupPath; + saveFileDialog.RestoreDirectory = true; + saveFileDialog.ShowDialog(); + + mifPath.Text = saveFileDialog.FileName; + } + + private void saveMifBtn_Click(object sender, EventArgs e) + { + string savePath = mifPath.Text; + if (savePath.Length == 0) return; + if (shpList.Count == 0) return; + + shpList.ElementAt(0).SaveAsMif(savePath); + + MessageBox.Show("保存成功"); + + } + private void DrawPanel_MouseWheel(object sender, MouseEventArgs e) + { + if (shpList.Count > 0) + { + PointF now_pos = new PointF(e.X, e.Y); + PointF[] pos = new PointF[1]; + pos[0] = now_pos; + var trans_inv = transform.Clone(); + trans_inv.Invert(); + trans_inv.TransformPoints(pos); + if (e.Delta > 0) + transform.Scale(e.Delta / 100f, e.Delta / 100f); + else + transform.Scale(-100f / e.Delta, -100f / e.Delta); + PointF[] pos_scale = new PointF[1]; + pos_scale[0] = now_pos; + trans_inv = transform.Clone(); + trans_inv.Invert(); + trans_inv.TransformPoints(pos_scale); + float dx = pos_scale[0].X - pos[0].X; + float dy = pos_scale[0].Y - pos[0].Y; + transform.Translate(dx, dy); + DrawPanel.Refresh(); + } + } + + private void DrawPanel_MouseMove(object sender, MouseEventArgs e) + { + if (shpList.Count != 0) + { + PointF now_pos = new PointF(e.X, e.Y); + PointF[] pos_coord = new PointF[1]; + pos_coord[0] = now_pos; + if (e.Button == MouseButtons.Left) + { + this.Cursor = Cursors.Hand; + PointF[] pos = new PointF[2]; + pos[0] = mouse_pos; + pos[1] = now_pos; + var trans_inv = transform.Clone(); + trans_inv.Invert(); + trans_inv.TransformPoints(pos); + float dx = pos[1].X - pos[0].X; + float dy = pos[1].Y - pos[0].Y; + transform.Translate(dx, dy); + DrawPanel.Refresh(); + } + var trans_inv1 = transform.Clone(); + trans_inv1.Invert(); + trans_inv1.TransformPoints(pos_coord); + coorStatusLabel.Text = "当前X、Y坐标:" + pos_coord[0].X + ", " + pos_coord[0].Y; + } + mouse_pos = new PointF(e.X, e.Y); + } + private void DrawPanel_MouseClick(object sender, MouseEventArgs e) + { + + } + + private void DrawPanel_MouseUp(object sender, MouseEventArgs e) + { + this.Cursor = Cursors.Default; + } + + private void DrawPanel_MouseDoubleClick(object sender, MouseEventArgs e) + { + InitScale(); + DrawPanel.Refresh(); + } + + private void InitScale() + { + float w = DrawPanel.Width; + float h = DrawPanel.Height; + float max_left = Convert.ToSingle(shpList[0].BoundingBox.Left); + float max_right= Convert.ToSingle(shpList[0].BoundingBox.Right); + float max_top = Convert.ToSingle(shpList[0].BoundingBox.Top); + float max_bottom= Convert.ToSingle(shpList[0].BoundingBox.Bottom); + for (int i = 1; i < shpList.Count; i++) + { + if (shpList[i].BoundingBox.Left < max_left) + max_left = Convert.ToSingle(shpList[i].BoundingBox.Left); + if (shpList[i].BoundingBox.Right > max_right) + max_right = Convert.ToSingle(shpList[i].BoundingBox.Right); + if (shpList[i].BoundingBox.Bottom < max_bottom) + max_bottom = Convert.ToSingle(shpList[i].BoundingBox.Bottom); + if (shpList[i].BoundingBox.Top > max_top) + max_top = Convert.ToSingle(shpList[i].BoundingBox.Top); + } + + float data_width = max_right - max_left; + float data_height = max_top - max_bottom; + float sx = w / (data_width * 1.02f); + float sy = h / (data_height * 1.02f); + float dx = 0.0f; + float dy = 0.0f; + if (sx > sy) + { + sx = sy; + dx = (data_width - w / sx) / 2.0f; // 调整横向比例,横向居中 + } + else + { + sy = sx; + dy = (data_height - h / sy) / 2.0f; // 调整纵向比例,纵向居中 + } + Matrix new_trans = new Matrix(); + + new_trans.Scale(sx, -sy); + new_trans.Translate(-max_left + data_width * 0.01f - dx, + -max_top - data_height * 0.01f + dy); + transform = new_trans; } } } diff --git a/ShapeFileViewer/MainForm.resx b/ShapeFileViewer/MainForm.resx index 7893ed4d518dc2fddd59c68d4abff7d456588dd6..dd8173283d975334e3755780b790b48aba6347c7 100644 --- a/ShapeFileViewer/MainForm.resx +++ b/ShapeFileViewer/MainForm.resx @@ -195,18 +195,87 @@ Top, Bottom, Left, Right - - Top, Bottom, Left, Right + + tabPage1 - - 0, 0 + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 623, 410 + + tabControl1 - + 0 + + tabPage2 + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tabControl1 + + + 1 + + + 3, 3 + + + 636, 438 + + + 1 + + + tabControl1 + + + System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + splitContainer1.Panel2 + + + 0 + + + splitContainer1.Panel2 + + + System.Windows.Forms.SplitterPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + splitContainer1 + + + 1 + + + 400 + + + 870, 444 + + + 224 + + + 4 + + + splitContainer1 + + + System.Windows.Forms.SplitContainer, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + DrawPanel @@ -246,16 +315,28 @@ 0 - - Fill + + Top, Bottom, Left, Right - - 3, 3 + + 0, 0 - - 620, 404 + + 623, 410 - + + 0 + + + DrawPanel + + + System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tabPage1 + + 0 @@ -297,78 +378,33 @@ 1 - - 3, 3 - - - 636, 438 - - - 1 - - - tabControl1 + + Fill - - System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 3, 3 - - splitContainer1.Panel2 + + 620, 404 - + 0 - - splitContainer1.Panel2 - - - System.Windows.Forms.SplitterPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - splitContainer1 - - - 1 - - - 400 - - - 870, 444 - - - 224 - - - 4 - - - splitContainer1 + + dbfdataGridView - - System.Windows.Forms.SplitContainer, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.DataGridView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - $this + + tabPage2 - - 2 + + 0 17, 17 - - 160, 22 - - - 打开Shape文件 - - - 44, 21 - - - 文件 - 0, 0 @@ -393,21 +429,21 @@ 3 - - 137, 17 - - - 68, 17 + + 44, 21 - - 当前图层: + + 文件 - - 83, 17 + + 160, 22 - - 当前XY坐标: + + 打开Shape文件 + + 137, 17 + 0, 566 @@ -432,9 +468,81 @@ 1 + + 68, 17 + + + 当前图层: + + + 83, 17 + + + 当前XY坐标: + Bottom, Left, Right + + Right + + + NoControl + + + 783, 48 + + + 75, 21 + + + 3 + + + 保存 + + + saveMifBtn + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 0 + + + Right + + + NoControl + + + 702, 49 + + + 75, 21 + + + 3 + + + 浏览 + + + browseMifBtn + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 1 + Right @@ -463,7 +571,37 @@ panel1 - 0 + 2 + + + NoControl + + + 12, 52 + + + 115, 18 + + + 2 + + + 保存到Mif文件: + + + MiddleCenter + + + mifLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 3 Right @@ -490,8 +628,32 @@ panel1 + 4 + + + Top, Bottom, Left, Right + + + 133, 49 + + + 563, 21 + + 1 + + mifPath + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 5 + 12, 16 @@ -517,7 +679,7 @@ panel1 - 2 + 6 Top, Bottom, Left, Right @@ -541,7 +703,7 @@ panel1 - 3 + 7 0, 478 diff --git a/Shapefile/ESRIPoint.cs b/Shapefile/ESRIPoint.cs index 717ba0e18754b9c45feba6da35413ddf98057fe9..a772a0d5cc808b707bba2adc6567d3a342dcfad1 100644 --- a/Shapefile/ESRIPoint.cs +++ b/Shapefile/ESRIPoint.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Specialized; using System.Data; +using System.Drawing; namespace Shapefile { @@ -37,5 +38,13 @@ namespace Shapefile { get { return point_; } } + + public override void Render(Graphics g) + { + float sx = g.Transform.Elements[0]; + float sy = g.Transform.Elements[3]; + Brush brush = new SolidBrush(Color.Red); + g.FillEllipse(brush, Convert.ToSingle(point_.X), Convert.ToSingle(point_.Y), 5/sx, -5/sy); + } } } diff --git a/Shapefile/ESRIPolyLine.cs b/Shapefile/ESRIPolyLine.cs index c43ad04d12e0ff844827f51958b57f999cc42b3f..541f2145b87c2cd841fff37b31e0e2c49a9ab149 100644 --- a/Shapefile/ESRIPolyLine.cs +++ b/Shapefile/ESRIPolyLine.cs @@ -3,6 +3,9 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.Data; using System.Text; +using System.Drawing; +using System.Drawing.Text; +using System.Drawing.Drawing2D; namespace Shapefile { @@ -30,5 +33,27 @@ namespace Shapefile { get { return parts_; } } + + public override void Render(Graphics g) + { + float sx = g.Transform.Elements[0]; + float sy = g.Transform.Elements[3]; + float pen_width = 1.0f / (sx - sy) * 2; + Pen pen = new Pen(Color.Blue, pen_width); + + for (int i = 0; i < parts_.Count; i++) + { + GraphicsPath path = new GraphicsPath(); + PointF[] temp = new PointF[parts_[i].Length]; + for (int j = 0; j < parts_[i].Length; j++) + { + temp[j].X = Convert.ToSingle(parts_[i][j].X); + temp[j].Y = Convert.ToSingle(parts_[i][j].Y); + } + path.FillMode = FillMode.Alternate; + path.AddLines(temp); + g.DrawPath(pen, path); + } + } } } diff --git a/Shapefile/ESRIPolygon.cs b/Shapefile/ESRIPolygon.cs index 1165f636d26e13083bb815aba40797dc0dd6d445..08c2eafcc954f9c481c53df05a6561faadfe9866 100644 --- a/Shapefile/ESRIPolygon.cs +++ b/Shapefile/ESRIPolygon.cs @@ -3,6 +3,9 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.Data; using System.Text; +using System.Drawing; +using System.Linq; +using System.Drawing.Drawing2D; namespace Shapefile { @@ -26,5 +29,30 @@ namespace Shapefile { get { return parts_; } } + + public override void Render(Graphics g) + { + float sx = g.Transform.Elements[0]; + float sy = g.Transform.Elements[3]; + float pen_width = 1.0f / (sx - sy) * 2; + Pen pen = new Pen(Color.Blue, pen_width); + Brush brush = new SolidBrush(Color.AliceBlue); + for (int i=0;i GetEnumerator() { @@ -261,9 +372,7 @@ namespace Shapefile indexStream_, count_); } - #endregion - #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { diff --git a/Shapefile/Shapefile.csproj b/Shapefile/Shapefile.csproj index 07270653cdf533f7989a8ad58231ac4ec227d989..28c733c1a63fdc6f6c43b272ce31e7398bd9ef43 100644 --- a/Shapefile/Shapefile.csproj +++ b/Shapefile/Shapefile.csproj @@ -33,6 +33,7 @@ +