/// <summary> /// 生成椭圆 /// </summary> public IEllipticArc GenerateEllipticArc(IPoint pCenterPoint, double rotationAngle, double Descripe, double Seismic) { Core.DAL.DisaParameter disapara = new DAL.DisaParameter(); List <Core.Model.DisaParameter> listdisapara = new List <Model.DisaParameter>(); listdisapara = disapara.GetList();//读取灾区范围参数 double MajorAxis = 0; double MinorAxis = 0; for (int i = 0; i < listdisapara.Count; i++) { if (listdisapara[i].isMajorAxis) { //根据地震等级和烈度计算出长短轴 MajorAxis = System.Math.Pow(10, (listdisapara[i].A + listdisapara[i].B * Convert.ToDouble(Descripe) - Seismic) / listdisapara[i].C) - listdisapara[i].D;//长半轴 } else { MinorAxis = System.Math.Pow(10, (listdisapara[i].A + listdisapara[i].B * Convert.ToDouble(Descripe) - Seismic) / listdisapara[i].C) - listdisapara[i].D;//短半轴 } } if (MajorAxis <= 0 || MinorAxis <= 0) { MessageBox.Show("输入烈度过大!"); return(null); } double ratio; if (MajorAxis > MinorAxis) { ratio = MinorAxis / MajorAxis; } else { ratio = MajorAxis / MinorAxis; } IEllipticArc ellipticArc = new EllipticArcClass(); //ellipticArc.PutCoordsByAngle(基准,中心点,起点角度,椭圆圆心角,旋转角度,长轴,长短轴之比);轴长单位为米,角度单位为弧度 ellipticArc.PutCoordsByAngle(false, pCenterPoint, 0, 2 * Math.PI, rotationAngle * Math.PI / 180, (double)MajorAxis / Core.Generic.SysEnviriment.LengthPerRad * 2, ratio); ISegment segment = ellipticArc as ISegment; ISegmentCollection polygon = new Polygon() as ISegmentCollection; object Missing = Type.Missing; polygon.AddSegment(segment, ref Missing, ref Missing); //图上显示 Color color = Color.Red; ISymbol symbol = CreateSimpleFillSymbol(color, 1, esriSimpleFillStyle.esriSFSHollow); AddElement(polygon as IGeometry, symbol, "result"); IEnvelope envelope; envelope = ellipticArc.Envelope; if (!envelope.IsEmpty) { envelope.Expand(1, 1, true); } mapControl.Extent = envelope; this.mapControl.Refresh(); return(ellipticArc); }
//确定键 private void buttonOK_Click(object sender, EventArgs e) { double dL = 0.0, dB = 0.0, dZJ = 0.0, dTransAngle = 0.0; bool bL = double.TryParse(textBoxLong.Text, out dL); //经度 bool bB = double.TryParse(textBoxLat.Text, out dB); //纬度 bool bZJ = double.TryParse(textBoxLevel.Text, out dZJ); //震级 bool bTransAngle = double.TryParse(txtTransAngle.Text, out dTransAngle); //旋转角 time = textBoxTime.Text; //开启编辑状态 IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass(); IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(dataFile, 0) as IFeatureWorkspace; IWorkspaceEdit pWorkspaceEdit = pFeatureWorkspace as IWorkspaceEdit; pWorkspaceEdit.StartEditing(false); pWorkspaceEdit.StartEditOperation(); //插入震中点数据 IFeatureClass pFeatureClassPoint = pFeatureLayerPoint.FeatureClass; IFeatureClassWrite fwritePoint = pFeatureClassPoint as IFeatureClassWrite; IFeature pFeaturePoint = pFeatureClassPoint.CreateFeature(); IPointCollection pointCollection = new MultipointClass(); IPoint pPoint = new PointClass(); IGeoDataset pGeoDataset = pFeatureClassPoint as IGeoDataset; //记录空间投影信息 ISpatialReference spatialReference = pGeoDataset.SpatialReference; //输入经纬度 pPoint.PutCoords(dL, dB); pPoint.SpatialReference = spatialReference; pointCollection.AddPoint(pPoint, ref _missing, ref _missing); pFeaturePoint.Shape = pointCollection as IGeometry; //设置“标注”属性值 pFeaturePoint.set_Value(3, time); fwritePoint.WriteFeature(pFeaturePoint); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaturePoint); //记录屏幕显示区域 IEnvelope pEnvelope = null; //生成地震烈度椭圆 //当都输入值的时候,生成椭圆 if (bL && bB && bZJ && bTransAngle) { IGraphicsContainer graphicsContainer = _MainPageLayoutControl.ActiveView.FocusMap as IGraphicsContainer; string sElementName = "zjEllipticArc"; DelectElementByName(graphicsContainer, sElementName); List <EllipticArcPro> pListEllipticArcPro = CalculatEllipticArc(pPoint, dZJ, dTransAngle); int tot = pListEllipticArcPro.Count; int iCount = 1; foreach (EllipticArcPro pEllipticArcPro in pListEllipticArcPro) { IEllipticArc pEll = new EllipticArcClass(); if (tot == 3) { pEll.PutCoordsByAngle(pEllipticArcPro.ellipseStd, pEllipticArcPro.CenterPoint, pEllipticArcPro.FromAngle, pEllipticArcPro.CentralAngle, pEllipticArcPro.rotationAngle, pEllipticArcPro.semiMajor / 100000, pEllipticArcPro.minorMajorRatio); } else { pEll.PutCoordsByAngle(pEllipticArcPro.ellipseStd, pEllipticArcPro.CenterPoint, pEllipticArcPro.FromAngle, pEllipticArcPro.CentralAngle, pEllipticArcPro.rotationAngle, pEllipticArcPro.semiMajor / 100000, pEllipticArcPro.minorMajorRatio); } IGeometry pGeo = EllipticArcTransPolygon(pEll); pGeo.SpatialReference = spatialReference; IPolygon pPloy = pGeo as IPolygon; if (iCount == 1) //第一个烈度图层 { IFeatureClass pFeatureClass8LD = pFeatureLayer8LD.FeatureClass; IFeatureClassWrite fwrite8LD = pFeatureClass8LD as IFeatureClassWrite; IFeature pFeature8LD = pFeatureClass8LD.CreateFeature(); pFeature8LD.Shape = pPloy; fwrite8LD.WriteFeature(pFeature8LD); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature8LD); pFeature8LD = null; if (dZJ > 5.3) { iCount++; } //更新显示区域 IActiveView pAV = _MainPageLayoutControl.ActiveView.FocusMap as IActiveView; pEnvelope = pPloy.Envelope; pEnvelope.Expand(1.8, 1.8, true); pAV.Extent = pEnvelope; pAV.Refresh(); } else if (iCount == 2) { IFeatureClass pFeatureClass7LD = pFeatureLayer7LD.FeatureClass; IFeatureClassWrite fwrite7LD = pFeatureClass7LD as IFeatureClassWrite; IFeature pFeature7LD = pFeatureClass7LD.CreateFeature(); pFeature7LD.Shape = pPloy; fwrite7LD.WriteFeature(pFeature7LD); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature7LD); pFeature7LD = null; if (tot == 3) { iCount++; } } else if (iCount == 3) { IFeatureClass pFeatureClass6LD = pFeatureLayer6LD.FeatureClass; IFeatureClassWrite fwrite6LD = pFeatureClass6LD as IFeatureClassWrite; IFeature pFeature6LD = pFeatureClass6LD.CreateFeature(); pFeature6LD.Shape = pPloy; fwrite6LD.WriteFeature(pFeature6LD); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature6LD); pFeature6LD = null; iCount++; } } } pFeaturePoint = null; pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); this.Hide(); setFormIPoint(pPoint, textBoxLevel.Text, pEnvelope); //修改标题 IElement pElementTitle = _MainPageLayoutControl.FindElementByName("Title"); ITextElement pTextElementTitle = pElementTitle as ITextElement; string sXZQName = GetXZQName(pPoint); string sText = sXZQName + "M" + textBoxLevel.Text + "级地震震区水库分布图"; pTextElementTitle.Text = sText; MessageBox.Show("操作成功!", "提示"); }