private void dgrdvZhzzt_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 4 && Alert.confirm(Const.DEL_CONFIRM_MSG)) { //删除 if (GIS.Common.DataEditCommon.DeleteFeatureByWhereClause(frmzhzzt.pFeatureClass, "BID='" + dgrdvZhzzt.Rows[e.RowIndex].Cells[2].Value.ToString() + "'")) { binddata(); } } if (e.ColumnIndex == 5) { //打开 string bid = dgrdvZhzzt.Rows[e.RowIndex].Cells[2].Value.ToString(); string bilichi = dgrdvZhzzt.Rows[e.RowIndex].Cells[3].Value.ToString(); List <ESRI.ArcGIS.Geometry.IGeometry> listgeo = new List <ESRI.ArcGIS.Geometry.IGeometry>(); IQueryFilter pFilter = new QueryFilterClass(); pFilter.WhereClause = "BID='" + bid + "'"; IFeatureCursor pCursor = frmzhzzt.pFeatureClass.Search(pFilter, false); IFeature pFeature = pCursor.NextFeature(); while (pFeature != null) { listgeo.Add(pFeature.Shape); pFeature = pCursor.NextFeature(); } frmzhzzt.pGeometry = MyMapHelp.GetGeoFromGeos(listgeo); frmzhzzt.BID = bid; frmzhzzt.blc = Convert.ToDouble(bilichi); DialogResult = DialogResult.OK; this.Close(); } if (e.ColumnIndex == 6) { //修改 this.Close(); string bid = dgrdvZhzzt.Rows[e.RowIndex].Cells[2].Value.ToString(); FrmNewZHZZT frm = new FrmNewZHZZT(frmzhzzt, bid); frm.Show(frmzhzzt); } if (e.ColumnIndex == 0) { if (dgrdvZhzzt.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString().ToLower() == "true") { dgrdvZhzzt.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = false; } else { dgrdvZhzzt.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = true; } } }
private void FrmZhzzt_Load(object sender, EventArgs e) { axMapControlZZT.LoadMxFile(Application.StartupPath + @"\综合柱状图.mxd"); pLayer = DataEditCommon.GetLayerByName(axMapControlZZT.Map, LayerNames.LAYER_ALIAS_MR_Zhuzhuang); ESRI.ArcGIS.Carto.IFeatureLayer pFeatureLayer = (ESRI.ArcGIS.Carto.IFeatureLayer)pLayer; pFeatureClass = pFeatureLayer.FeatureClass; if (pFeatureLayer == null) { MessageBox.Show("柱状图图层缺失!"); this.Close(); return; } if (pFeatureClass == null) { MessageBox.Show("柱状图图层缺失!"); this.Close(); return; } if (BID == "" || pGeometry == null) { return; } List <IGeometry> listgeo = new List <IGeometry>(); IQueryFilter pFilter = new QueryFilterClass(); pFilter.WhereClause = "BID='" + BID + "'"; IFeatureCursor pCursor = pFeatureClass.Search(pFilter, false); IFeature pFeature = pCursor.NextFeature(); while (pFeature != null) { listgeo.Add(pFeature.Shape); pFeature = pCursor.NextFeature(); } pGeometry = setgeo(MyMapHelp.GetGeoFromGeos(listgeo)); axMapControlZZT.Extent = pGeometry.Envelope; axMapControlZZT.MapScale = blc; axMapControlZZT.ActiveView.Refresh(); }
/// <summary> /// Check数据是否在矿界范围之内。 /// </summary> /// <params name="file"></params> /// <returns></returns> private bool withIn(string file) { try { bool within = true; ILayer pLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MINE_BOUNDARY); if (pLayer == null) { MessageBox.Show("煤层矿界图层缺失!"); return(false); } IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IQueryFilter pFilter = new QueryFilterClass(); pFilter.WhereClause = "layer='预警矿界'"; IFeatureCursor pCursor = pFeatureClass.Search(pFilter, false); IFeature pFeature = pCursor.NextFeature(); List <IGeometry> list = new List <IGeometry>(); if (pFeature == null) { return(false); } ISegmentCollection pSegmentCollection = new PolygonClass(); while (pFeature != null) { list.Add(pFeature.Shape); pFeature = pCursor.NextFeature(); } IGeometry pgeoLine = MyMapHelp.GetGeoFromGeos(list); pSegmentCollection = pgeoLine as ISegmentCollection; IPolyline pPolyline = pSegmentCollection as IPolyline; IPolygon pPolygon = DataEditCommon.PolylineToPolygon(pPolyline); string[] liststr = File.ReadAllLines(file); list = new List <IGeometry>(); IPoint pt = new PointClass(); double x, y; for (int i = 0; i < liststr.Length; i++) { pt = new PointClass(); if (!double.TryParse(liststr[i].Split(',')[0], out x) || !double.TryParse(liststr[i].Split(',')[1], out y)) { MessageBox.Show("存在非数字的坐标,请检查!"); return(false); } pt.X = x; pt.Y = y; list.Add(pt); } if (list.Count < 3) { MessageBox.Show("离散点数据为空或小于三个,无法生成等值线!"); return(false); } for (int i = 0; i < liststr.Length; i++) { for (int j = 0; j < liststr.Length; j++) { if (liststr[i].Split(',')[0] == liststr[j].Split(',')[0] && liststr[i].Split(',')[1] == liststr[j].Split(',')[1] && liststr[i].Split(',')[2] == liststr[j].Split(',')[2] && i != j) { MessageBox.Show("存在重复点,请检查!"); return(false); } } } List <IGeometry> listrt = MyMapHelp.withIn(pPolygon, list); if (listrt.Count > 0) { within = false; DialogResult dr = MessageBox.Show("存在超边界的坐标,是否立即查看?", "", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { string strlen = ""; for (int i = 0; i < listrt.Count; i++) { pt = listrt[i] as IPoint; strlen += pt.X.ToString() + "," + pt.Y.ToString() + " \r\n"; } string filename = Application.StartupPath + "\\ContentError.txt"; File.WriteAllText(filename, strlen); Process.Start(filename); } } return(within); } catch (Exception ex) { MessageBox.Show("获取矿界失败!" + ex.Message); return(false); } }
private void btnSubmit_Click(object sender, EventArgs e) { //1煤2碳化灰岩3粉砂质泥岩4泥岩5泥质粉砂岩 IWorkspaceEdit workspaceEdit = null; try { labelSC.Visible = true; Application.DoEvents(); //去除无用空行 for (int i = 0; i < dgrdvZhzzt.RowCount - 1; i++) { if (this.dgrdvZhzzt.Rows[i].Cells[0].Value == null && this.dgrdvZhzzt.Rows[i].Cells[1].Value == null && this.dgrdvZhzzt.Rows[i].Cells[2].Value == null) { this.dgrdvZhzzt.Rows.RemoveAt(i); } } //验证 if (!check()) { this.DialogResult = DialogResult.None; return; } this.DialogResult = DialogResult.OK; if (isadd) { bid = IDGenerator.NewBindingID(); } //实体赋值 Histogram historam = new Histogram(); historam.HistogramEntName = txtname.Text.Trim(); historam.BLC = Convert.ToDouble(txtBlc.Text.Trim()); historam.ID = bid; historam.listMY = new List <Historgramlist>(); double height = 0; for (int i = 0; i < dgrdvZhzzt.RowCount - 1; i++) { Historgramlist hisl = new Historgramlist(); hisl.BID = bid; hisl.Index = (i + 1); //煤岩名称 DataGridViewTextBoxCell cell = dgrdvZhzzt.Rows[i].Cells[0] as DataGridViewTextBoxCell; hisl.MYName = cell.Value.ToString(); cell = dgrdvZhzzt.Rows[i].Cells[1] as DataGridViewTextBoxCell; hisl.Height = Convert.ToDouble(cell.Value.ToString()); height += hisl.Height; hisl.SHeight = height; hisl.ZZType = ZZStrToCode(dgrdvZhzzt.Rows[i].Cells[2].Value.ToString()); cell = dgrdvZhzzt.Rows[i].Cells[3] as DataGridViewTextBoxCell; if (cell.Value != null) { hisl.Describe = cell.Value.ToString(); } historam.listMY.Add(hisl); } if (!isadd) { DataEditCommon.DeleteFeatureByWhereClause(frmZhzzt.pFeatureClass, "BID='" + bid + "'"); } progressBar1.Maximum = historam.listMY.Count * 6 + 9; progressBar1.Value = 0; IFeatureClass pFeatureClass = frmZhzzt.pFeatureClass; progressBar1.Value += 1; Application.DoEvents(); IDataset dataset = (IDataset)pFeatureClass; IWorkspace workspace = dataset.Workspace; workspaceEdit = workspace as IWorkspaceEdit; workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); ISegmentCollection pSegmentCollection = new PolygonClass(); double xbasic = 100; double xmin = xbasic, ymin = 99.5, xmax = 110, ymax = 100; List <IGeometry> listgeo = new List <IGeometry>(); IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(xmin, ymin, xmax, ymax); List <ziduan> listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", historam.HistogramEntName)); listzd.Add(new ziduan("zztype", "6")); listzd.Add(new ziduan("strtype", "1")); listzd.Add(new ziduan("bilici", historam.BLC.ToString())); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); ymax = ymin; ymin -= 0.3; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "比例 1:" + historam.BLC.ToString() + " 单位:米")); listzd.Add(new ziduan("zztype", "6")); listzd.Add(new ziduan("strtype", "2")); listzd.Add(new ziduan("bilici", historam.BLC.ToString())); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); ymax = ymin; ymin -= 0.3; xmax = xmin + 0.6; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "序号")); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 1.8; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "煤 岩 名 称")); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 0.8; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "真厚")); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 1; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "累厚")); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 1.2; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "柱 状")); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 4.6; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "岩 性 描 述")); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); List <Historgramlist> list = historam.ListMY; for (int i = 0; i < list.Count; i++) { xmin = xbasic; double m_height = list[i].Height; if (m_height < 0.3) { m_height = 0.3; } pEnvelope = new EnvelopeClass(); ymax = ymin; ymin -= m_height; xmax = xmin + 0.6; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", list[i].Index.ToString())); listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString())); listzd.Add(new ziduan("xuhaoC", "1")); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 1.8; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", list[i].MYName)); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString())); listzd.Add(new ziduan("xuhaoC", "2")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 0.8; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", list[i].Height.ToString())); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString())); listzd.Add(new ziduan("xuhaoC", "3")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 1; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", Math.Round(list[i].SHeight, 1).ToString())); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString())); listzd.Add(new ziduan("xuhaoC", "4")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 1.2; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "")); listzd.Add(new ziduan("zztype", list[i].ZZType)); listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString())); listzd.Add(new ziduan("xuhaoC", "5")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 4.6; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); string strms = list[i].Describe; string miaoshu = ""; if (strms != null && strms.Length > 0) { ASCIIEncoding ascii = new ASCIIEncoding(); int temLen = 0; byte[] s = ascii.GetBytes(strms); for (int j = 0; j < s.Length; j++) { if ((int)s[j] == 63) { temLen += 2; } else { temLen += 1; } miaoshu += strms[j]; if (temLen % 38 == 0 || (temLen + 1) % 38 == 0) { if (miaoshu.LastIndexOf('|') != miaoshu.Length - 1) { miaoshu += "|"; } } } } listzd.Add(new ziduan("textstr", miaoshu)); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString())); listzd.Add(new ziduan("xuhaoC", "6")); listzd.Add(new ziduan("strtype", "3")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); } workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); frmZhzzt.pGeometry = MyMapHelp.GetGeoFromGeos(listgeo); frmZhzzt.BID = historam.ID; frmZhzzt.blc = historam.BLC; DialogResult = DialogResult.OK; this.Close(); if (!isadd) { frmZhzzt.refresh(); } } catch (Exception ex) { labelSC.Visible = false; MessageBox.Show(ex.Message); if (workspaceEdit != null) { workspaceEdit.AbortEditOperation(); workspaceEdit.StopEditing(false); } } }