private void FillValue()//初始化DataGridView的部分移动到了此函数中 { DataTable table = new DataTable(); //增加ID列 table.Columns.Add("ID"); //增加其他列 用以记录所有字段 for (int i = 0; i < Layer.Fields.Count; i++) { table.Columns.Add(Layer.Fields[i].name); } //增加行 填充属性值 for (int i = 0; i < Layer.FeatureCount(); i++) { DataRow r = table.NewRow(); r.BeginEdit(); r[0] = Layer.GetFeature(i).ID; for (int j = 0; j < Layer.Fields.Count; j++) { r[j + 1] = Layer.GetFeature(i).getAttribute(j); } r.EndEdit(); table.Rows.Add(r); //dataGridView1.Rows.Add(); ////增加ID值 //dataGridView1.Rows[i].Cells[0].Value = Layer.GetFeature(i).ID; ////增加其他属性值 //for (int j = 0; j < Layer.Fields.Count; j++) //{ // dataGridView1.Rows[i].Cells[j+1].Value = Layer.GetFeature(i).getAttribute(j); //} ////确定每行的选择状态 //dataGridView1.Rows[i].Selected = Layer.GetFeature(i).Selected; } //指定数据源 dataGridView1.DataSource = table; //更新选择状态 for (int i = 0; i < Layer.FeatureCount(); i++) { dataGridView1.Rows[i].Selected = Layer.GetFeature(i).Selected; } }
static void WriteFileHeader(GISLayer layer, BinaryWriter bw)//bw是与文件相连的文件写入工具 { MyFileHeader mfh = new MyFileHeader(); mfh.MinX = layer.Extent.getMinX(); mfh.MinY = layer.Extent.getMinY(); mfh.MaxX = layer.Extent.getMaxX(); mfh.MaxY = layer.Extent.getMaxY(); mfh.FeatureCount = layer.FeatureCount(); mfh.Shapetype = (int)(layer.ShapeType); mfh.FieldCount = layer.Fields.Count; bw.Write(GISTools.ToBytes(mfh)); }
//输出图层所有GISFeatrue static void WriteFeatures(GISLayer layer, BinaryWriter bw) { for (int featureindex = 0; featureindex < layer.FeatureCount(); featureindex++) { GISFeature feature = layer.GetFeature(featureindex); if (layer.ShapeType == SHAPETYPE.point) { ((GISPoint)feature.spatialpart).centroid.WriteVertex(bw); } else if (layer.ShapeType == SHAPETYPE.line) { GISLine line = (GISLine)(feature.spatialpart); WriteMultipleVertexes(line.Vertexes, bw); } else if (layer.ShapeType == SHAPETYPE.polygon) { GISPolygon polygon = (GISPolygon)(feature.spatialpart); WriteMultipleVertexes(polygon.Vertexes, bw); } WriteAttributes(feature.attributepart, bw); } }
private void FillValue()//初始化DataGridView的部分移动到了此函数中 { //增加ID列 dataGridView1.Columns.Add("ID", "ID"); //增加其他列 用以记录所有字段 for (int i = 0; i < Layer.Fields.Count; i++) { dataGridView1.Columns.Add(Layer.Fields[i].name, Layer.Fields[i].name); } //增加行 for (int i = 0; i < Layer.FeatureCount(); i++) { dataGridView1.Rows.Add(); //增加ID值 dataGridView1.Rows[i].Cells[0].Value = Layer.GetFeature(i).ID; //增加其他属性值 for (int j = 0; j < Layer.Fields.Count; j++) { dataGridView1.Rows[i].Cells[j + 1].Value = Layer.GetFeature(i).getAttribute(j); } //确定每行的选择状态 dataGridView1.Rows[i].Selected = Layer.GetFeature(i).Selected; } }