/// <summary> /// /// </summary> /// <param name="pCol">for a polygon, the fisrt point and the last point are identical</param> /// <param name="dblFactor"></param> /// <returns></returns> public static IEnumerable <CPoint> GetCptEbByICol(IPointCollection4 pCol) { for (int i = 0; i < pCol.PointCount; i++) { yield return(new CPoint(i, pCol.get_Point(i))); } }
public IPolygon BoundingPolygon(IList <IPoint> pList, ISpatialReference spatialrefrence) { try { IGeometryBridge2 pGeoBrg = new GeometryEnvironment() as IGeometryBridge2; IPointCollection4 pPointColl = (IPointCollection4) new Multipoint(); // edited here int numPoints = pList.Count; WKSPoint[] aWKSPointBuffer = new WKSPoint[numPoints]; for (int i = 0; i < pList.Count; i++) { WKSPoint A = new WKSPoint(); A.X = pList[i].X; A.Y = pList[i].Y; aWKSPointBuffer[i] = A; } pGeoBrg.SetWKSPoints(pPointColl, ref aWKSPointBuffer); // edits here IGeometry pGeom = (IMultipoint)pPointColl; pGeom.SpatialReference = spatialrefrence; ITopologicalOperator pTopOp = (ITopologicalOperator)pGeom; IPolygon pPointColl2 = (IPolygon)pTopOp.ConvexHull(); pPointColl2.SpatialReference = spatialrefrence; // OutputPolygon = pPointColl2; maybe you don't need this line as the object is not used return(pPointColl2); } catch (Exception e) { return(null); } }
public IPointCollection4 ToPointCollection(IGeometry geometry, out int nrPoints) { IPointCollection4 result = null; nrPoints = 0; if (geometry != null) { result = geometry as IPointCollection4; TypeOfLayer typeOfLayer = GetTypeOfLayer(geometry); if ((!geometry.IsEmpty) && (typeOfLayer == TypeOfLayer.Point) && (result == null) && IsPointMeasurement) { var pointc = geometry as IPoint; result = new MultipointClass(); result.AddPoint(pointc); } if (result != null) { nrPoints = result.PointCount; if ((nrPoints >= 2) && (typeOfLayer == TypeOfLayer.Polygon)) { IPoint point1 = result.Point[0]; IPoint point2 = result.Point[nrPoints - 1]; nrPoints = (point1.Compare(point2) == 0) ? (nrPoints - 1) : nrPoints; } } } return(result); }
private double GetEndElevation(IFeatureLayer pDepthSoundings, IFeatureLayer pLineLayer, IFeature pLineFeature, string strDepthField) { try { IEnvelope pCombinedEnvelope = CombineExtents(pDepthSoundings.FeatureClass, pLineLayer.FeatureClass); IPointCollection4 pPointColl = pLineFeature.Shape as IPointCollection4; IPoint ppoint = new PointClass(); //Get the last point on the line ppoint = pPointColl.get_Point(-1); IFeatureCursor pDepthCursor = pDepthSoundings.Search(null, false); IFeatureIndex2 pFtrInd = new FeatureIndexClass(); pFtrInd.FeatureClass = pDepthSoundings.FeatureClass; pFtrInd.FeatureCursor = pDepthCursor; pFtrInd.Index(null, pCombinedEnvelope); IIndexQuery2 pIndQry = pFtrInd as IIndexQuery2; int FtdID = 0; double dDist2Ftr = 0; pIndQry.NearestFeature(ppoint, out FtdID, out dDist2Ftr); IFeature pCloseFeature = pDepthSoundings.FeatureClass.GetFeature(FtdID); return(Convert.ToDouble(pCloseFeature.get_Value(pCloseFeature.Fields.FindField(strDepthField)))); } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); return(0); } }
private IFeature WalkLine(IFeatureLayer pDepthSoundings, IFeatureLayer pLineLayer, IFeature pLineFeature) { try { IEnvelope pCombinedEnvelope = CombineExtents(pDepthSoundings.FeatureClass, pLineLayer.FeatureClass); IPointCollection4 pPointColl = pLineFeature.Shape as IPointCollection4; IPoint ppoint = new PointClass(); IFeatureCursor pDepthCursor = pDepthSoundings.Search(null, false); IFeatureIndex2 pFtrInd = new FeatureIndexClass(); pFtrInd.FeatureClass = pDepthSoundings.FeatureClass; pFtrInd.FeatureCursor = pDepthCursor; pFtrInd.Index(null, pCombinedEnvelope); IIndexQuery2 pIndQry = pFtrInd as IIndexQuery2; int FtdID = 0; double dDist2Ftr = 0; pIndQry.NearestFeature(ppoint, out FtdID, out dDist2Ftr); IFeature pCloseFeature = pDepthSoundings.FeatureClass.GetFeature(FtdID); return(pCloseFeature); } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); return(null); } }
private static double GetMostFrequentZValue([NotNull] IPointCollection4 points, out int mostFrequentZValuePointCount) { Assert.ArgumentNotNull(points, nameof(points)); int pointCount = points.PointCount; WKSPointZ[] wks = GetPointArray(points); var zFrequency = new Dictionary <double, int>(); int maxFrequency = int.MinValue; double maxFrequencyZ = double.NaN; for (int pointIndex = 0; pointIndex < pointCount; pointIndex++) { double z = wks[pointIndex].Z; int count; count = zFrequency.TryGetValue(z, out count) ? count + 1 : 1; zFrequency[z] = count; if (count > maxFrequency) { maxFrequency = count; maxFrequencyZ = z; } } mostFrequentZValuePointCount = maxFrequency; return(maxFrequencyZ); }
private IPointCollection AddVerticePointToCollection(IPolyline coastline) { //IPointCollection4 IPointCollection4 verticePointColl = (IPointCollection4)coastline; return(verticePointColl); }
private static double[][] ToArray(this IPointCollection4 pointCollection) { return(Enumerable.Range(0, pointCollection.PointCount).Select(i => { var p = pointCollection.Point[i]; return new[] { p.X, p.Y }; }).ToArray()); }
private static WKSPointZ[] GetPointArray([NotNull] IPointCollection4 points) { var pointArray = new WKSPointZ[points.PointCount]; GeometryUtils.QueryWKSPointZs(points, pointArray); return(pointArray); }
private void SetZToZero(IPointCollection4 pCol) { for (int i = 0; i < pCol.PointCount; i++) { IPoint copyipt = pCol.get_Point(i); copyipt.Z = 0; pCol.UpdatePoint(i, copyipt); } }
/// <summary> /// /// </summary> /// <param name="pCol"></param> /// <remarks>note that if we set z coordinates, then we may lose many information related to IPolygon /// (ConnectedComponentBag, InteriorRingBag, ExteriorRingBag, etc.) </remarks> public static void SetZCoordinates(IPointCollection4 pCol) { for (int i = 0; i < pCol.PointCount; i++) { IPoint copyipt = pCol.get_Point(i); copyipt.Z = 0; pCol.UpdatePoint(i, copyipt); } }
private List <PartProxy> AddSinglePartProxy([NotNull] IPointCollection4 baseGeometry) { var result = new List <PartProxy>(1); var partProxy = new PartProxy(_boxTree, 0, baseGeometry); result.Add(partProxy); return(result); }
public IndexedPolycurve([NotNull] IPointCollection4 baseGeometry) { Assert.ArgumentNotNull(baseGeometry, nameof(baseGeometry)); const bool @dynamic = true; const int dimension = 2; const int maxElementCountPerTile = 4; // was: 64; _boxTree = new BoxTree <SegmentProxy>(dimension, maxElementCountPerTile, @dynamic); var geometry = (IGeometry)baseGeometry; _envelope = geometry.Envelope; double tolerance = GeometryUtils.GetXyTolerance(geometry); Box extent = QaGeometryUtils.CreateBox(_envelope); Expand(extent, tolerance); _boxTree.InitSize(new IGmtry[] { extent }); var geometryCollection = baseGeometry as IGeometryCollection; if (geometryCollection != null) { int partCount = geometryCollection.GeometryCount; if (partCount > 1) { // unpack and add individual parts _partProxies = new List <PartProxy>(partCount); for (int partIndex = 0; partIndex < partCount; partIndex++) { var part = (IPointCollection4)geometryCollection.Geometry[partIndex]; var partProxy = new PartProxy(_boxTree, partIndex, part); _partProxies.Add(partProxy); Marshal.ReleaseComObject(part); } } else { // single part in collection _partProxies = AddSinglePartProxy(baseGeometry); } } else { // no geometry collection _partProxies = AddSinglePartProxy(baseGeometry); } }
public PatchProxy(int patchIndex, int minPartIndex, [NotNull] IPointCollection4 baseGeometry) { PatchIndex = patchIndex; _minPartIndex = minPartIndex; SpatialReference = ((IGeometry)baseGeometry).SpatialReference; _points = new WKSPointZ[baseGeometry.PointCount]; GeometryUtils.QueryWKSPointZs(baseGeometry, _points); _patchType = ((IGeometry)baseGeometry).GeometryType; }
//public virtual CGeoBase Copy() //{ // return null; //} /// <summary> /// this funcation can only be used for a shape that implements IPointCollection4 /// </summary> public virtual void JudgeAndSetZToZero() { IPointCollection4 pCol = _pGeo as IPointCollection4; if (pCol.PointCount > 0) { IPoint ipt0 = pCol.get_Point(0); if (double.IsNaN(ipt0.Z)) { SetZToZero(pCol); } } }
private static IEnumerable <IPointList> GetAsPointList( [NotNull] ICollection <IRing> rings) { foreach (IRing ring in rings) { IPointCollection4 pointCollection = (IPointCollection4)ring; WKSPointZ[] pointArray = new WKSPointZ[pointCollection.PointCount]; GeometryUtils.QueryWKSPointZs(pointCollection, pointArray); yield return(new WksPointZPointList(pointArray, 0, pointCollection.PointCount)); } }
private void UpdateFeature(IFeature selectedFeature, IPointCollection4 polylinePoints) { IPointCollection4 geometry; esriGeometryType geometryType = selectedFeature.Shape.GeometryType; switch (geometryType) { case esriGeometryType.esriGeometryMultipoint: geometry = new MultipointClass(); break; case esriGeometryType.esriGeometryPolyline: geometry = new PolylineClass(); break; case esriGeometryType.esriGeometryPolygon: geometry = new PolygonClass(); break; default: geometry = null; break; } if (geometry == null) { return; } geometry.AddPointCollection(polylinePoints); IFeatureClass featureClass = selectedFeature.Class as IFeatureClass; IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (!(workspaceEdit.IsBeingEdited())) { return; } try { workspaceEdit.StartEditOperation(); selectedFeature.Shape = geometry as IGeometry; selectedFeature.Store(); workspaceEdit.StopEditOperation(); } catch (Exception ex) { workspaceEdit.AbortEditOperation(); MessageBox.Show("移动要素顶点失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private static List <WKSPointZ> GetErrorPoints([NotNull] IPointCollection4 points, double minAllowedZ, double maxAllowedZ) { WKSPointZ[] wksPoints = GetPointArray(points); var result = new List <WKSPointZ>(); foreach (WKSPointZ wksPointZ in wksPoints) { if (IsError(wksPointZ.Z, minAllowedZ, maxAllowedZ)) { result.Add(wksPointZ); } } return(result); }
private static IEnumerable <IPointList> GetPartsAsPointLists([NotNull] IPolycurve polycurve) { int[] pointCounts = GeometryUtils.GetPointCountPerPart(polycurve); IPointCollection4 pointCollection = (IPointCollection4)polycurve; // For large polygons with many parts (huge lockergestein) getting the wks point array // only once and re-using it for each part takes half as long as getting the array for // each part. WKSPointZ[] pointArray = GetWksPointArray(pointCollection.PointCount); GeometryUtils.QueryWKSPointZs(pointCollection, pointArray); int currentStart = 0; foreach (int pointCount in pointCounts) { yield return(new WksPointZPointList(pointArray, currentStart, pointCount)); currentStart += pointCount; } }
public IPointCollection4 modify1VertexOfAPolyline(IGeometryCollection geo, Double searchRadius, Double offsetX, Double offsetY) { IPoint queryPoint = m_activePoint; IPoint hitPoint = new PointClass(); Double hitDistance = 0; Int32 hitPartIndex = 0; Int32 hitSegmentIndex = 0; Boolean rightSide = false; IHitTest hitTest = (IHitTest)geo; Boolean foundGeometry = hitTest.HitTest(queryPoint, searchRadius, esriGeometryHitPartType.esriGeometryPartVertex, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref rightSide); if (foundGeometry == true) { IGeometry geometry = geo.get_Geometry(hitPartIndex); IPointCollection4 pointCollection = (IPointCollection4)geometry; IPoint transformPoint = pointCollection.get_Point(hitSegmentIndex); ITransform2D transform2D = (ITransform2D)transformPoint; transform2D.Move(offsetX, offsetY); pointCollection.UpdatePoint(hitSegmentIndex, transformPoint); return(pointCollection); } return(null); }
private static void AddErrorPointSequences([NotNull] IPointCollection4 curvePoints, double minAllowedZ, double maxAllowedZ, [NotNull] ICollection <List <WKSPointZ> > result) { WKSPointZ[] wksPoints = GetPointArray(curvePoints); List <WKSPointZ> currentErrorSequence = null; foreach (WKSPointZ wksPointZ in wksPoints) { if (IsError(wksPointZ.Z, minAllowedZ, maxAllowedZ)) { if (currentErrorSequence == null) { currentErrorSequence = new List <WKSPointZ>(); } currentErrorSequence.Add(wksPointZ); } else { if (currentErrorSequence != null) { result.Add(currentErrorSequence); currentErrorSequence = null; } } } // last may have been error if (currentErrorSequence != null) { result.Add(currentErrorSequence); } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button != (int)Keys.LButton) { return; } ILayer layer = m_engineEditor.TargetLayer; if (layer == null) { MessageBox.Show("请先启动编辑!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } m_activeView = m_hookHelper.ActiveView; m_map = m_hookHelper.FocusMap; if (m_map == null || m_activeView == null) { return; } m_activePoint = m_activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); GetSelectedFeature(); if (m_selectedFeature == null) { MessageBox.Show("请选择要素(在要移动的顶点处点选)!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } IGeometryCollection geometry = m_selectedFeature.Shape as IGeometryCollection; IPointCollection4 polylinePoints = modify1VertexOfAPolyline(geometry, 1, 5, 5); if (polylinePoints != null) { UpdateFeature(m_selectedFeature, polylinePoints); } m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent); }
/// <summary> /// /// </summary> /// <param name="ConstraintCpllt"></param> /// <param name="KnownCEdgeLt"></param> /// <param name="strIdentity"></param> /// <param name="blnSave"></param> /// <remarks>If the "data area" is not set deliberately, then ArcEngine will set a default "data area". /// The default data area excludes super edges and super nodes</remarks> public void Triangulate(List <CPolyline> ConstraintCpllt = null, List <CEdge> KnownCEdgeLt = null, string strIdentity = "", bool blnSave = false) { var cpg = _CPg; //cpg.pPolygon = null; cpg.JudgeAndSetPolygon(); IPointCollection4 pCol = cpg.pPolygon as IPointCollection4; int intCount = pCol.PointCount; var pEnv = cpg.pPolygon.Envelope; ITinEdit TinEdit = new TinClass(); TinEdit.InitNew(pEnv); ITinEdit2 TinEdit2 = TinEdit as ITinEdit2; TinEdit2.SetToConstrainedDelaunay(); //this must be done before adding any feature var pTinAdvanced2 = TinEdit as ITinAdvanced2; ITinFeatureEdit pTinFeatureEdit = TinEdit as ITinFeatureEdit; cpg.JudgeAndSetZToZero(); //we need z coordinate to construct triangulation pTinFeatureEdit.AddPolygonZ(cpg.pPolygon, esriTinEdgeType.esriTinHardEdge, 1, 1, 1, null); if (ConstraintCpllt != null) { foreach (var cpl in ConstraintCpllt) { cpl.JudgeAndSetPolyline(); cpl.JudgeAndSetZToZero(); pTinFeatureEdit.AddPolylineZ(cpl.pPolyline, esriTinEdgeType.esriTinHardEdge, 1, 1, null); } } _pTinAdvanced2 = pTinAdvanced2; //we are not allowed to use AddShapeZ. //it will report that there is no Z value in the shape, even we already set Z value to 0 //The reason may be that we actually need polyhedron //TinEdit.AddShapeZ((IGeometry)cpg.pPolygon, esriTinSurfaceType.esriTinHardClip, 0); //******************************************** //this function set the "data area" of the TIN, //we avoid to use this function because it may introduce new points //the new poins can be very close to the original points //TinEdit.AddShape((IGeometry)cpg.pPolygon, esriTinSurfaceType.esriTinHardClip, 0); //TinEdit.Refresh(); if (pTinAdvanced2.DataNodeCount != this.CptLt.Count) { //Usually, KnownCEdgeLt saves all the constraints for the triangulation CSaveFeature.SaveCEdgeEb(KnownCEdgeLt, "KnownCEdgeLt" + strIdentity); CSaveFeature.SaveCptEb(this.CptLt, "CptLtForKnownCEdgeLt" + strIdentity); var NodeCptLt = GetCptLtFromTinAdvanced(pTinAdvanced2, true); CSaveFeature.SaveCptEb(NodeCptLt, "TinNode" + strIdentity); //var TinCEdgeLt= get var ExtraNodeCptLt = new List <CPoint>(pTinAdvanced2.DataNodeCount - this.CptLt.Count); foreach (var nodeCpt in NodeCptLt) { if (this.CptSD.ContainsKey(nodeCpt) == false) { ExtraNodeCptLt.Add(nodeCpt); } } CSaveFeature.SaveCptEb(ExtraNodeCptLt, "ExtraNodeCptLt" + strIdentity); var TinCEdgeLt = GetCEdgeLtFromTinAdvanced(pTinAdvanced2); CSaveFeature.SaveCEdgeEb(TinCEdgeLt, "TinCEdgeLt" + strIdentity); throw new ArgumentException("the numbers of points should be the same!"); } this.CptLt.SetIndexID(); var ITinEdgeLt = GenerateITinEdgeLt(); var tincedgeSS = new SortedSet <CEdge>(new CCmpEdge_CptGID_BothDirections()); var tincedgelt = new List <CEdge>(); if (KnownCEdgeLt != null) { tincedgeSS = new SortedSet <CEdge>(KnownCEdgeLt, new CCmpEdge_CptGID_BothDirections()); tincedgelt.AddRange(KnownCEdgeLt); } cpg.SetAxisAngleAndReverseLt(); var cptSD = this.CptSD; foreach (var tinedge in ITinEdgeLt) { //there are always a pair of edges between a pair of triangles, but we only need one edge. //So we reverse some edges than we can delete one edge of each pair var pFrNode = tinedge.FromNode; var pToNode = tinedge.ToNode; CPoint frcpt, tocpt; FindCorrCptInSDByTinNode(pFrNode, cptSD, out frcpt); FindCorrCptInSDByTinNode(pToNode, cptSD, out tocpt); CEdge newCEdge; if (frcpt.indexID < tocpt.indexID) { newCEdge = new CEdge(frcpt, tocpt); } else if (frcpt.indexID > tocpt.indexID) { newCEdge = new CEdge(tocpt, frcpt); } else { throw new ArgumentException("should not happen!"); } //test if the new edge is outside the boundary polygon (cpg) if (newCEdge.FrCpt.indexID < cpg.CEdgeLt.Count) { //the new edge starts from a point which constitues the boundary polygon (cpg) newCEdge.SetAxisAngle(); if (CGeoFunc.IsInbetween_Counterclockwise(cpg.AxisAngleLt[newCEdge.FrCpt.indexID], newCEdge.dblAxisAngle, cpg.ReverseAxisAngleLt[newCEdge.FrCpt.indexID]) == false) { //the new edge is outside the boundary polygon (cpg) continue; } } //add the new edge if the edge is not added yet if (tincedgeSS.Add(newCEdge)) { this.NewCEdgeLt.Add(newCEdge); tincedgelt.Add(newCEdge); } } if (blnSave == true) { CSaveFeature.SaveCEdgeEb(tincedgelt, "tincedgelt" + strIdentity, blnVisible: false); } this.CEdgeLt = tincedgelt; }
public override void OnClick() { try { //setup a file stream and a stream writer to write out the addresses that do not have a nearby street or a street out of range string path = @"C:\temp\DeleteDupVerts" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm") + ".txt"; System.IO.FileStream fileStream = new System.IO.FileStream(path, FileMode.Create); StreamWriter streamWriter = new StreamWriter(fileStream); streamWriter.WriteLine("UniqueID" + "," + "FeatureOID" + "," + "VertIndex1" + "," + "VertIndex2"); int intUniqueID = 0; bool updatePreviousPnt; int numberOfVerticesRemovedFromPntCollection; int vertexIndexToRemove; // get access to the current arcmap variables clsPushSgidStaticClass.GetCurrentMapDocVariables(); // show the cursor as busy System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; clsGlobals.pGFlayer = null; clsGlobals.arcFeatLayer = null; IFeatureLayer arcFeatureLayerVertPnts = null; IFeatureClass arcFeatureClassVertPnts = null; //var listOfIndexesToRemove = new List<Int32>(); // loop through the map's layers and check for the layer with the targeted name for (int i = 0; i < clsGlobals.pMap.LayerCount; i++) { if (clsGlobals.pMap.Layer[i].Name == "REMOVE_DUP_VERTS") { clsGlobals.pGFlayer = (IGeoFeatureLayer)clsGlobals.pMap.Layer[i]; clsGlobals.arcFeatLayer = (IFeatureLayer)clsGlobals.pMap.Layer[i]; } if (clsGlobals.pMap.Layer[i].Name == "VERT_PNTS") { arcFeatureLayerVertPnts = (IFeatureLayer)clsGlobals.pMap.Layer[i]; arcFeatureClassVertPnts = arcFeatureLayerVertPnts.FeatureClass; } } // make sure the user is editing //get the editor extension UID arcUID = new UID(); arcUID.Value = "esriEditor.Editor"; clsGlobals.arcEditor = clsGlobals.arcApplication.FindExtensionByCLSID(arcUID) as IEditor3; // check if editing first if (clsGlobals.arcEditor.EditState == ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing) { MessageBox.Show("You must be editing in order to remove duplicate vertices.", "Must Be Editing", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } IDataset arcDataset = (IDataset)clsGlobals.arcFeatLayer; IWorkspace arcWorkspace = arcDataset.Workspace; IWorkspaceEdit arcWorkspaceEdit = (IWorkspaceEdit)arcWorkspace; // make sure we're editing the correct workspace if (!(arcWorkspaceEdit.IsBeingEdited())) { MessageBox.Show("You must be editing the REMOVE_DUP_VERTS layer in order to proceed.", "Must Be Editing", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // get access to the selected features in the user specified layer IDisplayTable arcDisplayTable = (IDisplayTable)clsGlobals.arcFeatLayer; ISelectionSet arcSelectionSet = arcDisplayTable.DisplaySelectionSet; // make sure there's at least one feature selected in the specified layer if (arcSelectionSet.Count == 0) { MessageBox.Show( "You must select at least one feature in the REMOVE_DUP_VERTS layer to spatially assign values to.", "No Features are Selected.", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // confirm the user wants to edit that layer's fields on the selected records DialogResult dialogResult = MessageBox.Show( "Would you like to proceed with editing " + arcSelectionSet.Count + " features on the REMOVE_DUP_VERTS Layer, removing non-coincident verticies that are within 1 meter of eachother?", "Confirm Edits", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { // loop through the selected feature remove_dup_verts layer IEnumIDs arcEnumIDs = arcSelectionSet.IDs; int iD; while ((iD = arcEnumIDs.Next()) != -1) { vertexIndexToRemove = 0; numberOfVerticesRemovedFromPntCollection = 0; clsGlobals.arcFeatureToEditSpatial = clsGlobals.arcFeatLayer.FeatureClass.GetFeature(iD); clsGlobals.arcEditor.StartOperation(); // Loop through this features verticies. // Get the feature's geometry. IGeometry arcEdit_geometry = clsGlobals.arcFeatureToEditSpatial.Shape; IPolyline arcEdit_polyline = arcEdit_geometry as IPolyline; // get a point collection IPointCollection4 pointCollection = (IPointCollection4)arcEdit_polyline; IPoint currPoint = null; IPoint previousPoint = null; // Iterate the point collection array (the first point is the start of the line and last is the end of the line). // I added the numberOfVerticesRemovedFromPntCollection variable in order to preserve the initial point collection iterations (it's needed in order to loop through all the original vertices) for (int i = 0; i < pointCollection.PointCount + numberOfVerticesRemovedFromPntCollection; i++) { // Reset the boolean value. updatePreviousPnt = true; // Reset the number of vertices removed to zero //numberOfVerticesRemovedFromPntCollection = 0; //vertexIndexToRemove = 0; // Get the current point. currPoint = null; // This is the problem as it's setting the current i point, but this should be a reference to the original index //currPoint = pointCollection.get_Point(i); currPoint = pointCollection.get_Point(i - numberOfVerticesRemovedFromPntCollection); //MessageBox.Show("X:" + currPoint.X + " , Y:" + currPoint.Y); // Check if the previous point has been assigned yet (if not, it's the first itteration of this line segment) if (previousPoint != null) { // Check the distance between the currPoint and previousPoint to see if it's less than 1 meter IProximityOperator proximityOperator; IGeometry currGeometry = currPoint; IGeometry previousGeometry = previousPoint; proximityOperator = currGeometry as IProximityOperator; // Check distance to the previous vertex. double distBetweenCurrAndPrevPnt = proximityOperator.ReturnDistance(previousGeometry); // Check if distance is less than 1 meter. if (distBetweenCurrAndPrevPnt <= 3) { //MessageBox.Show(distance.ToString() + " is less than 1 meter."); // Check if the the current point intersects any other vertices, before we delete it. // If it does, then check the current point to see if intersects any other vertices, before we delete it. ISpatialFilter spatialFilterCurr = new SpatialFilterClass(); spatialFilterCurr.Geometry = currGeometry; spatialFilterCurr.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor featureCursorCurr = arcFeatureClassVertPnts.Search(spatialFilterCurr, false); IFeature featureCurr = null; int vertAtCurrPnt = 0; while ((featureCurr = featureCursorCurr.NextFeature()) != null) { vertAtCurrPnt = vertAtCurrPnt + 1; } // Check if we can delete this vertex if (vertAtCurrPnt > 1) { // There's more than one vertex here at the current vertex/point, so we cant' delete it, check the the previous // now check the if we can delete the previous point (as we can't delete the current point b/c it is co-incident) ISpatialFilter spatialFilterPrev = new SpatialFilterClass(); spatialFilterPrev.Geometry = previousGeometry; spatialFilterPrev.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor featureCursorPrev = arcFeatureClassVertPnts.Search(spatialFilterPrev, false); IFeature featurePrev = null; int vertsAtPrevPnt = 0; while ((featurePrev = featureCursorPrev.NextFeature()) != null) { vertsAtPrevPnt = vertsAtPrevPnt + 1; } // Check if we can delete this vertex if (vertsAtPrevPnt > 1) { // can delete this one either, so log it in the text file so we can inspect it manual intUniqueID = intUniqueID + 1; streamWriter.WriteLine(intUniqueID + "," + clsGlobals.arcFeatureToEditSpatial.OID + "," + i + "," + Convert.ToString(i - 1)); //MessageBox.Show("Can't Delete either vertex for this 1 meter duplicate. Help! Need a human!"); } else { // Delete the previous vertex. // Add this index to the list of //listOfIndexesToRemove.Add(i); vertexIndexToRemove = i - numberOfVerticesRemovedFromPntCollection; // test replacing the point collection before we do anything with it //pointCollection.ReplacePointCollection(0,pointCollection.PointCount,pointCollection); //MessageBox.Show("before remove: " + pointCollection.PointCount); // Remove the point from the collection. //pointCollection.RemovePoints(i - 1, 1); pointCollection.RemovePoints(vertexIndexToRemove - 1, 1); //MessageBox.Show("after remove: " + pointCollection.PointCount); // Increment the total number of vertices removed numberOfVerticesRemovedFromPntCollection = numberOfVerticesRemovedFromPntCollection + 1; // reset the point collection, now that the point has been removed //pointCollection.ReplacePointCollection(i, i - pointCollection.PointCount, pointCollection); // Replace the features shape with the newly modified point collection. //clsGlobals.arcFeatureToEditSpatial.Shape = pointCollection as IGeometry; //clsGlobals.arcFeatureToEditSpatial.Store(); } // release the feature cursor System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursorPrev); } else { // Delete the current vertex // Add this index to the list of //listOfIndexesToRemove.Add(i); vertexIndexToRemove = i - numberOfVerticesRemovedFromPntCollection; // test replacing the point collection before we do anything with it //pointCollection.ReplacePointCollection(0, pointCollection.PointCount, pointCollection); //MessageBox.Show("before remove: " + pointCollection.PointCount); // Remove the point from the collection. //pointCollection.RemovePoints(i, 1); pointCollection.RemovePoints(vertexIndexToRemove, 1); //MessageBox.Show("after remove: " + pointCollection.PointCount); // Increment the total number of vertices removed numberOfVerticesRemovedFromPntCollection = numberOfVerticesRemovedFromPntCollection + 1; // since we are removing this current point, make sure we don't assign it as the previousPoint (in other words keep the active previous point for the next iterattion) updatePreviousPnt = false; // reset the point collection, now that the point has been removed //pointCollection.ReplacePointCollection(i,i- pointCollection.PointCount,pointCollection); // Replace the features shape with the newly modified point collection. //clsGlobals.arcFeatureToEditSpatial.Shape = pointCollection as IGeometry; //clsGlobals.arcFeatureToEditSpatial.Store(); } // release the feature cursor System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursorCurr); } } // Set this current point to the next point, so next time through the iteration we can check the distance between them. if (updatePreviousPnt) { previousPoint = null; previousPoint = currPoint; } //MessageBox.Show("total times though the loop: " + i); } //// Remove the ID'd verticies from this segment //foreach (var index in listOfIndexesToRemove) //{ // // Remove the point from the collection. // pointCollection.RemovePoints(index, 1); //} // Replace the features shape with the newly modified point collection. clsGlobals.arcFeatureToEditSpatial.Shape = pointCollection as IGeometry; clsGlobals.arcFeatureToEditSpatial.Store(); clsGlobals.arcEditor.StopOperation("RemovedDuplicateVertices"); } //close the stream writer streamWriter.Close(); MessageBox.Show( "Done updating " + arcSelectionSet.Count + " features on the REMOVE_DUP_VERTS Layer, removing non-coincident vertices that were within 1 meter of eachother. Don't forget to save edits if you want to retain the changes.", "Done!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (dialogResult == DialogResult.No) { return; } } catch (Exception ex) { MessageBox.Show("Error Message: " + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine + "Error Source: " + Environment.NewLine + ex.Source + Environment.NewLine + Environment.NewLine + "Error Location:" + Environment.NewLine + ex.StackTrace, "Push Utrans Roads to SGID!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); clsGlobals.arcEditor.StopOperation("RemovedDuplicateVertices"); } }
private IPolyline GetNonLinearSubpart(int startSegmentIndex, double startFraction, int endSegmentIndex, double endFraction) { var subpart = new PolylineClass(); IPointCollection4 points = subpart; ISegmentCollection segs = subpart; subpart.SpatialReference = SpatialReference; bool hasNonLinearParts = false; object missing = Type.Missing; SegmentProxy segProxy; AoSegmentProxy aoSegProxy; #region startSegment var currentWksPoints = new List <WKSPointZ>(); if (_nonLinearSegments.TryGetValue(startSegmentIndex, out aoSegProxy)) { hasNonLinearParts = true; ISegment seg = aoSegProxy.InnerSegment; ICurve part; double end = 1; if (endSegmentIndex == startSegmentIndex) { end = endFraction; } seg.GetSubcurve(startFraction, end, true, out part); segs.AddSegment((ISegment)part, ref missing, ref missing); } else { segProxy = GetSegment(startSegmentIndex); IPnt p = segProxy.GetPointAt(startFraction, as3D: true); currentWksPoints.Add(QaGeometryUtils.GetWksPoint(p)); } #endregion #region segments for (int i = startSegmentIndex + 1; i < endSegmentIndex; i++) { if (_nonLinearSegments.TryGetValue(i, out aoSegProxy)) { hasNonLinearParts = true; if (currentWksPoints.Count > 0) { currentWksPoints.Add(_points[i]); WKSPointZ[] add = currentWksPoints.ToArray(); GeometryUtils.AddWKSPointZs(points, add); currentWksPoints.Clear(); } ISegment seg = GeometryFactory.Clone(aoSegProxy.InnerSegment); segs.AddSegment(seg, ref missing, ref missing); } else { currentWksPoints.Add(_points[i]); } } #endregion #region endsegment if (startSegmentIndex == endSegmentIndex) { if (currentWksPoints.Count > 0) { segProxy = GetSegment(endSegmentIndex); IPnt p = segProxy.GetPointAt(endFraction, as3D: true); currentWksPoints.Add(QaGeometryUtils.GetWksPoint(p)); WKSPointZ[] add = currentWksPoints.ToArray(); GeometryUtils.AddWKSPointZs(points, add); } } else { if (_nonLinearSegments.TryGetValue(endSegmentIndex, out aoSegProxy)) { hasNonLinearParts = false; if (currentWksPoints.Count > 0) { currentWksPoints.Add(_points[endSegmentIndex]); WKSPointZ[] add = currentWksPoints.ToArray(); GeometryUtils.AddWKSPointZs(points, add); currentWksPoints.Clear(); } ISegment seg = aoSegProxy.InnerSegment; ICurve part; seg.GetSubcurve(0, endFraction, true, out part); segs.AddSegment((ISegment)part, ref missing, ref missing); } else { currentWksPoints.Add(_points[endSegmentIndex]); segProxy = GetSegment(endSegmentIndex); IPnt p = segProxy.GetPointAt(endFraction, as3D: true); currentWksPoints.Add(QaGeometryUtils.GetWksPoint(p)); WKSPointZ[] add = currentWksPoints.ToArray(); GeometryUtils.AddWKSPointZs(points, add); } } #endregion if (hasNonLinearParts) { var topoOp = (ITopologicalOperator2)subpart; topoOp.IsKnownSimple_2 = false; topoOp.Simplify(); } return(subpart); }
public PartProxy([NotNull] BoxTree <SegmentProxy> boxTree, int partIndex, [NotNull] IPointCollection4 baseGeometry) { _partIndex = partIndex; SpatialReference = ((IGeometry)baseGeometry).SpatialReference; _points = new WKSPointZ[baseGeometry.PointCount]; GeometryUtils.QueryWKSPointZs(baseGeometry, _points); var segmentCollection = baseGeometry as ISegmentCollection; if (segmentCollection == null) { return; } SegmentCount = segmentCollection.SegmentCount; IsClosed = ((ICurve)segmentCollection).IsClosed; segmentCollection.HasNonLinearSegments(ref _hasNonLinearSegs); if (_hasNonLinearSegs) { _nonLinearSegments = new Dictionary <int, AoSegmentProxy>(); IEnumSegment enumSeg = segmentCollection.EnumSegments; bool recycling = enumSeg.IsRecycling; ISegment segment; int outPartIndex = 0; int outSegmentIndex = 0; enumSeg.Next(out segment, ref outPartIndex, ref outSegmentIndex); while (segment != null) { var line = segment as ILine; SegmentProxy segmentProxy; if (line != null) { segmentProxy = new WksSegmentProxy(this, _partIndex, outSegmentIndex); } else { var aoSegmentProxy = new AoSegmentProxy(recycling ? GeometryFactory.Clone(segment) : segment, _partIndex, outSegmentIndex); _nonLinearSegments.Add(outSegmentIndex, aoSegmentProxy); segmentProxy = aoSegmentProxy; } boxTree.Add(segmentProxy.Extent, segmentProxy); if (recycling) { Marshal.ReleaseComObject(segment); } enumSeg.Next(out segment, ref outPartIndex, ref outSegmentIndex); } } else { int segmentCount = segmentCollection.SegmentCount; for (int segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) { var wksSegmentProxy = new WksSegmentProxy(this, _partIndex, segmentIndex); boxTree.Add(wksSegmentProxy.Extent, wksSegmentProxy); } } }
public CPolyline(int intID, IPointCollection4 pCol) : this(intID, pCol as IPolyline5) { }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { m_dynamicMap = m_hookHelper.FocusMap as IDynamicMap; if (m_dynamicMap == null) return; if (!m_dynamicMap.DynamicMapEnabled) { MessageBox.Show("Please enable dynamic mode and try again."); return; } if (!m_bConnected) { m_xmlPath = GetPlaybackXmlPath(); if (m_xmlPath == string.Empty) return; m_bikePositionInfo = new BikePositionInfo(); m_bikePositionInfo.positionCount = m_bikePositionCount; m_bikePositionInfo.altitudeMeters = 0; m_bikePositionInfo.time = DateTime.Now; m_bikePositionInfo.position.X = 0; m_bikePositionInfo.position.Y = 0; m_bikePositionInfo.heartRate = 0; m_bikePositionInfo.lapCount = 0; m_bikePositionInfo.lapAverageHeartRate = 0; m_bikePositionInfo.lapMaximumHeartRate = 0; m_bikePositionInfo.lapDistanceMeters = 0; m_bikePositionInfo.lapMaximumSpeed = 0; m_bikePositionInfo.lapCalories = 0; m_gpsPosition = new PointClass(); m_additionalInfoPoint = new PointClass(); m_additionalInfoPoint.PutCoords(70, 90); m_bikeRouteGeometry = new PolylineClass(); // wire dynamic map events ((IDynamicMapEvents_Event)m_dynamicMap).AfterDynamicDraw += new IDynamicMapEvents_AfterDynamicDrawEventHandler(OnAfterDynamicDraw); ((IDynamicMapEvents_Event)m_dynamicMap).DynamicMapStarted += new IDynamicMapEvents_DynamicMapStartedEventHandler(OnDynamicMapStarted); // spin the thread that plays the data from the xml file m_dataLoaderThread = new Thread(new ParameterizedThreadStart(XmlReaderTask)); XmlDocTaksData taskData; taskData.xmlDocPath = m_xmlPath; m_dataLoaderThread.Start(taskData); } else { // unwire wire dynamic map events ((IDynamicMapEvents_Event)m_dynamicMap).AfterDynamicDraw -= new IDynamicMapEvents_AfterDynamicDrawEventHandler(OnAfterDynamicDraw); ((IDynamicMapEvents_Event)m_dynamicMap).DynamicMapStarted -= new IDynamicMapEvents_DynamicMapStartedEventHandler(OnDynamicMapStarted); // force the bike xml playback thread to quite m_autoEvent.Set(); m_dataLoaderThread.Join(); System.Diagnostics.Trace.WriteLine("Done!!!"); } m_bConnected = !m_bConnected; }
private void DWIntersect(CPolyline pBSCpl, ref List <CPoint> cptlt, double dblIgnorableDis) { IPointCollection4 pCol = new PolylineClass(); for (int i = 0; i < cptlt.Count; i++) { cptlt[i].SetPoint(); pCol.AddPoint(cptlt[i].pPoint); } IPolyline5 ipl = pCol as IPolyline5; pBSCpl.SetPolyline(); IRelationalOperator pRel = pBSCpl.pPolyline as IRelationalOperator; bool isCrosses = pRel.Crosses(ipl); if (isCrosses == true) { ITopologicalOperator pTop = pBSCpl.pPolyline as ITopologicalOperator; IGeometry pGeoIntersect = pTop.Intersect(ipl, esriGeometryDimension.esriGeometry0Dimension); IPointCollection4 pColIntersect = pGeoIntersect as IPointCollection4; double dblMaxDis = 0; for (int j = 0; j < pColIntersect.PointCount; j++) { double dblDis = CGeoFunc.CalDistanceFromStartPoint(ipl, pColIntersect.get_Point(j), false); if (dblDis > dblMaxDis) { dblMaxDis = dblDis; } } ICurve pSubCurve; ipl.GetSubcurve(dblMaxDis, ipl.Length, false, out pSubCurve); //IPolyline5 Cutipl = pSubCurve as IPolyline5; IPointCollection4 iplCutCol = pSubCurve as IPointCollection4; //the new first segment IPointCollection4 pSegCol = new PolylineClass(); pSegCol.AddPoint(ipl.FromPoint, _Missing, _Missing); pSegCol.AddPoint(iplCutCol.get_Point(1), _Missing, _Missing); IPolyline5 seg = pSegCol as IPolyline5; bool isCrossesSeg; int intIndex = 0; while (intIndex < iplCutCol.PointCount - 1) { intIndex++; pSegCol.UpdatePoint(1, iplCutCol.get_Point(intIndex)); isCrossesSeg = pRel.Crosses(seg); if (isCrossesSeg == false) { iplCutCol.RemovePoints(1, intIndex - 1); iplCutCol.UpdatePoint(0, ipl.FromPoint); break; } if (seg.Length >= dblIgnorableDis) { double dblOriginalIntersectionDis = CGeoFunc.CalDistanceFromStartPoint(pBSCpl.pPolyline, pCol.get_Point(0), false); double dblRealisticIntersectionDis = CGeoFunc.CalDistanceFromStartPoint(pBSCpl.pPolyline, iplCutCol.get_Point(0), false); IPointCollection4 pColBSCpl = pBSCpl.pPolyline as IPointCollection4; double dblSumDis = 0; for (int i = 0; i < pColBSCpl.PointCount - 1; i++) { double dblDis = CGeoFunc.CalDis(pColBSCpl.get_Point(i), pColBSCpl.get_Point(i + 1)); dblSumDis += dblDis; if (dblSumDis >= dblRealisticIntersectionDis) { double dblDisPre = Math.Abs(dblSumDis - dblDis - dblOriginalIntersectionDis); double dblDisNext = Math.Abs(dblSumDis - dblOriginalIntersectionDis); IPoint intersectpt = new PointClass(); if (dblDisPre <= dblDisNext) { intersectpt = pColBSCpl.get_Point(i); } else { intersectpt = pColBSCpl.get_Point(i + 1); } iplCutCol.UpdatePoint(0, intersectpt); break; } } break; } } cptlt = CHelpFunc.GetCptEbByICol(iplCutCol).ToList(); } }
public void GeneratePoints2(string sLineLayer, string sDepthPointsLayer, double dblInterval, string strDepthField) { try { IMxDocument pmxdoc = ArcMap.Document as IMxDocument; IMap pmap = pmxdoc.FocusMap; IFeatureLayer pDepthSoundings = FindLayer(pmap, sDepthPointsLayer) as IFeatureLayer; IFeatureLayer pLineLayer = FindLayer(pmap, sLineLayer) as IFeatureLayer; IFeatureLayer pOutpoints = new FeatureLayerClass(); pOutpoints.FeatureClass = MakePointFC(); pOutpoints.Name = "Output Points"; ArcMap.Document.ActiveView.FocusMap.AddLayer(pOutpoints); IProgressDialog2 pProgressDialog = ShowProgressIndicator("Calculating...", pLineLayer.FeatureClass.FeatureCount(null), 1); pProgressDialog.ShowDialog(); //Set up the Outpoints cursor IFeatureCursor pFCurOutPoints = pOutpoints.Search(null, false); pFCurOutPoints = pOutpoints.FeatureClass.Insert(true); //Set up the LineLayer Cursor IFeatureCursor pFCur = pLineLayer.Search(null, false); IFeature pLineFeature = pFCur.NextFeature(); IFeatureBuffer pFBuffer = pOutpoints.FeatureClass.CreateFeatureBuffer(); ICurve pCurve; IPoint ppoint; int iLineProgressCount = 1; double dblDistance = 0; double dblTotalDistanceCalculated = 0; double iNumIntervals = 0; double dblElevationDiff = 0; double dblElevationInterval = 0; double dblElevation = 0; double dlbStartElevation = 0; double dblEndElevation = 0; pProgressDialog.Description = "Generating points for Line: " + iLineProgressCount + " of " + pLineLayer.FeatureClass.FeatureCount(null).ToString(); while (pLineFeature != null) { int iStartVertex = 0; int iEndVertex = 1; //Get the vertices of the line feature IPointCollection4 pPointColl = pLineFeature.Shape as IPointCollection4; //loop thru the vertices for (int i = 0; i <= pPointColl.PointCount - 1; i++) { IPoint pStartPoint = pPointColl.get_Point(iStartVertex); IPoint pEndPoint = pPointColl.get_Point(iEndVertex); //Make an intermediate line segment between each set of vertices IPath pPath = MakePath(pStartPoint, pEndPoint); //Get the starting elevation from the depth point layer dlbStartElevation = GetPointElevation(pDepthSoundings, pLineLayer, pStartPoint, strDepthField); dblElevation = dlbStartElevation; IPointCollection pPointForPath = null; //Get the ending elevation from the next vertex pEndPoint = pPointColl.get_Point(iEndVertex); dblEndElevation = GetPointElevation(pDepthSoundings, pLineLayer, pEndPoint, strDepthField); //If the returned elevation is 0, then there is no coincident depth point, move to the next vertex for your endpoint if (dblEndElevation == 0) { //IPointCollection reshapePath = new PathClass(); object missing = Type.Missing; pPointForPath = new PathClass(); pPointForPath.AddPoint(pStartPoint, ref missing, ref missing); while (dblEndElevation == 0) { pEndPoint = pPointColl.get_Point(iEndVertex); dblEndElevation = GetPointElevation(pDepthSoundings, pLineLayer, pEndPoint, strDepthField); pPointForPath.AddPoint(pEndPoint, ref missing, ref missing); //pLineSegment.Reshape(reshapePath as IPath); if (dblEndElevation != 0) { break; } iEndVertex++; } } if (pPointForPath != null) { pPath = pPointForPath as IPath; } //number of line segments based on the user's interval iNumIntervals = Convert.ToDouble(pPath.Length / dblInterval); dblElevationDiff = dblEndElevation - dlbStartElevation; //The calculated elevation interval to step up each time dblElevationInterval = dblElevationDiff / iNumIntervals; ppoint = new PointClass(); while (dblTotalDistanceCalculated <= pPath.Length) { pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID); pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), Math.Round(dblDistance, 4)); pFBuffer.set_Value(pFBuffer.Fields.FindField("Elevation"), Math.Round(dblElevation, 4)); //this code set the point on the line at a distance pPath.QueryPoint(0, dblDistance, false, ppoint); pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), ppoint.X); pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), ppoint.Y); //reCalc the new distance and elevation values for the next iteration dblDistance = dblDistance + dblInterval; dblTotalDistanceCalculated = dblTotalDistanceCalculated + dblInterval; //Insert the feature into the featureclass pFBuffer.Shape = ppoint; if (!IsPointCoincident(ppoint, pOutpoints)) { pFCurOutPoints.InsertFeature(pFBuffer); } if (dblTotalDistanceCalculated >= pPath.Length) { break; } dblElevation = dblElevation + dblElevationInterval; } //start the next line segment at the end of last one iStartVertex = iEndVertex; //look to the next vertex for the new ending point iEndVertex++; if (iEndVertex == pPointColl.PointCount) { ////if its the last vertex of the last line, add a point //pFBuffer.Shape = pPath.ToPoint; //pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID); //pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), Math.Round(dblDistance, 4)); //pFBuffer.set_Value(pFBuffer.Fields.FindField("Elevation"), Math.Round(dblElevation, 4)); //pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), pPath.ToPoint.X); //pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), pPath.ToPoint.Y); //pFCurOutPoints.InsertFeature(pFBuffer); //Reset the distance values back to 0 for the next feature dblDistance = 0; dblTotalDistanceCalculated = 0; pStepProgressor.Step(); iLineProgressCount++; pPath.SetEmpty(); break; } //Reset the distance values back to 0 for the next feature dblDistance = 0; dblTotalDistanceCalculated = 0; //pLineFeature = pFCur.NextFeature(); pStepProgressor.Step(); //pProgressDialog.Description = "Generating points for Line: " + iLineProgressCount + " of " + pLineLayer.FeatureClass.FeatureCount(null).ToString(); iLineProgressCount++; pPath.SetEmpty(); } pLineFeature = pFCur.NextFeature(); } //cleanup pFCurOutPoints.Flush(); pFCur.Flush(); pProgressDialog.HideDialog(); pmxdoc.ActiveView.Refresh(); } catch (Exception ex) { } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { m_dynamicMap = m_hookHelper.FocusMap as IDynamicMap; if (m_dynamicMap == null) { return; } if (!m_dynamicMap.DynamicMapEnabled) { MessageBox.Show("Please enable dynamic mode and try again."); return; } if (!m_bConnected) { m_xmlPath = GetPlaybackXmlPath(); if (m_xmlPath == string.Empty) { return; } m_bikePositionInfo = new BikePositionInfo(); m_bikePositionInfo.positionCount = m_bikePositionCount; m_bikePositionInfo.altitudeMeters = 0; m_bikePositionInfo.time = DateTime.Now; m_bikePositionInfo.position.X = 0; m_bikePositionInfo.position.Y = 0; m_bikePositionInfo.heartRate = 0; m_bikePositionInfo.lapCount = 0; m_bikePositionInfo.lapAverageHeartRate = 0; m_bikePositionInfo.lapMaximumHeartRate = 0; m_bikePositionInfo.lapDistanceMeters = 0; m_bikePositionInfo.lapMaximumSpeed = 0; m_bikePositionInfo.lapCalories = 0; m_gpsPosition = new PointClass(); m_additionalInfoPoint = new PointClass(); m_additionalInfoPoint.PutCoords(70, 90); m_bikeRouteGeometry = new PolylineClass(); // wire dynamic map events ((IDynamicMapEvents_Event)m_dynamicMap).AfterDynamicDraw += new IDynamicMapEvents_AfterDynamicDrawEventHandler(OnAfterDynamicDraw); ((IDynamicMapEvents_Event)m_dynamicMap).DynamicMapStarted += new IDynamicMapEvents_DynamicMapStartedEventHandler(OnDynamicMapStarted); // spin the thread that plays the data from the xml file m_dataLoaderThread = new Thread(new ParameterizedThreadStart(XmlReaderTask)); XmlDocTaksData taskData; taskData.xmlDocPath = m_xmlPath; m_dataLoaderThread.Start(taskData); } else { // unwire wire dynamic map events ((IDynamicMapEvents_Event)m_dynamicMap).AfterDynamicDraw -= new IDynamicMapEvents_AfterDynamicDrawEventHandler(OnAfterDynamicDraw); ((IDynamicMapEvents_Event)m_dynamicMap).DynamicMapStarted -= new IDynamicMapEvents_DynamicMapStartedEventHandler(OnDynamicMapStarted); // force the bike xml playback thread to quite m_autoEvent.Set(); m_dataLoaderThread.Join(); System.Diagnostics.Trace.WriteLine("Done!!!"); } m_bConnected = !m_bConnected; }