private void AddCircleElement(IGeometry pGeo, IActiveView pAv) { ISegmentCollection pSegColl; pSegColl = new PolygonClass(); object Missing1 = Type.Missing; object Missing2 = Type.Missing; pSegColl.AddSegment(pGeo as ISegment, ref Missing1, ref Missing2); ISimpleLineSymbol pLineSym; pLineSym = new SimpleLineSymbolClass(); pLineSym.Color = getRGB(110, 22, 125); pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; ISimpleFillSymbol pSimpleFillSym; pSimpleFillSym = new SimpleFillSymbolClass(); pSimpleFillSym.Color = getRGB(66, 55, 145); pSimpleFillSym.Outline = pLineSym; pSimpleFillSym.Style = esriSimpleFillStyle.esriSFSCross; IElement pPolygonEle; pPolygonEle = new CircleElementClass(); pPolygonEle.Geometry = pSegColl as IGeometry; IFillShapeElement pFillEle; pFillEle = pPolygonEle as IFillShapeElement; pFillEle.Symbol = pSimpleFillSym; IGraphicsContainer pGraphicsContainer; pGraphicsContainer = pAv as IGraphicsContainer; pGraphicsContainer.AddElement(pFillEle as IElement, 0); pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void btnOK_Click(object sender, EventArgs e) { double num = double.Parse(this.txtXCoor.Text); double num2 = double.Parse(this.txtYCoor.Text); double radius = double.Parse(this.txtRadio.Text); if (this.imap_0.MapUnits != esriUnits.esriKilometers) { num *= 1000.0; num2 *= 1000.0; radius *= 1000.0; } IPoint centerPoint = new PointClass { X = num, Y = num2 }; ICircularArc arc = new CircularArcClass(); (arc as IConstructCircularArc).ConstructCircle(centerPoint, radius, false); ISegmentCollection segments = new PolygonClass(); object before = Missing.Value; segments.AddSegment(arc as ISegment, ref before, ref before); this.igeometry_0 = segments as IGeometry; base.DialogResult = DialogResult.OK; }
public void AddCreateElement(IGeometry pCircularArc, IActiveView pAV) { IFillShapeElement pElemFillShp; IElement pElem; ISimpleFillSymbol pSFSym; ISegmentCollection pSegColl = new PolygonClass(); object missing = Type.Missing; ISegment segement = (ISegment)pCircularArc; pSegColl.AddSegment(segement, missing, missing); pElem = new CircleElementClass(); pElem.Geometry = (IGeometry)pSegColl; pElemFillShp = (IFillShapeElement)pElem; pSFSym = new SimpleFillSymbolClass(); Color color = ColorTranslator.FromHtml(SystemInfo.Instance.FillColor); IColor pColor = new RgbColorClass(); pColor.RGB = color.B * 65536 + color.G * 256 + color.R; pSFSym.Color = pColor; pSFSym.Style = esriSimpleFillStyle.esriSFSSolid; pElemFillShp.Symbol = pSFSym; pGraphicsContainer = pAV as IGraphicsContainer; pGraphicsContainer.AddElement(pElem, 0); }
/// <summary> /// 创建图形元素 /// </summary> /// <param name="pGeometry">几何图形</param> /// <param name="lineColor">边框颜色</param> /// <param name="fillColor">填充颜色</param> /// <returns></returns> private static IElement CreateElement(IGeometry pGeometry, IRgbColor lineColor, IRgbColor fillColor) { if (pGeometry == null || lineColor == null || fillColor == null) { return(null); } IElement pElem = null; try { if (pGeometry is IEnvelope) { pElem = new RectangleElementClass(); } else if (pGeometry is IPolygon) { pElem = new PolygonElementClass(); } else if (pGeometry is ICircularArc) { ISegment pSegCircle = pGeometry as ISegment;//QI ISegmentCollection pSegColl = new PolygonClass(); object o = Type.Missing; pSegColl.AddSegment(pSegCircle, ref o, ref o); IPolygon pPolygon = pSegColl as IPolygon; pGeometry = pPolygon as IGeometry; pElem = new CircleElementClass(); } else if (pGeometry is IPolyline) { pElem = new LineElementClass(); } if (pElem == null) { return(null); } pElem.Geometry = pGeometry; IFillShapeElement pFElem = pElem as IFillShapeElement; ISimpleFillSymbol pSymbol = new SimpleFillSymbolClass(); pSymbol.Color = fillColor; pSymbol.Outline.Color = lineColor; pSymbol.Style = esriSimpleFillStyle.esriSFSCross; if (pSymbol == null) { return(null); } pFElem.Symbol = pSymbol; } catch (Exception ex) { MessageBox.Show(ex.Message); } return(pElem); }
//圆弧(线)转圆几何 public static IGeometry GetCircleGeometry(ICircularArc pCircularArc) { ISegmentCollection pSegmentCollection = new PolygonClass(); object missing1 = System.Type.Missing; object missing2 = System.Type.Missing; pSegmentCollection.AddSegment(pCircularArc as ISegment, ref missing1, ref missing2); IGeometry pGeometry = pSegmentCollection as IGeometry; return pGeometry; }
//圆弧(线)转多边形(圆) public static IPolygon CircularArcToPolygon(ICircularArc pCircularArc) { ISegmentCollection pSegmentCollection = new PolygonClass(); object missing1 = System.Type.Missing; object missing2 = System.Type.Missing; pSegmentCollection.AddSegment(pCircularArc as ISegment, ref missing1, ref missing2); IPolygon pPolygon = pSegmentCollection as IPolygon; return pPolygon; }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { if (button == 1) { int dis; IRubberBand pRubberBand; pRubberBand = new RubberCircleClass(); IGeometry pCircle; ISegmentCollection pSegColl = new PolygonClass(); pCircle = pRubberBand.TrackNew(m_Display, null); object a = Type.Missing; pSegColl.AddSegment((ISegment)pCircle, ref a, ref a); dis = Class.SelectionEnv.System_Selection_Environment(m_ActiveView).SearchTolerance; IFeatureSelection pFeaSel = m_pCurEditLayer as IFeatureSelection; IGeometry pGeoSel = Class.Common.DoBuffer((IPolygon)pSegColl, dis); ISpatialFilter pSpaFilter = new SpatialFilter(); pSpaFilter.Geometry = pGeoSel; pSpaFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; if (shift == 1) { pFeaSel.CombinationMethod = esriSelectionResultEnum.esriSelectionResultAdd; //Class.SelectionEnv.System_Selection_Environment(m_ActiveView).CombinationMethod = esriSelectionResultEnum.esriSelectionResultAdd; } if (Class.SelectionEnv.System_Selection_Environment(m_ActiveView).CombinationMethod == 0)//new selection { this.m_ActiveView.FocusMap.ClearSelection(); } else { pFeaSel.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; this.m_ActiveView.FocusMap.ClearSelection(); } pFeaSel.SelectFeatures(pSpaFilter, pFeaSel.CombinationMethod, false); //m_ActiveView.FocusMap.SelectByShape(Class.Common.DoBuffer(pLine, dis), Class.SelectionEnv.System_Selection_Environment(m_ActiveView), false); m_App.Workbench.UpdateMenu(); if (m_ActiveView.FocusMap.SelectionCount > 0) { m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); } else { m_ActiveView.Refresh(); } } }
/// <summary> /// 创建图形元素 /// </summary> /// <param name="geometry">几何图形</param> /// <param name="lineColor">边界颜色</param> /// <param name="fillColor">填充颜色</param> /// <returns>图形元素</returns> public static IElement CreateElement(IGeometry geometry, IRgbColor lineColor, IRgbColor fillColor) { if (geometry == null || lineColor == null || fillColor == null) { return(null); } IElement element = null; // 判断图形的类型 if (geometry is IEnvelope) { element = new RectangleElementClass(); } else if (geometry is IPolygon) { element = new PolygonElementClass(); } else if (geometry is ICircularArc) { ISegment segment = geometry as ISegment; ISegmentCollection segmentCollection = new PolygonClass(); segmentCollection.AddSegment(segment, Type.Missing, Type.Missing); IPolygon polygon = segmentCollection as IPolygon; geometry = polygon as IGeometry; element = new CircleElementClass(); } else if (geometry is IPolyline) { element = new LineElementClass(); } if (element == null) { return(null); } element.Geometry = geometry; ISimpleFillSymbol symbol = new SimpleFillSymbolClass(); symbol.Outline.Color = lineColor; symbol.Color = fillColor; symbol.Style = esriSimpleFillStyle.esriSFSCross; if (symbol == null) { return(null); } IFillShapeElement fillShapeElement = element as IFillShapeElement; fillShapeElement.Symbol = symbol; return(element); }
public override void OnMouseUp(int Button, int Shift, int X, int Y) { if (Button != 1) { return; } if (m_lMouseDownCount > 2) { m_lMouseDownCount = 0; ISegmentCollection pSegColl = null; IFeatureLayer featureLayer = m_pCurrentLayer as IFeatureLayer; if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) //创建线要素 { IPolyline pPolyline; pSegColl = new PolylineClass(); pSegColl.AddSegment(m_pCircleArc as ISegment); pPolyline = pSegColl as IPolyline; if (pPolyline.Length < 0.001) { return; } IFeature pFeature = DataEditCommon.CreateUndoRedoFeature(featureLayer, pPolyline); m_hookHelper.FocusMap.SelectFeature(m_pCurrentLayer, pFeature); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewBackground, null, null); } else //创建面要素 { IPolygon pPolygon; pSegColl = new PolygonClass(); pSegColl.AddSegment(m_pCircleArc as ISegment); pPolygon = pSegColl as IPolygon; pPolygon.Close(); if (pPolygon.Length < 0.001) { return; } IFeature pFeature = DataEditCommon.CreateUndoRedoFeature(featureLayer, pPolygon); m_hookHelper.FocusMap.SelectFeature(m_pCurrentLayer, pFeature); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewBackground, null, null); } //局部刷新 //IInvalidArea pInvalidArea = new InvalidAreaClass(); //pInvalidArea.Add(pSegColl); //pInvalidArea.Display = m_hookHelper.ActiveView.ScreenDisplay; //pInvalidArea.Invalidate((short)esriScreenCache.esriAllScreenCaches); m_bCreated = true; } }
/// <summary> /// 根据绘制的圆形创建要素 /// </summary> /// <params name="pLayer"></params> /// <params name="pCircuArc"></params> /// <params name="pScreenDisplay"></params> private void DrawCircleFeature(ILayer pLayer, ICircularArc pCircuArc, IScreenDisplay pScreenDisplay) { if (pLayer == null) { return; } ISegmentCollection pSegmentCollection = null; if (pLayer is IFeatureLayer) { IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; if (pFeatureClass != null) { IPolyline pPolyline = null; IPolygon pPolygon = null; if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { pSegmentCollection = new PolylineClass(); pSegmentCollection.AddSegment(pCircuArc as ISegment); pPolyline = pSegmentCollection as IPolyline; } else if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) { pSegmentCollection = new PolygonClass(); pSegmentCollection.AddSegment(pCircuArc as ISegment); pPolygon = pSegmentCollection as IPolygon; } else { return; } IFeature pFeature = null; if (pPolyline != null) { pFeature = DataEditCommon.CreateUndoRedoFeature(pFeatureLayer, pPolyline); } else if (pPolygon != null) { pFeature = DataEditCommon.CreateUndoRedoFeature(pFeatureLayer, pPolygon); } else { return; } m_hookHelper.FocusMap.SelectFeature(m_pCurrentLayer, pFeature); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewBackground, null, null); } } }
/// <summary> /// 转换椭圆线为椭圆面几何形状 /// </summary> /// <param name="geometry">ESRI几何形状接口</param> /// <returns>椭圆面几何形状的ESRI几何形状接口</returns> public static IGeometry ConvertEllipticArcToPolygon(IGeometry geometry) { if ((IsValidGeometry(geometry)) && (geometry is ISegment)) { ISegmentCollection segmentCollecttion = new PolygonClass(); object Missing = Type.Missing; segmentCollecttion.AddSegment((ISegment)geometry, ref Missing, ref Missing); return((IGeometry)segmentCollecttion); } else { return(null); } }
private void OnMouseUp() { if (m_lMouseDownCount != 2) { return; } if (m_pEllipticArc == null) { return; } m_lMouseDownCount = 0; ISegmentCollection pSegColl = null; if (m_pEllipticArc.Envelope.Width > 0.001 && m_pEllipticArc.Envelope.Height > 0.001) { m_pCurrentLayer = DataEditCommon.g_pLayer; IFeatureLayer featureLayer = m_pCurrentLayer as IFeatureLayer; if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) //创建线要素 { IPolyline pPolyline; pSegColl = new PolylineClass(); pSegColl.AddSegment(m_pEllipticArc as ISegment); pPolyline = pSegColl as IPolyline; IFeature pFeature = DataEditCommon.CreateUndoRedoFeature(featureLayer, pPolyline); m_hookHelper.FocusMap.SelectFeature(m_pCurrentLayer, pFeature); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewBackground, null, null); } if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) //创建面要素 { IPolygon pPolygon; pSegColl = new PolygonClass(); pSegColl.AddSegment(m_pEllipticArc as ISegment); pPolygon = pSegColl as IPolygon; IFeature pFeature = DataEditCommon.CreateUndoRedoFeature(featureLayer, pPolygon); m_hookHelper.FocusMap.SelectFeature(m_pCurrentLayer, pFeature); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewBackground, null, null); } //局部刷新 IInvalidArea pInvalidArea = new InvalidAreaClass(); pInvalidArea.Add(pSegColl); pInvalidArea.Display = m_hookHelper.ActiveView.ScreenDisplay; pInvalidArea.Invalidate((short)esriScreenCache.esriAllScreenCaches); m_bCreated = true; } }
private void AddEllipseElement() { IEnvelope pEnvelope = axMapControl1.TrackRectangle(); if (pEnvelope == null) { return; } IConstructEllipticArc pConstructEllipticArc = new EllipticArcClass(); //建立橢圓的Geometry pConstructEllipticArc.ConstructEnvelope(pEnvelope); IEllipticArc pEllipticArc = (IEllipticArc)pConstructEllipticArc; ISegmentCollection pSegmentCollection = new PolygonClass(); object Missing = Type.Missing; pSegmentCollection.AddSegment((ISegment)pEllipticArc, ref Missing, ref Missing); IGeometry pGeometry = pSegmentCollection as IGeometry; IEllipseElement pEllipseElement = new EllipseElementClass(); IElement pElement = pEllipseElement as IElement; pElement.Geometry = pGeometry; AddElement(pElement); }
public void OnMouseUp(int button, int shift, int x, int y) { try { IGeometry geometry = this._feedback.Stop(); this.mInUsing = false; this.ResetTool(); ISegmentCollection segments = new PolygonClass(); object missing = Type.Missing; segments.AddSegment(geometry as ISegment, ref missing, ref missing); IPolygon polygon = segments as IPolygon; try { Editor.UniqueInstance.StartEditOperation(); IFeature feature = Editor.UniqueInstance.TargetLayer.FeatureClass.CreateFeature(); (feature as IRowSubtypes).InitDefaultValues(); feature.Shape = polygon; Editor.UniqueInstance.AddAttribute = true; feature.Store(); Editor.UniqueInstance.StopEditOperation("create"); Editor.UniqueInstance.AddAttribute = false; IFeatureSelection targetLayer = Editor.UniqueInstance.TargetLayer as IFeatureSelection; targetLayer.Clear(); targetLayer.Add(feature); this._hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGeography, Editor.UniqueInstance.TargetLayer, feature.Extent); } catch { Editor.UniqueInstance.AbortEditOperation(); } } catch (Exception exception) { this.mErrOpt.ErrorOperate(this._mSubSysName, "ShapeEdit.Create2", "OnMouseUp", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); } }
private ISegmentCollection createSegments(Cell cell,BoostVoronoi bv,ArcConstructionMethods method,ISpatialReference spatialReference) { List<Cell> cells = bv.Cells; List<Edge> edges = bv.Edges; List<Vertex> vertices = bv.Vertices; IPoint previousEndPoint = null; ISegmentCollection segmentCollection = new PolygonClass() { SpatialReference = spatialReference }; // As per boost documentation, edges are returned in counter clockwise (CCW) rotation. // voronoi_edge_type* next() Returns the pointer to the CCW next edge within the corresponding Voronoi cell. Edges not necessarily share a common vertex (e.g. infinite edges). for (int i = cell.EdgesIndex.Count - 1; i >= 0; i--) { Edge edge = edges[cell.EdgesIndex[i]]; //If the vertex index equals -1, it means the edge is infinite. It is impossible to print the coordinates. if (!edge.IsFinite && edge.End < 0) { // this is the ending portion of a pair of infinite edges, file the previous edge with Start >= 0 Edge previous = null; for (int k = i + 1; k < cell.EdgesIndex.Count; k++) { previous = edges[cell.EdgesIndex[k]]; if (previous.End >= 0) break; previous = null; } if (previous == null) { for (int k = 0; k < i; k++) { previous = edges[cell.EdgesIndex[k]]; if (previous.End >= 0) break; previous = null; } } if (previous == null) throw new Exception("No outbound infinite edge could be found"); //Add a straight line segment Vertex start = vertices[previous.End]; IPoint FromPoint = new PointClass() { X = start.X, Y = start.Y, SpatialReference = spatialReference }; Vertex end = vertices[edge.Start]; IPoint ToPoint = new PointClass() { X = end.X, Y = end.Y, SpatialReference = spatialReference }; segmentCollection.AddSegment(new LineClass() { FromPoint = FromPoint, ToPoint = ToPoint, SpatialReference = spatialReference }); previousEndPoint = ToPoint; } else if (edge.IsFinite) { Vertex start = vertices[edge.End]; IPoint FromPoint = new PointClass() { X = start.X, Y = start.Y, SpatialReference = spatialReference }; if (previousEndPoint != null) { if ((Math.Abs(previousEndPoint.X - FromPoint.X) > 0.05 || Math.Abs(previousEndPoint.X - FromPoint.X) > 0.05)) throw new Exception("Significant change between last end point and current start point"); else FromPoint = previousEndPoint; } Vertex end = vertices[edge.Start]; IPoint ToPoint = new PointClass() { X = end.X, Y = end.Y, SpatialReference = spatialReference }; if (method == ArcConstructionMethods.Straight || edge.IsLinear) { segmentCollection.AddSegment(new LineClass() { FromPoint = FromPoint, ToPoint = ToPoint, SpatialReference = spatialReference }); previousEndPoint = ToPoint; } else { // We need three points, use start, end, mid-point between focus and directrix Cell twinCell = cells[edges[edge.Twin].Cell]; VPoint pointSite; VSegment lineSite; if (cell.ContainsPoint && twinCell.ContainsSegment) { pointSite = bv.RetrieveInputPoint(cell); lineSite = bv.RetrieveInputSegment(twinCell); } else if (cell.ContainsSegment && twinCell.ContainsPoint) { pointSite = bv.RetrieveInputPoint(twinCell); lineSite = bv.RetrieveInputSegment(cell); } else { throw new Exception("Invalid edge, curves should only be present between a point and a line"); } double scaleFactor = Convert.ToDouble(bv.ScaleFactor); IPoint aoPointSite = new Point() { X = Convert.ToDouble(pointSite.X) / scaleFactor, Y = Convert.ToDouble(pointSite.Y) / scaleFactor, SpatialReference = spatialReference }; ISegment aoLineSite = new LineClass() { FromPoint = new PointClass() { X = Convert.ToDouble(lineSite.Start.X) / scaleFactor, Y = Convert.ToDouble(lineSite.Start.Y) / scaleFactor, SpatialReference = spatialReference }, ToPoint = new PointClass() { X = Convert.ToDouble(lineSite.End.X) / scaleFactor, Y = Convert.ToDouble(lineSite.End.Y) / scaleFactor, SpatialReference = spatialReference }, SpatialReference = spatialReference }; if (method == ArcConstructionMethods.Approximate) { List<Vertex> sampledVerticed = null; try { sampledVerticed = bv.SampleCurvedEdge(edge, aoLineSite.Length / 10); } catch (FocusOnDirectixException e) { //Log any exception here is required sampledVerticed = new List<Vertex>() { start, end }; } catch (UnsolvableVertexException e) { sampledVerticed = new List<Vertex>() { start, end }; } sampledVerticed.Reverse(); List<IPoint> discretizedEdge = sampledVerticed.Select( p => new Point() { X = p.X, Y = p.Y } ).ToList<IPoint>(); IPoint prev = discretizedEdge[0]; foreach (IPoint v in discretizedEdge.Skip(1)) { segmentCollection.AddSegment(new LineClass() { FromPoint = new Point() { X = prev.X, Y = prev.Y, SpatialReference = spatialReference }, ToPoint = new Point() { X = v.X, Y = v.Y, SpatialReference = spatialReference }, SpatialReference = spatialReference }); prev = v; } previousEndPoint = discretizedEdge.Last(); } else if (method == ArcConstructionMethods.Circular) { IPoint nearPoint = ((IProximityOperator)aoLineSite).ReturnNearestPoint(aoPointSite, esriSegmentExtension.esriNoExtension); IPoint midpoint = new PointClass() { X = (nearPoint.X + aoPointSite.X) / 2, Y = (nearPoint.Y + aoPointSite.Y) / 2, SpatialReference = spatialReference }; IConstructCircularArc constArc = new CircularArcClass() { SpatialReference = spatialReference }; constArc.ConstructThreePoints(FromPoint, midpoint, ToPoint, false); ICircularArc arc = (ICircularArc)constArc; if (!arc.IsMinor) { constArc = new CircularArcClass() { SpatialReference = spatialReference }; constArc.ConstructEndPointsRadius(FromPoint, ToPoint, !arc.IsCounterClockwise, arc.Radius, true); arc = (ICircularArc)constArc; } segmentCollection.AddSegment((ISegment)arc); previousEndPoint = arc.ToPoint; } else if (method == ArcConstructionMethods.Ellipse) { IPoint nearPoint = ((IProximityOperator)aoLineSite).ReturnNearestPoint(aoPointSite, esriSegmentExtension.esriExtendTangents); nearPoint.SpatialReference = spatialReference; ILine lineToFocus = new LineClass() { FromPoint = nearPoint, ToPoint = aoPointSite, SpatialReference = spatialReference }; ILine semiMajor = new LineClass() { SpatialReference = spatialReference }; lineToFocus.QueryTangent(esriSegmentExtension.esriExtendTangentAtTo, 1, true, 100 * lineToFocus.Length, semiMajor); IPoint center = new PointClass() { X = (semiMajor.FromPoint.X + semiMajor.ToPoint.X) / 2, Y = (semiMajor.FromPoint.Y + semiMajor.ToPoint.Y) / 2, SpatialReference = spatialReference }; double minor_length = Math.Sqrt( Math.Pow(distance(semiMajor.FromPoint, ToPoint) + distance(semiMajor.ToPoint, ToPoint), 2) - Math.Pow(semiMajor.Length, 2)); IEllipticArc arc = new EllipticArcClass() { SpatialReference = spatialReference }; double rotation = lineToFocus.Angle; double from = GetAngle(center, FromPoint); arc.PutCoords(false, center, FromPoint, ToPoint, rotation, minor_length / semiMajor.Length, esriArcOrientation.esriArcMinor); segmentCollection.AddSegment((ISegment)arc); previousEndPoint = arc.ToPoint; } } } } return segmentCollection; }
/// <summary> /// ���ݻ��Ƶ�Բ�δ���Ҫ�� /// </summary> /// <params name="pLayer"></params> /// <params name="pCircuArc"></params> /// <params name="pScreenDisplay"></params> private void DrawCircleFeature(ILayer pLayer, ICircularArc pCircuArc, IScreenDisplay pScreenDisplay) { if (pLayer == null) return; ISegmentCollection pSegmentCollection = null; if (pLayer is IFeatureLayer) { IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; if (pFeatureClass != null) { IPolyline pPolyline = null; IPolygon pPolygon = null; if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { pSegmentCollection = new PolylineClass(); pSegmentCollection.AddSegment(pCircuArc as ISegment); pPolyline = pSegmentCollection as IPolyline; } else if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) { pSegmentCollection = new PolygonClass(); pSegmentCollection.AddSegment(pCircuArc as ISegment); pPolygon = pSegmentCollection as IPolygon; } else return; IFeature pFeature = null; if (pPolyline != null) pFeature = DataEditCommon.CreateUndoRedoFeature(pFeatureLayer, pPolyline); else if (pPolygon != null) pFeature = DataEditCommon.CreateUndoRedoFeature(pFeatureLayer, pPolygon); else return; m_hookHelper.FocusMap.SelectFeature(m_pCurrentLayer, pFeature); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewBackground, null, null); } } }
public override void OnMouseUp(int Button, int Shift, int X, int Y) { if (Button != 1) return; if (m_lMouseDownCount > 2) { m_lMouseDownCount = 0; ISegmentCollection pSegColl=null; IFeatureLayer featureLayer = m_pCurrentLayer as IFeatureLayer; if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) //������Ҫ�� { IPolyline pPolyline; pSegColl = new PolylineClass(); pSegColl.AddSegment(m_pCircleArc as ISegment); pPolyline = pSegColl as IPolyline; if (pPolyline.Length < 0.001) return; IFeature pFeature = DataEditCommon.CreateUndoRedoFeature(featureLayer, pPolyline); m_hookHelper.FocusMap.SelectFeature(m_pCurrentLayer, pFeature); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewBackground, null, null); } else //������Ҫ�� { IPolygon pPolygon; pSegColl = new PolygonClass(); pSegColl.AddSegment(m_pCircleArc as ISegment); pPolygon = pSegColl as IPolygon; pPolygon.Close(); if (pPolygon.Length < 0.001) return; IFeature pFeature = DataEditCommon.CreateUndoRedoFeature(featureLayer, pPolygon); m_hookHelper.FocusMap.SelectFeature(m_pCurrentLayer, pFeature); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewBackground, null, null); } //�ֲ�ˢ�� //IInvalidArea pInvalidArea = new InvalidAreaClass(); //pInvalidArea.Add(pSegColl); //pInvalidArea.Display = m_hookHelper.ActiveView.ScreenDisplay; //pInvalidArea.Invalidate((short)esriScreenCache.esriAllScreenCaches); m_bCreated = true; } }
private void DrawFanShaped(double x, double y, IActiveView pActiveView) { double radius = this.radius; double small_radius = this.small_radius; double start_angle = this.start_angle; double central_angle = this.central_angle; if (pActiveView != null) { IGraphicsContainer graphicsContainer = pActiveView as IGraphicsContainer; //画大圆 IPoint pCenterPoint = new PointClass(); pCenterPoint.PutCoords(x, y); ICircularArc pCircularArc = new CircularArcClass(); pCircularArc.PutCoordsByAngle(pCenterPoint, start_angle * Math.PI / 180.0, central_angle * Math.PI / 180.0, radius); IPoint pStartPoint = pCircularArc.FromPoint; IPoint pEndPoint = pCircularArc.ToPoint; ILine pLine1 = new LineClass(); pLine1.PutCoords(pCenterPoint, pStartPoint); ILine pLine2 = new LineClass(); pLine2.PutCoords(pEndPoint, pCenterPoint); ISegmentCollection pRing1 = new PolygonClass(); ISegment pSegment1 = pLine1 as ISegment; pRing1.AddSegment(pSegment1); ISegment pSegment2 = pCircularArc as ISegment; pRing1.AddSegment(pSegment2); ISegment pSegment3 = pLine2 as ISegment; pRing1.AddSegment(pSegment3); //小圆 ICircularArc pCircularArc1 = new CircularArcClass(); pCircularArc1.PutCoordsByAngle(pCenterPoint, start_angle * Math.PI / 180.0, central_angle * Math.PI / 180.0, small_radius); IPoint pStartPoint1 = pCircularArc1.FromPoint; IPoint pEndPoint1 = pCircularArc1.ToPoint; ILine pLine3 = new LineClass(); pLine3.PutCoords(pCenterPoint, pStartPoint1); ILine pLine4 = new LineClass(); pLine4.PutCoords(pEndPoint1, pCenterPoint); ISegmentCollection pRing2 = new PolygonClass(); ISegment pSegment4 = pLine3 as ISegment; pRing2.AddSegment(pSegment4); ISegment pSegment5 = pCircularArc1 as ISegment; pRing2.AddSegment(pSegment5); ISegment pSegment6 = pLine4 as ISegment; pRing2.AddSegment(pSegment6); //简化 ITopologicalOperator pTopoLogical1 = pRing1 as ITopologicalOperator; pTopoLogical1.Simplify(); ITopologicalOperator pTopoLogical2 = pRing2 as ITopologicalOperator; pTopoLogical2.Simplify(); IGeometry geometry = pTopoLogical1.Difference(pTopoLogical2 as IGeometry); //产生一个SimpleFillSymbol符号 IRgbColor rgbColor = new RgbColorClass(); rgbColor.Red = 255; rgbColor.Green = 0; rgbColor.Blue = 0; ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = rgbColor; simpleLineSymbol.Width = 1; ISimpleFillSymbol simpleFillSymbol; simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross; //设置颜色 IRgbColor rgbcolor = new RgbColorClass(); rgbcolor.Red = 0; rgbcolor.Green = 0; rgbcolor.Blue = 255; simpleFillSymbol.Color = rgbcolor as IColor; simpleFillSymbol.Outline = simpleLineSymbol; IFillShapeElement fillShapeElement = new PolygonElementClass(); fillShapeElement.Symbol = simpleFillSymbol; IElement pElement = fillShapeElement as IElement; pElement.Geometry = geometry; graphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } }
private ISegmentCollection createSegments(Cell cell, BoostVoronoi bv, ArcConstructionMethods method, ISpatialReference spatialReference) { List <Cell> cells = bv.Cells; List <Edge> edges = bv.Edges; List <Vertex> vertices = bv.Vertices; IPoint previousEndPoint = null; ISegmentCollection segmentCollection = new PolygonClass() { SpatialReference = spatialReference }; // As per boost documentation, edges are returned in counter clockwise (CCW) rotation. // voronoi_edge_type* next() Returns the pointer to the CCW next edge within the corresponding Voronoi cell. Edges not necessarily share a common vertex (e.g. infinite edges). for (int i = cell.EdgesIndex.Count - 1; i >= 0; i--) { Edge edge = edges[cell.EdgesIndex[i]]; //If the vertex index equals -1, it means the edge is infinite. It is impossible to print the coordinates. if (!edge.IsFinite && edge.End < 0) { // this is the ending portion of a pair of infinite edges, file the previous edge with Start >= 0 Edge previous = null; for (int k = i + 1; k < cell.EdgesIndex.Count; k++) { previous = edges[cell.EdgesIndex[k]]; if (previous.End >= 0) { break; } previous = null; } if (previous == null) { for (int k = 0; k < i; k++) { previous = edges[cell.EdgesIndex[k]]; if (previous.End >= 0) { break; } previous = null; } } if (previous == null) { throw new Exception("No outbound infinite edge could be found"); } //Add a straight line segment Vertex start = vertices[previous.End]; IPoint FromPoint = new PointClass() { X = start.X, Y = start.Y, SpatialReference = spatialReference }; Vertex end = vertices[edge.Start]; IPoint ToPoint = new PointClass() { X = end.X, Y = end.Y, SpatialReference = spatialReference }; segmentCollection.AddSegment(new LineClass() { FromPoint = FromPoint, ToPoint = ToPoint, SpatialReference = spatialReference }); previousEndPoint = ToPoint; } else if (edge.IsFinite) { Vertex start = vertices[edge.End]; IPoint FromPoint = new PointClass() { X = start.X, Y = start.Y, SpatialReference = spatialReference }; if (previousEndPoint != null) { if ((Math.Abs(previousEndPoint.X - FromPoint.X) > 0.05 || Math.Abs(previousEndPoint.X - FromPoint.X) > 0.05)) { throw new Exception("Significant change between last end point and current start point"); } else { FromPoint = previousEndPoint; } } Vertex end = vertices[edge.Start]; IPoint ToPoint = new PointClass() { X = end.X, Y = end.Y, SpatialReference = spatialReference }; if (method == ArcConstructionMethods.Straight || edge.IsLinear) { segmentCollection.AddSegment(new LineClass() { FromPoint = FromPoint, ToPoint = ToPoint, SpatialReference = spatialReference }); previousEndPoint = ToPoint; } else { // We need three points, use start, end, mid-point between focus and directrix Cell twinCell = cells[edges[edge.Twin].Cell]; VPoint pointSite; VSegment lineSite; if (cell.ContainsPoint && twinCell.ContainsSegment) { pointSite = bv.RetrieveInputPoint(cell); lineSite = bv.RetrieveInputSegment(twinCell); } else if (cell.ContainsSegment && twinCell.ContainsPoint) { pointSite = bv.RetrieveInputPoint(twinCell); lineSite = bv.RetrieveInputSegment(cell); } else { throw new Exception("Invalid edge, curves should only be present between a point and a line"); } double scaleFactor = Convert.ToDouble(bv.ScaleFactor); IPoint aoPointSite = new Point() { X = Convert.ToDouble(pointSite.X) / scaleFactor, Y = Convert.ToDouble(pointSite.Y) / scaleFactor, SpatialReference = spatialReference }; ISegment aoLineSite = new LineClass() { FromPoint = new PointClass() { X = Convert.ToDouble(lineSite.Start.X) / scaleFactor, Y = Convert.ToDouble(lineSite.Start.Y) / scaleFactor, SpatialReference = spatialReference }, ToPoint = new PointClass() { X = Convert.ToDouble(lineSite.End.X) / scaleFactor, Y = Convert.ToDouble(lineSite.End.Y) / scaleFactor, SpatialReference = spatialReference }, SpatialReference = spatialReference }; if (method == ArcConstructionMethods.Approximate) { List <Vertex> sampledVerticed = null; try { sampledVerticed = bv.SampleCurvedEdge(edge, aoLineSite.Length / 10); } catch (FocusOnDirectixException e) { //Log any exception here is required sampledVerticed = new List <Vertex>() { start, end }; } catch (UnsolvableVertexException e) { sampledVerticed = new List <Vertex>() { start, end }; } sampledVerticed.Reverse(); List <IPoint> discretizedEdge = sampledVerticed.Select( p => new Point() { X = p.X, Y = p.Y } ).ToList <IPoint>(); IPoint prev = discretizedEdge[0]; foreach (IPoint v in discretizedEdge.Skip(1)) { segmentCollection.AddSegment(new LineClass() { FromPoint = new Point() { X = prev.X, Y = prev.Y, SpatialReference = spatialReference }, ToPoint = new Point() { X = v.X, Y = v.Y, SpatialReference = spatialReference }, SpatialReference = spatialReference }); prev = v; } previousEndPoint = discretizedEdge.Last(); } else if (method == ArcConstructionMethods.Circular) { IPoint nearPoint = ((IProximityOperator)aoLineSite).ReturnNearestPoint(aoPointSite, esriSegmentExtension.esriNoExtension); IPoint midpoint = new PointClass() { X = (nearPoint.X + aoPointSite.X) / 2, Y = (nearPoint.Y + aoPointSite.Y) / 2, SpatialReference = spatialReference }; IConstructCircularArc constArc = new CircularArcClass() { SpatialReference = spatialReference }; constArc.ConstructThreePoints(FromPoint, midpoint, ToPoint, false); ICircularArc arc = (ICircularArc)constArc; if (!arc.IsMinor) { constArc = new CircularArcClass() { SpatialReference = spatialReference }; constArc.ConstructEndPointsRadius(FromPoint, ToPoint, !arc.IsCounterClockwise, arc.Radius, true); arc = (ICircularArc)constArc; } segmentCollection.AddSegment((ISegment)arc); previousEndPoint = arc.ToPoint; } else if (method == ArcConstructionMethods.Ellipse) { IPoint nearPoint = ((IProximityOperator)aoLineSite).ReturnNearestPoint(aoPointSite, esriSegmentExtension.esriExtendTangents); nearPoint.SpatialReference = spatialReference; ILine lineToFocus = new LineClass() { FromPoint = nearPoint, ToPoint = aoPointSite, SpatialReference = spatialReference }; ILine semiMajor = new LineClass() { SpatialReference = spatialReference }; lineToFocus.QueryTangent(esriSegmentExtension.esriExtendTangentAtTo, 1, true, 100 * lineToFocus.Length, semiMajor); IPoint center = new PointClass() { X = (semiMajor.FromPoint.X + semiMajor.ToPoint.X) / 2, Y = (semiMajor.FromPoint.Y + semiMajor.ToPoint.Y) / 2, SpatialReference = spatialReference }; double minor_length = Math.Sqrt( Math.Pow(distance(semiMajor.FromPoint, ToPoint) + distance(semiMajor.ToPoint, ToPoint), 2) - Math.Pow(semiMajor.Length, 2)); IEllipticArc arc = new EllipticArcClass() { SpatialReference = spatialReference }; double rotation = lineToFocus.Angle; double from = GetAngle(center, FromPoint); arc.PutCoords(false, center, FromPoint, ToPoint, rotation, minor_length / semiMajor.Length, esriArcOrientation.esriArcMinor); segmentCollection.AddSegment((ISegment)arc); previousEndPoint = arc.ToPoint; } } } } return(segmentCollection); }
// Execute: Execute the function given the array of the parameters public void Execute(IArray paramvalues, ITrackCancel trackcancel, IGPEnvironmentManager envMgr, IGPMessages message) { IFeatureClass outputFeatureClass = null; try { // get the input feature class IGPMultiValue inputFeatureClasses_Parameter = (IGPMultiValue)m_GPUtilities.UnpackGPValue(paramvalues.get_Element(0)); layer[] input_featureClasses = new layer[inputFeatureClasses_Parameter.Count]; for (int i = 0; i < inputFeatureClasses_Parameter.Count; i++) { IGPValue inputFeatureClass_Parameter = inputFeatureClasses_Parameter.get_Value(i); IFeatureClass inputFeatureClass; IQueryFilter inputQF; m_GPUtilities.DecodeFeatureLayer(inputFeatureClass_Parameter, out inputFeatureClass, out inputQF); input_featureClasses[i] = new layer() { featureclass = inputFeatureClass, qFilter = inputQF }; } if (input_featureClasses.Length == 0 || input_featureClasses.Any(w => w.featureclass == null)) { message.AddError(2, "Could not open one or more input dataset."); return; } //IFields additionalFields = new FieldsClass(); //additionalFields.AddField(FEATURE_SOURCE_FIELD_NAME, esriFieldType.esriFieldTypeString); //additionalFields.AddField(FEATURE_ID_FIELD_NAME, esriFieldType.esriFieldTypeInteger); //additionalFields.AddField( // input_featureClasses[0].featureclass.Fields.get_Field( // input_featureClasses[0].featureclass.Fields.FindField( // input_featureClasses[0].featureclass.ShapeFieldName))); // create the output feature class IGPValue outputFeatureClass_Parameter = m_GPUtilities.UnpackGPValue(paramvalues.get_Element(1)); outputFeatureClass = GPHelperFunctions.CreateFeatureClass(outputFeatureClass_Parameter, envMgr); if (outputFeatureClass == null) { message.AddError(2, "Could not create output dataset."); return; } IGPString curveTypeParameter = (IGPString)m_GPUtilities.UnpackGPValue(paramvalues.get_Element(2)); ArcConstructionMethods method; if (!Enum.TryParse <ArcConstructionMethods>(curveTypeParameter.Value, true, out method)) { message.AddError(2, string.Format("The value {0} is not expected. Expected values are: {1}.", curveTypeParameter.Value, string.Join(",", Enum.GetNames(typeof(ArcConstructionMethods))))); return; } IStepProgressor stepPro = (IStepProgressor)trackcancel; GPHelperFunctions.dropSpatialIndex(outputFeatureClass); BoostVoronoi bv = new BoostVoronoi(100); double minX = int.MaxValue, minY = int.MaxValue, maxX = int.MinValue, maxY = int.MinValue; List <site_key> point_sites = new List <site_key>(); List <site_key> segment_sites = new List <site_key>(); for (short i = 0; i < input_featureClasses.Length; i++) { layer l = input_featureClasses[i]; int featcount = l.featureclass.FeatureCount(l.qFilter); stepPro.MinRange = 0; stepPro.MaxRange = featcount; stepPro.StepValue = (1); stepPro.Message = "Reading features"; stepPro.Position = 0; stepPro.Show(); IFeatureCursor cursor = null; IFeature row = null; try { cursor = l.featureclass.Search(l.qFilter, false); while ((row = cursor.NextFeature()) != null) { stepPro.Step(); IPoint point = row.Shape as IPoint; if (point != null) { double X = point.X; double Y = point.Y; minX = Math.Min(minX, X); maxX = Math.Max(maxX, X); minY = Math.Min(minY, Y); maxY = Math.Max(maxY, Y); bv.AddPoint(point.X, point.Y); point_sites.Add(new site_key(i, row.OID)); } IMultipoint multipoint = row.Shape as IMultipoint; if (multipoint != null) { IPointCollection pointCollection = (IPointCollection)multipoint; IEnumVertex vertices = pointCollection.EnumVertices; IPoint vertex = null; int part, index; vertices.Next(out vertex, out part, out index); minX = Math.Min(minX, multipoint.Envelope.XMin); maxX = Math.Max(maxX, multipoint.Envelope.XMax); minY = Math.Min(minY, multipoint.Envelope.YMin); maxY = Math.Max(maxY, multipoint.Envelope.YMax); while (vertex != null) { bv.AddPoint(vertex.X, vertex.Y); point_sites.Add(new site_key(i, row.OID)); vertices.Next(out vertex, out part, out index); } } IPolyline polyline = row.Shape as IPolyline; if (polyline != null) { double fromX = polyline.FromPoint.X; double fromY = polyline.FromPoint.Y; double toX = polyline.ToPoint.X; double toY = polyline.ToPoint.Y; if (toX < fromX) { minX = Math.Min(minX, toX); maxX = Math.Max(maxX, fromX); } else { minX = Math.Min(minX, fromX); maxX = Math.Max(maxX, toX); } if (toY < fromY) { minY = Math.Min(minY, toY); maxY = Math.Max(maxY, fromY); } else { minY = Math.Min(minY, fromY); maxY = Math.Max(maxY, toY); } bv.AddSegment( polyline.FromPoint.X, polyline.FromPoint.Y, polyline.ToPoint.X, polyline.ToPoint.Y ); segment_sites.Add(new site_key(i, row.OID)); } Marshal.ReleaseComObject(row); } } finally { if (row != null) { Marshal.ReleaseComObject(row); } if (cursor != null) { Marshal.ReleaseComObject(cursor); } stepPro.Hide(); } } message.AddMessage(String.Format("{0}, {1} -> {2}, {3}", minX, minY, maxX, maxY)); int width = Math.Max((int)((maxX - minX) * 0.1), 1); int height = Math.Max((int)((maxY - minY) * 0.1), 1); maxX = maxX + width; minX = minX - width; maxY = maxY + height; minY = minY - height; message.AddMessage(String.Format("{0}, {1} -> {2}, {3}", minX, minY, maxX, maxY)); bv.AddSegment(minX, minY, maxX, minY); segment_sites.Add(new site_key(-1, -1)); bv.AddSegment(maxX, minY, maxX, maxY); segment_sites.Add(new site_key(-1, -1)); bv.AddSegment(maxX, maxY, minX, maxY); segment_sites.Add(new site_key(-1, -1)); bv.AddSegment(minX, maxY, minX, minY); segment_sites.Add(new site_key(-1, -1)); stepPro.Message = "Solve Voronoi"; stepPro.MaxRange = 0; stepPro.MaxRange = 0; stepPro.Show(); bv.Construct(); stepPro.Hide(); int featureSourceIndx = outputFeatureClass.Fields.FindField(FEATURE_SOURCE_FIELD_NAME); int featureIDIndx = outputFeatureClass.Fields.FindField(FEATURE_ID_FIELD_NAME); IFeatureCursor inserts = null; IFeatureBuffer buffer = null; try { object missing = Type.Missing; ISpatialReference spatialReference = ((IGeoDataset)outputFeatureClass).SpatialReference; inserts = outputFeatureClass.Insert(false); buffer = outputFeatureClass.CreateFeatureBuffer(); List <Cell> cells = bv.Cells; message.AddMessage(string.Format("{0} cells calculated", cells.Count)); List <Edge> edges = bv.Edges; message.AddMessage(string.Format("{0} edges calculated", edges.Count)); List <Vertex> vertices = bv.Vertices; message.AddMessage(string.Format("{0} vertexes calculated", vertices.Count)); stepPro.Message = "Write cells"; stepPro.MaxRange = 0; stepPro.MaxRange = cells.Count; stepPro.Show(); for (int cellIndex = 0; cellIndex < cells.Count; cellIndex++) { try { if (cellIndex % 5000 == 0) { message.AddMessage(String.Format("{0}. {1} cells processed.", DateTime.Now, cellIndex)); } Cell cell = cells[cellIndex]; int currentSite = cell.Site; IGeometryCollection geometryCollection = new GeometryBagClass() { SpatialReference = spatialReference }; //ignores any sliver cells if (cell.IsOpen || cell.EdgesIndex.Count < 3) { continue; } ISegmentCollection segmentCollection = createSegments(cell, bv, method, spatialReference); if (((IArea)segmentCollection).Area <= 0) { message.AddMessage("A invalid geometry has been detected, try reversing the orientation."); ISegmentCollection reversed_segmentCollection = new PolygonClass() { SpatialReference = spatialReference }; for (int i = segmentCollection.SegmentCount - 1; i >= 0; i--) { ISegment segment = (ISegment)segmentCollection.get_Segment(i); segment.ReverseOrientation(); reversed_segmentCollection.AddSegment(segment); } segmentCollection = reversed_segmentCollection; } ((IPolygon)segmentCollection).SpatialReference = spatialReference; if (((IArea)segmentCollection).Area <= 0) { message.AddWarning("An empty shell has been created"); for (int i = 0; i < segmentCollection.SegmentCount; i++) { ISegment segment = (ISegment)segmentCollection.get_Segment(i); message.AddMessage(String.Format("From {0}, {1} To {2},{3}", segment.FromPoint.X, segment.FromPoint.Y, segment.ToPoint.X, segment.ToPoint.Y)); } } //set attributes site_key sk = (currentSite >= point_sites.Count) ? segment_sites[currentSite - point_sites.Count] : point_sites[currentSite]; if (!sk.isEmpty) { buffer.set_Value(featureSourceIndx, input_featureClasses[sk.featureClassIndex].featureclass.AliasName); buffer.set_Value(featureIDIndx, sk.objectID); } else { buffer.set_Value(featureSourceIndx, DBNull.Value); buffer.set_Value(featureIDIndx, DBNull.Value); } IPolygon voronoiPolygon = (IPolygon)segmentCollection; buffer.Shape = (IPolygon)voronoiPolygon; inserts.InsertFeature(buffer); } catch (Exception e) { message.AddWarning("Failed to create a cell"); } } } finally { if (buffer != null) { Marshal.ReleaseComObject(buffer); } if (inserts != null) { Marshal.ReleaseComObject(inserts); } } GPHelperFunctions.createSpatialIndex(outputFeatureClass); } catch (Exception exx) { message.AddError(2, exx.Message); message.AddMessage(exx.ToString()); } finally { if (outputFeatureClass != null) { Marshal.ReleaseComObject(outputFeatureClass); } ((IProgressor)trackcancel).Hide(); } }
/// <summary> /// 把Geometry弄成一个element,添加到地图上 /// </summary> /// <param name="pGeometry"></param> private void AddElement(IGeometry pGeometry) { try { IElement pElement = null; ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Width = 2; pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSimpleFillSymbol.Outline = pSimpleLineSymbol; if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolyline)//多义线 { ILineElement pLineElement = new LineElementClass(); pLineElement.Symbol = pSimpleLineSymbol; pElement = pLineElement as IElement; pElement.Geometry = pGeometry; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryCircularArc)//圆 { ISegmentCollection pSegmentCollection; pSegmentCollection = new PolygonClass(); object Missing = Type.Missing;//注意 pSegmentCollection.AddSegment(pGeometry as ISegment, ref Missing, ref Missing);//后两个参数必须是这样,帮助说的,为什么?? pElement = new CircleElementClass(); pElement.Geometry = pSegmentCollection as IGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryEnvelope)//矩形 { pElement = new RectangleElementClass(); pElement.Geometry = pGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolygon)//多边形 { pElement = new PolygonElementClass(); pElement.Geometry = pGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryBezier3Curve)//Bezier曲线 { pElement = new LineElementClass(); pElement.Geometry = pGeometry; ILineElement pLineElement = pElement as ILineElement; pLineElement.Symbol = pSimpleLineSymbol; } this.pGraphicContainer.AddElement(pElement, 0); this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//剪裁输出forShp public static void cutExportShp(IFeatureCursor pfeaturecursor, IFeatureClass pfeatureclass, IGeometry pgeometry, int featurecount) { progressStep.Minimum = 0; progressStep.Maximum = featurecount; progressStep.Step = 1; IFeature pFeature = pfeaturecursor.NextFeature(); if (pFeature == null) { return; } IFeatureCursor pFeatureCursor = pfeatureclass.Insert(true); ISegmentCollection pSegmentCol = new PolygonClass(); if (pgeometry.GeometryType == esriGeometryType.esriGeometryEnvelope) { IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope = pgeometry as IEnvelope; pSegmentCol.SetRectangle(pEnvelope); pgeometry = pSegmentCol as IGeometry; } else if (pgeometry.GeometryType == esriGeometryType.esriGeometryCircularArc) { ICircularArc pCircularArc = new CircularArcClass(); pCircularArc = pgeometry as ICircularArc; object obj = System.Reflection.Missing.Value; pSegmentCol.AddSegment((ISegment)pCircularArc, ref obj, ref obj); pgeometry = pSegmentCol as IGeometry; } ITopologicalOperator pTopoOp = (ITopologicalOperator)pgeometry; IGeometry pBndGeom = pTopoOp.Boundary; esriGeometryDimension iDimension; IGeometry pAimGeometry = pFeature.ShapeCopy; if (pAimGeometry.Dimension < pgeometry.Dimension) { iDimension = pAimGeometry.Dimension; } else { iDimension = pgeometry.Dimension; } int iCount = 0; while (pFeature != null) { IFeatureBuffer pFeatureBuffer = pfeatureclass.CreateFeatureBuffer(); IFeature pAimFeature = (IFeature)pFeatureBuffer; pAimGeometry = pFeature.ShapeCopy; IRelationalOperator pRelOpeator = (IRelationalOperator)pAimGeometry; for (int i = 0; i < pFeature.Fields.FieldCount; i++) { //IField pFld = pAimFeature.Fields.get_Field(i); //if ((pFld.Editable == true) && pFld.Type != esriFieldType.esriFieldTypeGeometry) //{ // try // { // pAimFeature.set_Value(i, pFeature.get_Value(i)); // } // catch // { } //} string sFieldName = pFeature.Fields.get_Field(i).Name; int iIndex = -1; if (m_DicFields.Keys.Contains(sFieldName)) { iIndex = pFeatureBuffer.Fields.FindField(m_DicFields[sFieldName]); } else { iIndex = pFeatureBuffer.Fields.FindField(sFieldName); } if (iIndex == -1) { continue; } IField pFld = pAimFeature.Fields.get_Field(iIndex); if ((iIndex > -1) && (pFld.Editable == true) && pFld.Type != esriFieldType.esriFieldTypeGeometry) { pAimFeature.set_Value(iIndex, pFeature.get_Value(i)); } } if (pAimGeometry.GeometryType == esriGeometryType.esriGeometryPoint) { pAimFeature.Shape = pFeature.ShapeCopy; } //判断是否相交或者包含关系,如果是则进行空间切割 else { bool bCross = false; bool bContain = false; try { bCross = pRelOpeator.Crosses(pBndGeom);//changed by chulili 20111213 这句话可能报错,不要直接放在IF条件里 } catch { } try { bContain = pRelOpeator.Contains(pBndGeom);//changed by chulili 20111213 这句话可能报错 } catch { } if (bCross || bContain) { pTopoOp = (ITopologicalOperator)pFeature.ShapeCopy; pTopoOp.Simplify(); pAimFeature.Shape = pTopoOp.Intersect(pgeometry, iDimension); } else { pAimFeature.Shape = pFeature.ShapeCopy; } } pFeatureCursor.InsertFeature(pFeatureBuffer); if (iCount == 500) { pFeatureCursor.Flush(); iCount = 0; } iCount = iCount + 1; progressStep.PerformStep(); pFeature = pfeaturecursor.NextFeature(); } if (iCount > 0) { pFeatureCursor.Flush(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor); pFeatureCursor = null; }
public void updateMemory() { try { //get values int n = this.mPath.getLastIndex(); IPoint start = this.mPath[n - 1]; IPoint end = this.mPath[n]; double angleMoved = 0; double angleLeft = 0; double angleRight = 0; IPoint startLeft = new PointClass(); IPoint startRight = new PointClass(); IPoint endLeft = new PointClass(); IPoint endRight = new PointClass(); IGeometry g; ITopologicalOperator to; CircularArcClass startCurve = new CircularArcClass(); CircularArcClass endCurve = new CircularArcClass(); LineClass line1 = new LineClass(); LineClass line2 = new LineClass(); LineClass line3 = new LineClass(); LineClass line4 = new LineClass(); PolygonClass memoryPolygon = new PolygonClass(); object Missing = Type.Missing; //get angle from start to end angleMoved = System.Math.Atan((start.Y - end.Y) / (start.X - end.X)); //rotate pi/2 angleLeft = angleMoved + Math.PI / 2; angleRight = angleMoved - Math.PI / 2; //step perceptionDistance forward and back startLeft.X = start.X + this.mPerceptionDist * System.Math.Cos(angleLeft); startLeft.Y = start.Y + mPerceptionDist * System.Math.Sin(angleLeft); startRight.X = start.X + mPerceptionDist * System.Math.Cos(angleRight); startRight.Y = start.Y + mPerceptionDist * System.Math.Sin(angleRight); //repeat for end endLeft.X = end.X + mPerceptionDist * System.Math.Cos(angleLeft); endLeft.Y = end.Y + mPerceptionDist * System.Math.Sin(angleLeft); endRight.X = end.X + mPerceptionDist * System.Math.Cos(angleRight); endRight.Y = end.Y + mPerceptionDist * System.Math.Sin(angleRight); line1.FromPoint = startLeft; line1.ToPoint = endLeft; line2.FromPoint = endLeft; line2.ToPoint = endRight; line3.FromPoint = endRight; line3.ToPoint = startRight; line4.FromPoint = startRight; line4.ToPoint = startLeft; mLog.Debug("my current location is " + this.getLocation_XY()); mLog.Debug("StartRight is x,y " + startRight.X.ToString() + " " + startRight.Y.ToString()); mLog.Debug("startLeft is x,y " + startLeft.X.ToString() + " " + startLeft.Y.ToString()); mLog.Debug("endRight is x,y " + endRight.X.ToString() + " " + endRight.Y.ToString()); mLog.Debug("endLeft is x,y " + endLeft.X.ToString() + " " + endLeft.Y.ToString()); memoryPolygon.SpatialReference = this.Location.SpatialReference; memoryPolygon.AddSegment((ISegment)line1, ref Missing, ref Missing); memoryPolygon.AddSegment((ISegment)line2, ref Missing, ref Missing); memoryPolygon.AddSegment((ISegment)line3, ref Missing, ref Missing); memoryPolygon.AddSegment((ISegment)line4, ref Missing, ref Missing); if (memoryPolygon.Area < 0.0) { memoryPolygon.ReverseOrientation(); } to = (ITopologicalOperator)end; g = to.Buffer(mPerceptionDist); mLog.Debug("adding the step for time step " + this.timeStep.ToString()); // this.MapManager.AddMemoryPoly(this.IdNum,memoryPolygon); this.MapManager.AddTimeSteps(this.IdNum, memoryPolygon, (IPolygon)g, timeStep, sex); if (goingHome) { this.setSocialIndex(end); } } catch (System.Exception ex) { mLog.Debug("error look for error file"); // System.Windows.Forms.MessageBox.Show(ex.StackTrace); eLog.Debug(ex); } }
/// <summary> /// 把Geometry弄成一个element,添加到地图上 /// </summary> /// <param name="pGeometry"></param> private void AddElement(IGeometry pGeometry) { try { IElement pElement = null; ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Width = 2; pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSimpleFillSymbol.Outline = pSimpleLineSymbol; if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolyline)//多义线 { ILineElement pLineElement = new LineElementClass(); pLineElement.Symbol = pSimpleLineSymbol; pElement = pLineElement as IElement; pElement.Geometry = pGeometry; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryCircularArc)//圆 { ISegmentCollection pSegmentCollection; pSegmentCollection = new PolygonClass(); object Missing = Type.Missing; //注意 pSegmentCollection.AddSegment(pGeometry as ISegment, ref Missing, ref Missing); //后两个参数必须是这样,帮助说的,为什么?? pElement = new CircleElementClass(); pElement.Geometry = pSegmentCollection as IGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryEnvelope)//矩形 { pElement = new RectangleElementClass(); pElement.Geometry = pGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolygon)//多边形 { pElement = new PolygonElementClass(); pElement.Geometry = pGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryBezier3Curve)//Bezier曲线 { pElement = new LineElementClass(); pElement.Geometry = pGeometry; ILineElement pLineElement = pElement as ILineElement; pLineElement.Symbol = pSimpleLineSymbol; } this.pGraphicContainer.AddElement(pElement, 0); this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { DF2DApplication app = DF2DApplication.Application; bool ready = true; if (app == null || app.Current2DMapControl == null) { return; } m_ActiveView = app.Current2DMapControl.ActiveView; IScreenDisplay m_Display = app.Current2DMapControl.ActiveView.ScreenDisplay; try { if (button == 1) { ISimpleLineSymbol pLineSym = new SimpleLineSymbol(); IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 255; pColor.Blue = 0; pLineSym.Color = pColor; pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; ISimpleFillSymbol pFillSym = new SimpleFillSymbol(); pFillSym.Color = pColor; pFillSym.Style = esriSimpleFillStyle.esriSFSDiagonalCross; pFillSym.Outline = pLineSym; object symbol = pFillSym as object; IPoint point = new PointClass(); point.PutCoords(x, y); IRubberBand band = new RubberCircleClass(); ICircularArc pCircArc; ISegmentCollection pSegColl = new PolygonClass(); pCircArc = (ICircularArc)(band.TrackNew(m_Display, null)); object a = Type.Missing; pSegColl.AddSegment((ISegment)pCircArc, ref a, ref a); IGeometry pGeo = pSegColl as IGeometry; app.Current2DMapControl.DrawShape(pGeo, ref symbol); WaitForm.Start("正在查询...", "请稍后"); if (pGeo.IsEmpty) { IPoint searchPoint = new PointClass(); searchPoint.PutCoords(mapX, mapY); pGeo = PublicFunction.DoBuffer(searchPoint, PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate)); //m_ActiveView.FocusMap.SelectByShape(geo, s, false); } if (ready) { IMap pMap = app.Current2DMapControl.Map; ISelectionEnvironment selEnv = new SelectionEnvironmentClass(); pMap.SelectByShape(pGeo, selEnv, false); ISelection pSelection = pMap.FeatureSelection; FrmDxfExport dialog = new FrmDxfExport(pSelection, pMap); WaitForm.Stop(); dialog.ShowDialog(); } } } catch (System.Exception ex) { WaitForm.Stop(); } }
private double EvalAngle(ILine line1, ILine line2) { if (line1 == null || line2 == null) return double.NaN; // Create two alternate polygons and find the one with the minimum perimeter // First, assume that everybody's nose-to-tail ILine theJoinLine = new LineClass(); theJoinLine.PutCoords(line1.ToPoint, line2.FromPoint); ISegmentCollection theSegColl = new PolygonClass(); theSegColl.AddSegment((ISegment)line1, ref this._missing, ref this._missing); theSegColl.AddSegment((ISegment)theJoinLine, ref this._missing, ref this._missing); theSegColl.AddSegment((ISegment)line2, ref this._missing, ref this._missing); IPolygon thePolygon1 = (IPolygon)theSegColl; thePolygon1.Close(); // Now flip the second line create the second polygon ILine theFlipped = new LineClass(); theFlipped.PutCoords(line2.ToPoint, line2.FromPoint); theJoinLine = new LineClass(); theJoinLine.PutCoords(line1.ToPoint, theFlipped.FromPoint); theSegColl = new PolygonClass(); theSegColl.AddSegment((ISegment)line1, ref this._missing, ref this._missing); theSegColl.AddSegment((ISegment)theJoinLine, ref this._missing, ref this._missing); theSegColl.AddSegment((ISegment)theFlipped, ref this._missing, ref this._missing); IPolygon thePolygon2 = (IPolygon)theSegColl; thePolygon2.Close(); // The polygon with the minimum perimeter (length) is the one we want IPolygon theMinPerimeter; ILine theRealLine2; if (thePolygon1.Length < thePolygon2.Length) { theMinPerimeter = thePolygon1; theRealLine2 = line2; } else { theMinPerimeter = thePolygon2; theRealLine2 = theFlipped; } // Work out the angles from 1 to join to 2 double[] angles = new double[2]; IConstructAngle theConstAngle = (IConstructAngle) new GeometryEnvironmentClass(); angles[0] = Math.Abs(theConstAngle.ConstructThreePoint(line1.FromPoint, line1.ToPoint, theRealLine2.FromPoint)); if (this.IsConcave(line1.FromPoint, line1.ToPoint, theRealLine2.FromPoint, theMinPerimeter)) angles[0] = 2 * Math.PI - angles[0]; angles[1] = Math.Abs(theConstAngle.ConstructThreePoint(line1.ToPoint, theRealLine2.FromPoint, theRealLine2.ToPoint)); if (this.IsConcave(line1.ToPoint, theRealLine2.FromPoint, theRealLine2.ToPoint, theMinPerimeter)) angles[1] = 2 * Math.PI - angles[1]; // Figure out which side of the iBeam makes a theoretical triangle with angles A, B, and C double angleResult = Math.Abs(Math.PI - (angles[0] + angles[1])); //this.DebugPrint(line1, theJoinLine, theRealLine2, angles, angleResult); return angleResult; }
private void OnMouseUp() { if (m_lMouseDownCount != 2 ) return; if (m_pEllipticArc == null) return; m_lMouseDownCount = 0; ISegmentCollection pSegColl=null; if (m_pEllipticArc.Envelope.Width > 0.001 && m_pEllipticArc.Envelope.Height > 0.001) { m_pCurrentLayer = DataEditCommon.g_pLayer; IFeatureLayer featureLayer = m_pCurrentLayer as IFeatureLayer; if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) //������Ҫ�� { IPolyline pPolyline; pSegColl = new PolylineClass(); pSegColl.AddSegment(m_pEllipticArc as ISegment); pPolyline = pSegColl as IPolyline; IFeature pFeature = DataEditCommon.CreateUndoRedoFeature(featureLayer, pPolyline); m_hookHelper.FocusMap.SelectFeature(m_pCurrentLayer, pFeature); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewBackground, null, null); } if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) //������Ҫ�� { IPolygon pPolygon; pSegColl = new PolygonClass(); pSegColl.AddSegment(m_pEllipticArc as ISegment); pPolygon = pSegColl as IPolygon; IFeature pFeature = DataEditCommon.CreateUndoRedoFeature(featureLayer, pPolygon); m_hookHelper.FocusMap.SelectFeature(m_pCurrentLayer, pFeature); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewBackground, null, null); } //�ֲ�ˢ�� IInvalidArea pInvalidArea = new InvalidAreaClass(); pInvalidArea.Add(pSegColl); pInvalidArea.Display = m_hookHelper.ActiveView.ScreenDisplay; pInvalidArea.Invalidate((short)esriScreenCache.esriAllScreenCaches); m_bCreated = true; } }
// Execute: Execute the function given the array of the parameters public void Execute(IArray paramvalues, ITrackCancel trackcancel, IGPEnvironmentManager envMgr, IGPMessages message) { IFeatureClass outputFeatureClass = null; try { // get the input feature class IGPMultiValue inputFeatureClasses_Parameter = (IGPMultiValue)m_GPUtilities.UnpackGPValue(paramvalues.get_Element(0)); layer[] input_featureClasses = new layer[inputFeatureClasses_Parameter.Count]; for (int i = 0; i < inputFeatureClasses_Parameter.Count; i++) { IGPValue inputFeatureClass_Parameter = inputFeatureClasses_Parameter.get_Value(i); IFeatureClass inputFeatureClass; IQueryFilter inputQF; m_GPUtilities.DecodeFeatureLayer(inputFeatureClass_Parameter, out inputFeatureClass, out inputQF); input_featureClasses[i] = new layer() { featureclass = inputFeatureClass, qFilter = inputQF}; } if (input_featureClasses.Length == 0 || input_featureClasses.Any(w=> w.featureclass == null)) { message.AddError(2, "Could not open one or more input dataset."); return; } //IFields additionalFields = new FieldsClass(); //additionalFields.AddField(FEATURE_SOURCE_FIELD_NAME, esriFieldType.esriFieldTypeString); //additionalFields.AddField(FEATURE_ID_FIELD_NAME, esriFieldType.esriFieldTypeInteger); //additionalFields.AddField( // input_featureClasses[0].featureclass.Fields.get_Field( // input_featureClasses[0].featureclass.Fields.FindField( // input_featureClasses[0].featureclass.ShapeFieldName))); // create the output feature class IGPValue outputFeatureClass_Parameter = m_GPUtilities.UnpackGPValue(paramvalues.get_Element(1)); outputFeatureClass = GPHelperFunctions.CreateFeatureClass(outputFeatureClass_Parameter, envMgr); if (outputFeatureClass == null) { message.AddError(2, "Could not create output dataset."); return; } IGPString curveTypeParameter = (IGPString)m_GPUtilities.UnpackGPValue(paramvalues.get_Element(2)); ArcConstructionMethods method; if (!Enum.TryParse<ArcConstructionMethods>(curveTypeParameter.Value, true, out method)) { message.AddError(2, string.Format("The value {0} is not expected. Expected values are: {1}.", curveTypeParameter.Value, string.Join(",", Enum.GetNames(typeof(ArcConstructionMethods))))); return; } IStepProgressor stepPro = (IStepProgressor)trackcancel; GPHelperFunctions.dropSpatialIndex(outputFeatureClass); BoostVoronoi bv = new BoostVoronoi(100); double minX = int.MaxValue, minY = int.MaxValue, maxX = int.MinValue, maxY = int.MinValue; List<site_key> point_sites = new List<site_key>(); List<site_key> segment_sites = new List<site_key>(); for (short i = 0; i < input_featureClasses.Length; i++) { layer l = input_featureClasses[i]; int featcount = l.featureclass.FeatureCount(l.qFilter); stepPro.MinRange = 0; stepPro.MaxRange = featcount; stepPro.StepValue = (1); stepPro.Message = "Reading features"; stepPro.Position = 0; stepPro.Show(); IFeatureCursor cursor = null; IFeature row = null; try { cursor = l.featureclass.Search(l.qFilter, false); while ((row = cursor.NextFeature()) != null) { stepPro.Step(); IPoint point = row.Shape as IPoint; if (point != null) { double X = point.X; double Y = point.Y; minX = Math.Min(minX, X); maxX = Math.Max(maxX, X); minY = Math.Min(minY, Y); maxY = Math.Max(maxY, Y); bv.AddPoint(point.X, point.Y); point_sites.Add(new site_key(i, row.OID)); } IMultipoint multipoint = row.Shape as IMultipoint; if (multipoint != null) { IPointCollection pointCollection = (IPointCollection)multipoint; IEnumVertex vertices = pointCollection.EnumVertices; IPoint vertex = null; int part, index; vertices.Next(out vertex, out part, out index); minX = Math.Min(minX, multipoint.Envelope.XMin); maxX = Math.Max(maxX, multipoint.Envelope.XMax); minY = Math.Min(minY, multipoint.Envelope.YMin); maxY = Math.Max(maxY, multipoint.Envelope.YMax); while (vertex != null) { bv.AddPoint(vertex.X, vertex.Y); point_sites.Add(new site_key(i, row.OID)); vertices.Next(out vertex, out part, out index); } } IPolyline polyline = row.Shape as IPolyline; if (polyline != null) { double fromX = polyline.FromPoint.X; double fromY = polyline.FromPoint.Y; double toX = polyline.ToPoint.X; double toY = polyline.ToPoint.Y; if (toX < fromX) { minX = Math.Min(minX, toX); maxX = Math.Max(maxX, fromX); } else { minX = Math.Min(minX, fromX); maxX = Math.Max(maxX, toX); } if (toY < fromY) { minY = Math.Min(minY, toY); maxY = Math.Max(maxY, fromY); } else { minY = Math.Min(minY, fromY); maxY = Math.Max(maxY, toY); } bv.AddSegment( polyline.FromPoint.X, polyline.FromPoint.Y, polyline.ToPoint.X, polyline.ToPoint.Y ); segment_sites.Add(new site_key(i, row.OID)); } Marshal.ReleaseComObject(row); } } finally { if (row != null) Marshal.ReleaseComObject(row); if (cursor != null) Marshal.ReleaseComObject(cursor); stepPro.Hide(); } } message.AddMessage(String.Format("{0}, {1} -> {2}, {3}", minX, minY, maxX, maxY)); int width = Math.Max((int)((maxX - minX) * 0.1), 1); int height = Math.Max((int)((maxY - minY) * 0.1), 1); maxX = maxX + width; minX = minX - width; maxY = maxY + height; minY = minY - height; message.AddMessage(String.Format("{0}, {1} -> {2}, {3}", minX, minY, maxX, maxY)); bv.AddSegment(minX, minY, maxX, minY); segment_sites.Add(new site_key(-1, -1)); bv.AddSegment(maxX, minY, maxX, maxY); segment_sites.Add(new site_key(-1, -1)); bv.AddSegment(maxX, maxY, minX, maxY); segment_sites.Add(new site_key(-1, -1)); bv.AddSegment(minX, maxY, minX, minY); segment_sites.Add(new site_key(-1, -1)); stepPro.Message = "Solve Voronoi"; stepPro.MaxRange = 0; stepPro.MaxRange = 0; stepPro.Show(); bv.Construct(); stepPro.Hide(); int featureSourceIndx = outputFeatureClass.Fields.FindField(FEATURE_SOURCE_FIELD_NAME); int featureIDIndx = outputFeatureClass.Fields.FindField(FEATURE_ID_FIELD_NAME); IFeatureCursor inserts = null; IFeatureBuffer buffer = null; try { object missing = Type.Missing; ISpatialReference spatialReference = ((IGeoDataset)outputFeatureClass).SpatialReference; inserts = outputFeatureClass.Insert(false); buffer = outputFeatureClass.CreateFeatureBuffer(); List<Cell> cells = bv.Cells; message.AddMessage(string.Format("{0} cells calculated", cells.Count)); List<Edge> edges = bv.Edges; message.AddMessage(string.Format("{0} edges calculated", edges.Count)); List<Vertex> vertices = bv.Vertices; message.AddMessage(string.Format("{0} vertexes calculated", vertices.Count)); stepPro.Message = "Write cells"; stepPro.MaxRange = 0; stepPro.MaxRange = cells.Count; stepPro.Show(); for (int cellIndex = 0; cellIndex < cells.Count; cellIndex++) { try { if(cellIndex % 5000 == 0) message.AddMessage(String.Format("{0}. {1} cells processed.", DateTime.Now, cellIndex)); Cell cell = cells[cellIndex]; int currentSite = cell.Site; IGeometryCollection geometryCollection = new GeometryBagClass() { SpatialReference = spatialReference }; //ignores any sliver cells if (cell.IsOpen || cell.EdgesIndex.Count < 3) continue; ISegmentCollection segmentCollection = createSegments(cell, bv, method, spatialReference); if (((IArea)segmentCollection).Area <= 0) { message.AddMessage("A invalid geometry has been detected, try reversing the orientation."); ISegmentCollection reversed_segmentCollection = new PolygonClass() { SpatialReference = spatialReference }; for (int i = segmentCollection.SegmentCount - 1; i >= 0; i--) { ISegment segment = (ISegment)segmentCollection.get_Segment(i); segment.ReverseOrientation(); reversed_segmentCollection.AddSegment(segment); } segmentCollection = reversed_segmentCollection; } ((IPolygon)segmentCollection).SpatialReference = spatialReference; if (((IArea)segmentCollection).Area <= 0) { message.AddWarning("An empty shell has been created"); for (int i = 0; i < segmentCollection.SegmentCount; i++) { ISegment segment = (ISegment)segmentCollection.get_Segment(i); message.AddMessage(String.Format("From {0}, {1} To {2},{3}", segment.FromPoint.X, segment.FromPoint.Y, segment.ToPoint.X, segment.ToPoint.Y)); } } //set attributes site_key sk = (currentSite >= point_sites.Count) ? segment_sites[currentSite - point_sites.Count] : point_sites[currentSite]; if (!sk.isEmpty) { buffer.set_Value(featureSourceIndx, input_featureClasses[sk.featureClassIndex].featureclass.AliasName); buffer.set_Value(featureIDIndx, sk.objectID); } else { buffer.set_Value(featureSourceIndx, DBNull.Value); buffer.set_Value(featureIDIndx, DBNull.Value); } IPolygon voronoiPolygon = (IPolygon)segmentCollection; buffer.Shape = (IPolygon)voronoiPolygon; inserts.InsertFeature(buffer); } catch (Exception e) { message.AddWarning("Failed to create a cell"); } } } finally { if (buffer != null) Marshal.ReleaseComObject(buffer); if (inserts != null) Marshal.ReleaseComObject(inserts); } GPHelperFunctions.createSpatialIndex(outputFeatureClass); } catch (Exception exx) { message.AddError(2, exx.Message); message.AddMessage(exx.ToString()); } finally { if (outputFeatureClass != null) Marshal.ReleaseComObject(outputFeatureClass); ((IProgressor)trackcancel).Hide(); } }