private void cmdOK_Click(object sender, EventArgs e) { //calc distance between points double dbp = 0; if (rbNOP.Checked) dbp = m_polyline.Length / (int.Parse(txtNOP.Text) + 1); else dbp = int.Parse(txtDist.Text); m_editor.StartOperation(); this.Cursor = Cursors.WaitCursor; //create points at distance between points up to total length for (double d = dbp; d < m_polyline.Length; d += dbp) { IConstructPoint contructionPoint = new PointClass(); contructionPoint.ConstructAlong(m_polyline, esriSegmentExtension.esriNoExtension,d,false); CreatePoint(contructionPoint as IPoint); } //create points at start and end of sketch if (chkEnds.Checked) { CreatePoint(m_polyline.FromPoint); CreatePoint(m_polyline.ToPoint); } this.Cursor = Cursors.Default; m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("CrtPtsAlongLine")); this.Close(); }
private IPoint ConstructMiddlePoint(IPolyline pline, double distance) { IConstructPoint constructpnt = new PointClass();; constructpnt.ConstructAlong(pline, esriSegmentExtension.esriNoExtension, distance, false); return(constructpnt as IPoint); }
private List <IPoint> CreateLinesAtStartPoint(int numberOfLines, ref int lineCounter, ref int juncCounter, ref int spCounter, IPoint startPoint, double lineLength, double angleInRadians, IFeatureClass lineFC, IFeatureClass fuseFC, IFeatureClass serveFC, IFeatureClass juncFC) { List <IPoint> retList = new List <IPoint>(); System.Random rnd = new System.Random(); double starter = 1.0 / rnd.Next(1, 9); //starter = .5; for (double index = starter; index < numberOfLines; index++) { IConstructPoint outPoint = new PointClass(); outPoint.ConstructAngleDistance(startPoint, angleInRadians * index, lineLength); IPoint outPointpnt = outPoint as IPoint; IPointCollection pc = new PolylineClass(); pc.AddPoint(startPoint); pc.AddPoint(outPointpnt); IFeature lineFe = lineFC.CreateFeature(); lineFe.Shape = pc as IGeometry; lineFe.Store(); lineCounter++; ICurve curve = (ICurve)lineFe.ShapeCopy; bool brs = false; double dfc = 0; double dac = 0; IPoint pntToNQ = new PointClass(); if (lineLength > 200) { for (int j = 0; j <= numberOfLines; j++) { dac = j * (1.0 / numberOfLines); if (dac == 0) { IConstructPoint pntCP2 = new PointClass(); pntCP2.ConstructAlong(curve, esriSegmentExtension.esriNoExtension, 1, false); IPoint pntcp2pnt = (IPoint)pntCP2; IFeature fuseFe = fuseFC.CreateFeature(); fuseFe.Shape = pntcp2pnt as IGeometry; fuseFe.Store(); } else { IConstructPoint pntCP2 = new PointClass(); pntCP2.ConstructAlong(curve, esriSegmentExtension.esriNoExtension, dac, true); IPoint pntcp2pnt = (IPoint)pntCP2; IFeature juncfe = juncFC.CreateFeature(); juncfe.Shape = pntcp2pnt as IGeometry; juncfe.Store(); retList.Add(pntcp2pnt as IPoint); juncCounter++; } } } else { IFeature servFe = serveFC.CreateFeature(); servFe.Shape = outPointpnt as IGeometry; servFe.Store(); spCounter++; } } return(retList); }
static public double GetCurvature(IPoint firstPt, IPoint secondPt, IPoint thirdPt) { IPolyline ply = new PolylineClass(); ply.FromPoint = firstPt; ply.ToPoint = secondPt; IPolyline ply1 = new PolylineClass(); ply1.FromPoint = secondPt; ply1.ToPoint = thirdPt; IConstructPoint contructionPoint = new PointClass(); contructionPoint.ConstructAlong(ply, esriSegmentExtension.esriExtendAtTo, 5, true); IPoint extendPt = contructionPoint as IPoint; ILine line = new LineClass(); line.FromPoint = secondPt; line.ToPoint = extendPt; double beforeAnge = line.Angle; if (beforeAnge < 0) { beforeAnge = beforeAnge + 2 * Math.PI; } ILine afterLine = new LineClass(); afterLine.FromPoint = secondPt; afterLine.ToPoint = thirdPt; double afterAngle = afterLine.Angle; if (afterAngle < 0) { afterAngle = afterAngle + 2 * Math.PI; } double diferenceAngle = afterAngle - beforeAnge; if (Math.Abs(diferenceAngle) > Math.PI) { if (diferenceAngle < 0) { diferenceAngle = diferenceAngle + 2 * Math.PI; } else { diferenceAngle = diferenceAngle - 2 * Math.PI; } } return(diferenceAngle); }
//沿线创建法 private void button1_Click(object sender, EventArgs e) { delFeature("point"); IFeature polylineFeature; polylineFeature = getPolylineFeature("polyline"); if (polylineFeature != null) { ICurve curve = polylineFeature.Shape as ICurve; IConstructPoint constructPoint = new PointClass(); constructPoint.ConstructAlong(curve, esriSegmentExtension.esriNoExtension, 10, true); IPoint point1 = constructPoint as IPoint; constructPoint = new PointClass(); constructPoint.ConstructAlong(curve, esriSegmentExtension.esriNoExtension, 20, false); IPoint point2 = constructPoint as IPoint; addFeature("point", point1); addFeature("point", point2); } axMapControl1.Refresh(); }
private void cmdOK_Click(object sender, EventArgs e) { //calc distance between points double dbp = 0; if (rbNOP.Checked) { dbp = m_polyline.Length / (int.Parse(txtNOP.Text) + 1); } else { dbp = int.Parse(txtDist.Text); } m_editor.StartOperation(); this.Cursor = Cursors.WaitCursor; //create points at distance between points up to total length for (double d = dbp; d < m_polyline.Length; d += dbp) { IConstructPoint contructionPoint = new PointClass(); contructionPoint.ConstructAlong(m_polyline, esriSegmentExtension.esriNoExtension, d, false); CreatePoint(contructionPoint as IPoint); } //create points at start and end of sketch if (chkEnds.Checked) { CreatePoint(m_polyline.FromPoint); CreatePoint(m_polyline.ToPoint); } this.Cursor = Cursors.Default; m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("CrtPtsAlongLine")); this.Close(); }
public void ExtractPointData(string sLineLayer, string sRasterLayer, double dblInterval, string strFileName) { try { strSaveFile = strFileName; IMxDocument pmxdoc = ArcMap.Document as IMxDocument; IMap pmap = pmxdoc.FocusMap; IFeatureLayer pLineLayer = FindLayer(sLineLayer) as IFeatureLayer; IRasterLayer pRasterLayer = FindLayer(sRasterLayer) as IRasterLayer; //IFeatureLayer pPointLayer = FindLayer(sPointLayer) as IFeatureLayer; IFeatureLayer pPointLayer = new FeatureLayerClass(); pPointLayer.FeatureClass = MakePointFC(); //pPointLayer.Name = "Points"; // ArcMap.Document.ActiveView.FocusMap.AddLayer(pPointLayer); //get the Workspace from the IDataset interface on the feature class IDataset dataset = (IDataset)pLineLayer.FeatureClass; IWorkspace workspace = dataset.Workspace; //Cast for an IWorkspaceEdit IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace; //Start an edit session and operation workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); IProgressDialog2 pProgressDialog = ShowProgressIndicator("Calculating...", pLineLayer.FeatureClass.FeatureCount(null), 1); pProgressDialog.ShowDialog(); //Set up the Outpoints cursor IFeatureCursor pFCurOutPoints = pPointLayer.Search(null, false); pFCurOutPoints = pPointLayer.FeatureClass.Insert(true); //Set up the LineLayer Cursor IFeatureCursor pFCur = pLineLayer.Search(null, false); IFeature pLineFeature = pFCur.NextFeature(); IFeatureBuffer pFBuffer = pPointLayer.FeatureClass.CreateFeatureBuffer(); ICurve pCurve; double dlbProcessedLength = 0; double dblFCTotalLength = 0; int p = 0; while (pLineFeature != null) { pProgressDialog.Description = "Calculating line segment " + p.ToString() + " of: " + pLineLayer.FeatureClass.FeatureCount(null).ToString(); //create startpoint pCurve = pLineFeature.Shape as ICurve; pFBuffer.Shape = pCurve.FromPoint; pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), 0); pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID); pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), pCurve.FromPoint.X); pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), pCurve.FromPoint.Y); pFCurOutPoints.InsertFeature(pFBuffer); double dblTotalDistance = pCurve.Length; dlbProcessedLength = dblInterval; IConstructPoint contructionPoint; IPoint ppoint; while (dlbProcessedLength <= dblTotalDistance) { contructionPoint = new PointClass(); contructionPoint.ConstructAlong(pCurve, esriSegmentExtension.esriNoExtension, dlbProcessedLength, false); ppoint = new PointClass(); ppoint = contructionPoint as IPoint; pFBuffer.Shape = ppoint; //dblFCTotalLength += dblInterval; pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), Math.Round(dlbProcessedLength, 4)); pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID); pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), ppoint.X); pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), ppoint.Y); pFCurOutPoints.InsertFeature(pFBuffer); dlbProcessedLength += dblInterval; pStepProgressor.Step(); } dblFCTotalLength += dblInterval; p++; pLineFeature = pFCur.NextFeature(); } //cleanup pFCurOutPoints.Flush(); pFCur.Flush(); //Stop editing workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); Extract(pRasterLayer, pPointLayer); pProgressDialog.HideDialog(); pmxdoc.ActiveView.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); } }
public void ExtractPointData(string sLineLayer, string sRasterLayer, double dblInterval,string strFileName) { try { strSaveFile = strFileName; IMxDocument pmxdoc = ArcMap.Document as IMxDocument; IMap pmap = pmxdoc.FocusMap; IFeatureLayer pLineLayer = FindLayer(sLineLayer) as IFeatureLayer; IRasterLayer pRasterLayer = FindLayer(sRasterLayer) as IRasterLayer; //IFeatureLayer pPointLayer = FindLayer(sPointLayer) as IFeatureLayer; IFeatureLayer pPointLayer = new FeatureLayerClass(); pPointLayer.FeatureClass = MakePointFC(); //pPointLayer.Name = "Points"; // ArcMap.Document.ActiveView.FocusMap.AddLayer(pPointLayer); //get the Workspace from the IDataset interface on the feature class IDataset dataset = (IDataset)pLineLayer.FeatureClass; IWorkspace workspace = dataset.Workspace; //Cast for an IWorkspaceEdit IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace; //Start an edit session and operation workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); IProgressDialog2 pProgressDialog = ShowProgressIndicator("Calculating...", pLineLayer.FeatureClass.FeatureCount(null), 1); pProgressDialog.ShowDialog(); //Set up the Outpoints cursor IFeatureCursor pFCurOutPoints = pPointLayer.Search(null, false); pFCurOutPoints = pPointLayer.FeatureClass.Insert(true); //Set up the LineLayer Cursor IFeatureCursor pFCur = pLineLayer.Search(null, false); IFeature pLineFeature = pFCur.NextFeature(); IFeatureBuffer pFBuffer = pPointLayer.FeatureClass.CreateFeatureBuffer(); ICurve pCurve; double dlbProcessedLength = 0; double dblFCTotalLength = 0; int p = 0; while (pLineFeature != null) { pProgressDialog.Description = "Calculating line segment " + p.ToString() + " of: " + pLineLayer.FeatureClass.FeatureCount(null).ToString(); //create startpoint pCurve = pLineFeature.Shape as ICurve; pFBuffer.Shape = pCurve.FromPoint; pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), 0); pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID); pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), pCurve.FromPoint.X); pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), pCurve.FromPoint.Y); pFCurOutPoints.InsertFeature(pFBuffer); double dblTotalDistance = pCurve.Length; dlbProcessedLength = dblInterval; IConstructPoint contructionPoint; IPoint ppoint; while (dlbProcessedLength <= dblTotalDistance) { contructionPoint = new PointClass(); contructionPoint.ConstructAlong(pCurve, esriSegmentExtension.esriNoExtension, dlbProcessedLength, false); ppoint = new PointClass(); ppoint = contructionPoint as IPoint; pFBuffer.Shape = ppoint; //dblFCTotalLength += dblInterval; pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), Math.Round(dlbProcessedLength, 4)); pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID); pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), ppoint.X); pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), ppoint.Y); pFCurOutPoints.InsertFeature(pFBuffer); dlbProcessedLength += dblInterval; pStepProgressor.Step(); } dblFCTotalLength += dblInterval; p++; pLineFeature = pFCur.NextFeature(); } //cleanup pFCurOutPoints.Flush(); pFCur.Flush(); //Stop editing workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); Extract(pRasterLayer, pPointLayer); pProgressDialog.HideDialog(); pmxdoc.ActiveView.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); } }
private IPoint ConstructMiddlePoint(IPolyline pline, double distance) { IConstructPoint constructpnt = new PointClass(); ; constructpnt.ConstructAlong(pline, esriSegmentExtension.esriNoExtension, distance, false); return constructpnt as IPoint; }