public CurveConstruction MoveTo([NotNull] IPoint point) { object missing = Type.Missing; if (Curve is IPolygon) { var rings = (IGeometryCollection)Curve; var lastRing = (IRing)rings.Geometry[rings.GeometryCount - 1]; lastRing.Close(); IPointCollection newRing = new RingClass(); newRing.AddPoint(point, ref missing, ref missing); rings.AddGeometry((IGeometry)newRing, ref missing, ref missing); } else if (Curve is IPolyline) { var paths = (IGeometryCollection)Curve; IPointCollection newPath = new PathClass(); newPath.AddPoint(point, ref missing, ref missing); paths.AddGeometry((IGeometry)newPath, ref missing, ref missing); } else { throw new NotImplementedException("Unhandled geometryType" + Curve.GeometryType); } return(this); }
public static IPolyline Create3DPolylineFromPoints(IPoint pointLeft, IPoint pointRight) { object missing = Type.Missing; IGeometryCollection geometryCollection = new PolylineClass(); IPointCollection pointCollection = new PathClass(); pointCollection.AddPoint(pointLeft); pointCollection.AddPoint(pointRight); geometryCollection.AddGeometry(pointCollection as IGeometry, ref missing, ref missing); var geometry = geometryCollection as IGeometry; IZAware zAware = geometry as IZAware; zAware.ZAware = true; return(geometryCollection as IPolyline); }
public IGeometry XpgisFeatureToGeometry(ICoFeature icoFeature_0) { object before = Missing.Value; switch (icoFeature_0.Type) { case CoFeatureType.Point: { IPoint[] pointArray2 = this.method_4((icoFeature_0 as ICoPointFeature).Point); int index = 0; if (0 >= pointArray2.Length) { break; } return(pointArray2[index]); } case CoFeatureType.Polygon: { IGeometryCollection geometrys2 = new PolygonClass(); foreach (CoPointCollection points in (icoFeature_0 as ICoPolygonFeature).Points) { IPointCollection points3 = new RingClass(); foreach (IPoint point2 in this.method_4(points)) { points3.AddPoint(point2, ref before, ref before); } geometrys2.AddGeometry((IGeometry)points3, ref before, ref before); } ((IPolygon)geometrys2).SimplifyPreserveFromTo(); return((IGeometry)geometrys2); } case CoFeatureType.Polyline: { IGeometryCollection geometrys = new PolylineClass(); foreach (CoPointCollection points in (icoFeature_0 as ICoPolylineFeature).Points) { IPoint[] pointArray3 = this.method_4(points); IPointCollection points2 = new PathClass(); for (int i = 0; i < pointArray3.Length; i++) { points2.AddPoint(pointArray3[i], ref before, ref before); } geometrys.AddGeometry((IGeometry)points2, ref before, ref before); } return((IGeometry)geometrys); } } return(null); }
internal static Dictionary <IPolygon, bool> GetVisibilityPolygons(IPoint observerPoint, Dictionary <IPointCollection, bool> pointCollections) { var visibilityPolygons = new Dictionary <IPolygon, bool>(); foreach (var points in pointCollections) { var polygonPoints = new PathClass(); polygonPoints.AddPoint(observerPoint); polygonPoints.AddPointCollection(points.Key); visibilityPolygons.Add(EsriTools.GetVisilityPolygon(polygonPoints), points.Value); } return(visibilityPolygons); }
private static IPointCollection GetPoints(ProfileSurface surface) { var points = new PathClass(); foreach (var surfacePoint in surface.ProfileSurfacePoints) { IPoint point = new Point() { X = surfacePoint.X, Y = surfacePoint.Y, Z = surfacePoint.Z, SpatialReference = EsriTools.Wgs84Spatialreference }; point.Project(ArcMap.Document.FocusMap.SpatialReference); points.AddPoint(point); } return(points); }
private void dToolStripMenuItem_Click(object sender, EventArgs e) { IGeometry buffer; ISelection pSeletion = axMapControl1.Map.FeatureSelection; IEnumFeature pEnumFeature = (IEnumFeature)pSeletion; //IGraphicsContainer graphicsContainer = axMapControl1.ActiveView.GraphicsContainer; //graphicsContainer.DeleteAllElements(); IFeature pFeature = pEnumFeature.Next();//自己 double bufferDistance = GlobalData.dist; if (bufferDistance <= 0.0) { MessageBox.Show("距离设置错误"); return; } if (pFeature != null) { axMapControl1.Map.ClearSelection(); ITopologicalOperator topoOperator = pFeature.Shape as ITopologicalOperator; buffer = topoOperator.Buffer(bufferDistance); ISpatialFilter spatilaFilter = new SpatialFilterClass(); //在缓冲区内 spatilaFilter.Geometry = buffer; spatilaFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; int iIndex; object o = Type.Missing; IPoint pt0 = pFeature.Shape as IPoint; for (iIndex = 0; iIndex < axMapControl1.LayerCount; iIndex++) { ILayer pLayer = axMapControl1.get_Layer(iIndex); IFeatureLayer pFLayer = pLayer as IFeatureLayer; IFeatureClass pFClass = pFLayer.FeatureClass; ILayer lineLayer = axMapControl1.get_Layer(axMapControl1.LayerCount - 1 - iIndex); IFeatureLayer lineFLayer = lineLayer as IFeatureLayer; IFeatureClass lineFClass = lineFLayer.FeatureClass; if (pFClass.ShapeType == esriGeometryType.esriGeometryPoint) //点图层 { //IWorkspaceFactory pWSF=new IFeatureCursor featureCursor = pFClass.Search(spatilaFilter, true);//圈内的点 IFeature oFeature = featureCursor.NextFeature(); while (oFeature != null) { if (oFeature.OID != pFeature.OID) { IFeatureCursor polygonCursor = lineFClass.Search(spatilaFilter, true); IFeature polyFeature = polygonCursor.NextFeature(); IGeometryCollection polyline = new PolylineClass(); IPoint pt1 = oFeature.Shape as IPoint; IPointCollection pPath = new PathClass(); pPath.AddPoint(pt0, ref o, ref o); pPath.AddPoint(pt1, ref o, ref o); polyline.AddGeometry(pPath as IGeometry); ITopologicalOperator pTopoOperator = polyline as ITopologicalOperator; while (polyFeature != null) { IPolyline pPolylineresult = pTopoOperator.Intersect(polyFeature.Shape, esriGeometryDimension.esriGeometry1Dimension) as IPolyline; if (pPolylineresult.Length != 0) { break; } polyFeature = polygonCursor.NextFeature(); } if (polyFeature == null) //normal end { axMapControl1.Map.SelectFeature(pLayer, oFeature); //找出处自己之外的伙伴 } } oFeature = featureCursor.NextFeature(); } break; } } axMapControl1.Refresh(); } }
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { if (flagSelectFeature == true) //选择实体 { axMapControl1.Map.ClearSelection(); IGeometry geometry = axMapControl1.TrackRectangle(); IPoint p1, p2, p3, p4; p1 = new PointClass(); p2 = new PointClass(); p3 = new PointClass(); p4 = new PointClass(); p1.PutCoords(geometry.Envelope.XMin, geometry.Envelope.YMin); p2.PutCoords(geometry.Envelope.XMin, geometry.Envelope.YMax); p3.PutCoords(geometry.Envelope.XMax, geometry.Envelope.YMax); p4.PutCoords(geometry.Envelope.XMax, geometry.Envelope.YMin); IGeometryCollection pPolyline = new PolylineClass(); object o = Type.Missing; for (int i = 0; i < 4; i++) { IPointCollection pPath = new PathClass(); switch (i) { case 0: pPath.AddPoint(p1, ref o, ref o); pPath.AddPoint(p2, ref o, ref o); break; case 1: pPath.AddPoint(p2, ref o, ref o); pPath.AddPoint(p3, ref o, ref o); break; case 2: pPath.AddPoint(p3, ref o, ref o); pPath.AddPoint(p4, ref o, ref o); break; case 3: pPath.AddPoint(p4, ref o, ref o); pPath.AddPoint(p1, ref o, ref o); break; } pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o); } IGeometry polyline = pPolyline as IGeometry; ILineElement pLineElement = new LineElementClass(); rectpElement = pLineElement as IElement; rectpElement.Geometry = polyline; IGraphicsContainer graphicsContainer = axMapControl1.ActiveView.GraphicsContainer; graphicsContainer.DeleteAllElements(); graphicsContainer.AddElement(rectpElement, 0); axMapControl1.Refresh(); //创建sptialFilter ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = geometry; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; int iIndex = 0; for (iIndex = 0; iIndex < axMapControl1.LayerCount; iIndex++) { ILayer pLayer = axMapControl1.get_Layer(iIndex); IFeatureLayer pFLayer = pLayer as IFeatureLayer; IFeatureClass pFClass = pFLayer.FeatureClass; if (pFClass.ShapeType == esriGeometryType.esriGeometryPoint) { IFeatureCursor featureCursor = pFClass.Search(spatialFilter, true); IFeature pFeature = featureCursor.NextFeature(); while (pFeature != null) { axMapControl1.Map.SelectFeature(pLayer, pFeature); pFeature = featureCursor.NextFeature(); } axMapControl1.Refresh(); } } flagSelectFeature = false; 择测区范围ToolStripMenuItem.Checked = false; } else if (flagCreateFeature == true) //创建实体 { int iIndex; for (iIndex = 0; iIndex < axMapControl1.LayerCount; iIndex++) { ILayer pLayer = axMapControl1.get_Layer(iIndex); IFeatureLayer pFLayer = pLayer as IFeatureLayer; IFeatureClass pFClass = pFLayer.FeatureClass; IGeometry geometry = null; if (pFClass.ShapeType == esriGeometryType.esriGeometryPoint) { IPoint point = new PointClass(); point.PutCoords(e.mapX, e.mapY); geometry = point as IGeometry; IFeature pFeature = pFClass.CreateFeature(); pFeature.Shape = geometry; pFeature.Store(); axMapControl1.Refresh(); flagCreateFeature = false; 除控制点ToolStripMenuItem.Checked = false; } } } else if (flagSelectStation == true) { axMapControl1.Map.ClearSelection(); IGeometry geometry = axMapControl1.TrackCircle(); ISpatialFilter spatialFilter = new SpatialFilter(); spatialFilter.Geometry = geometry; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; int iIndex; for (iIndex = 0; iIndex < axMapControl1.LayerCount; iIndex++) { ILayer pLayer = axMapControl1.get_Layer(iIndex); IFeatureLayer pFLayer = pLayer as IFeatureLayer; IFeatureClass pFClass = pFLayer.FeatureClass; if (pFClass.ShapeType == esriGeometryType.esriGeometryPoint) { IFeatureCursor featureCursor = pFClass.Search(spatialFilter, true); IFeature pFeature = featureCursor.NextFeature(); while (pFeature != null) { axMapControl1.Map.SelectFeature(pLayer, pFeature); pFeature = featureCursor.NextFeature(); } axMapControl1.Refresh(); flagSelectStation = false; 择当前测站ToolStripMenuItem.Checked = false; } } } }
private void CreatePolyline(string filename) { try { using (StreamReader reader = new StreamReader(filename)) { int nIndex = 1; string line = reader.ReadLine(); if (line != null) { IPoint point; string str2; IGeometryCollection geometrys = new PolylineClass(); IPointCollection points = new PathClass(); object before = Missing.Value; bool flag = false; if (line.ToLower() == "part") { flag = true; } else { point = this.CreatePoint(line, nIndex); if (point == null) { str2 = string.Format("{0} 中第 {1}行数据有错误", filename, nIndex); Logger.Current.Error("", null, str2); } else { points.AddPoint(point, ref before, ref before); } } while ((line = reader.ReadLine()) != null) { line.Trim(); if (line.Length != 0) { nIndex++; if (line.ToLower() == "end") { break; } if (line.ToLower() == "part") { if (flag) { geometrys.AddGeometry(points as IGeometry, ref before, ref before); points = new PathClass(); } else { str2 = filename + " 中第 " + nIndex.ToString() + "行数据有错误"; Logger.Current.Error("", null, str2); } } else { point = this.CreatePoint(line, nIndex); if (point == null) { str2 = string.Concat(new object[] { filename, " 中第 ", nIndex, "行数据有错误" }); Logger.Current.Error("", null, str2); } else { points.AddPoint(point, ref before, ref before); } } } } if (points != null) { geometrys.AddGeometry(points as IGeometry, ref before, ref before); } try { IFeatureLayer featureLayer = Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer; this.SetZMProperty(geometrys as IGeometry); IFeature feature = featureLayer.FeatureClass.CreateFeature(); feature.Shape = geometrys as IGeometry; feature.Store(); IActiveView pMap = (IActiveView)this.m_pMap; this.m_pMap.ClearSelection(); this.m_pMap.SelectFeature(featureLayer, feature); pMap.Refresh(); } catch (Exception exception) { Logger.Current.Error("", exception, ""); } } } } catch (Exception exception2) { Logger.Current.Error("", exception2, ""); } }
private IFeatureBuffer method_9(ICoFeature icoFeature_0) { object before = Missing.Value; IFeatureBuffer buffer = null; if (this.bool_0) { buffer = this.ifeatureClass_0.CreateFeatureBuffer(); } else { buffer = this.ifeatureClass_0.CreateFeature() as IFeatureBuffer; } if (buffer != null) { buffer.Shape = null; } switch (icoFeature_0.Type) { case CoFeatureType.Point: if ((this.ifeatureClass_0.FeatureType != esriFeatureType.esriFTAnnotation) && (this.ifeatureClass_0.ShapeType == esriGeometryType.esriGeometryPoint)) { foreach (IPoint point in this.method_15((icoFeature_0 as ICoPointFeature).Point)) { buffer.Shape = point; } } break; case CoFeatureType.Polygon: if ((this.ifeatureClass_0.FeatureType != esriFeatureType.esriFTAnnotation) && (this.ifeatureClass_0.ShapeType == esriGeometryType.esriGeometryPolygon)) { IGeometryCollection geometrys2 = new PolygonClass(); foreach (CoPointCollection points in (icoFeature_0 as ICoPolygonFeature).Points) { IPointCollection points3 = new RingClass(); foreach (IPoint point2 in this.method_15(points)) { points3.AddPoint(point2, ref before, ref before); } geometrys2.AddGeometry((IGeometry)points3, ref before, ref before); } ((IPolygon)geometrys2).SimplifyPreserveFromTo(); buffer.Shape = (IGeometry)geometrys2; } break; case CoFeatureType.Annotation: if (this.ifeatureClass_0.FeatureType == esriFeatureType.esriFTAnnotation) { IAnnotationFeature feature = buffer as IAnnotationFeature; IPoint point = new PointClass(); ICoAnnotationFeature feature2 = icoFeature_0 as ICoAnnotationFeature; point.X = feature2.Point[0].X; point.Y = feature2.Point[0].Y; point.Z = feature2.Point[0].Z; ITextElement element = this.method_11(feature2.Text, 0.0, (decimal)feature2.Font.Size, feature2.Font.Name, feature2.Color.ToArgb(), point); feature.Annotation = (IElement)element; } break; case CoFeatureType.Polyline: if ((this.ifeatureClass_0.FeatureType != esriFeatureType.esriFTAnnotation) && (this.ifeatureClass_0.ShapeType == esriGeometryType.esriGeometryPolyline)) { IGeometryCollection geometrys = new PolylineClass(); foreach (CoPointCollection points in (icoFeature_0 as ICoPolylineFeature).Points) { IPoint[] pointArray = this.method_15(points); IPointCollection points2 = new PathClass(); for (int i = 0; i < pointArray.Length; i++) { points2.AddPoint(pointArray[i], ref before, ref before); } geometrys.AddGeometry((IGeometry)points2, ref before, ref before); } buffer.Shape = (IGeometry)geometrys; } break; } if (buffer != null) { if (buffer.Shape != null) { this.method_10(buffer, icoFeature_0); return(buffer); } return(null); } return(null); }
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) { } }
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) { } }
public static IGeometry GetExample13() { const double CircleDegrees = 360.0; const int CircleDivisions = 36; const double VectorComponentOffset = 0.0000001; const double CircleRadius = 3.0; const double BaseZ = 0.0; const double RotationAngleInDegrees = 89.9; //Extrusion: 3D Circle Polyline Extruded Along 3D Vector Via ConstructExtrudeRelative() IPointCollection pathPointCollection = new PathClass(); IGeometry pathGeometry = pathPointCollection as IGeometry; GeometryUtilities.MakeZAware(pathGeometry); IPoint originPoint = GeometryUtilities.ConstructPoint3D(0, 0, 0); IVector3D upperAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, 10); IVector3D lowerAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, -10); lowerAxisVector3D.XComponent += VectorComponentOffset; IVector3D normalVector3D = upperAxisVector3D.CrossProduct(lowerAxisVector3D) as IVector3D; normalVector3D.Magnitude = CircleRadius; double rotationAngleInRadians = GeometryUtilities.GetRadians(CircleDegrees / CircleDivisions); for (int i = 0; i < CircleDivisions; i++) { normalVector3D.Rotate(-1 * rotationAngleInRadians, upperAxisVector3D); IPoint vertexPoint = GeometryUtilities.ConstructPoint3D(originPoint.X + normalVector3D.XComponent, originPoint.Y + normalVector3D.YComponent, BaseZ); pathPointCollection.AddPoint(vertexPoint, ref _missing, ref _missing); } pathPointCollection.AddPoint(pathPointCollection.get_Point(0), ref _missing, ref _missing); //Rotate Geometry IVector3D rotationAxisVector3D = GeometryUtilities.ConstructVector3D(0, 10, 0); ITransform3D transform3D = pathGeometry as ITransform3D; transform3D.RotateVector3D(rotationAxisVector3D, GeometryUtilities.GetRadians(RotationAngleInDegrees)); //Construct Polyline From Path Vertices IGeometry polylineGeometry = new PolylineClass(); GeometryUtilities.MakeZAware(polylineGeometry); IPointCollection polylinePointCollection = polylineGeometry as IPointCollection; for (int i = 0; i < pathPointCollection.PointCount; i++) { polylinePointCollection.AddPoint(pathPointCollection.get_Point(i), ref _missing, ref _missing); } ITopologicalOperator topologicalOperator = polylineGeometry as ITopologicalOperator; topologicalOperator.Simplify(); //Define Vector To Extrude Along IVector3D extrusionVector3D = GeometryUtilities.ConstructVector3D(10, 0, 5); //Perform Extrusion IConstructMultiPatch constructMultiPatch = new MultiPatchClass(); constructMultiPatch.ConstructExtrudeRelative(extrusionVector3D, polylineGeometry); return(constructMultiPatch as IGeometry); }
public static IGeometry GetExample13() { const double CircleDegrees = 360.0; const int CircleDivisions = 36; const double VectorComponentOffset = 0.0000001; const double CircleRadius = 3.0; const double BaseZ = 0.0; const double RotationAngleInDegrees = 89.9; //Extrusion: 3D Circle Polyline Extruded Along 3D Vector Via ConstructExtrudeRelative() IPointCollection pathPointCollection = new PathClass(); IGeometry pathGeometry = pathPointCollection as IGeometry; GeometryUtilities.MakeZAware(pathGeometry); IPoint originPoint = GeometryUtilities.ConstructPoint3D(0, 0, 0); IVector3D upperAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, 10); IVector3D lowerAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, -10); lowerAxisVector3D.XComponent += VectorComponentOffset; IVector3D normalVector3D = upperAxisVector3D.CrossProduct(lowerAxisVector3D) as IVector3D; normalVector3D.Magnitude = CircleRadius; double rotationAngleInRadians = GeometryUtilities.GetRadians(CircleDegrees / CircleDivisions); for (int i = 0; i < CircleDivisions; i++) { normalVector3D.Rotate(-1 * rotationAngleInRadians, upperAxisVector3D); IPoint vertexPoint = GeometryUtilities.ConstructPoint3D(originPoint.X + normalVector3D.XComponent, originPoint.Y + normalVector3D.YComponent, BaseZ); pathPointCollection.AddPoint(vertexPoint, ref _missing, ref _missing); } pathPointCollection.AddPoint(pathPointCollection.get_Point(0), ref _missing, ref _missing); //Rotate Geometry IVector3D rotationAxisVector3D = GeometryUtilities.ConstructVector3D(0, 10, 0); ITransform3D transform3D = pathGeometry as ITransform3D; transform3D.RotateVector3D(rotationAxisVector3D, GeometryUtilities.GetRadians(RotationAngleInDegrees)); //Construct Polyline From Path Vertices IGeometry polylineGeometry = new PolylineClass(); GeometryUtilities.MakeZAware(polylineGeometry); IPointCollection polylinePointCollection = polylineGeometry as IPointCollection; for (int i = 0; i < pathPointCollection.PointCount; i++) { polylinePointCollection.AddPoint(pathPointCollection.get_Point(i), ref _missing, ref _missing); } ITopologicalOperator topologicalOperator = polylineGeometry as ITopologicalOperator; topologicalOperator.Simplify(); //Define Vector To Extrude Along IVector3D extrusionVector3D = GeometryUtilities.ConstructVector3D(10, 0, 5); //Perform Extrusion IConstructMultiPatch constructMultiPatch = new MultiPatchClass(); constructMultiPatch.ConstructExtrudeRelative(extrusionVector3D, polylineGeometry); return constructMultiPatch as IGeometry; }
/// <summary> /// 选中并定位到选中行中的所有要素 /// </summary> /// <param name="iColumnIndex"></param> /// <param name="iRowIndex"></param> private void ShowAllFeature(int iColumnIndex, int iRowIndex) { if (iRowIndex == -1) { return; } int iOID1 = Convert.ToInt32(DataGridErrs.Rows[iRowIndex].Cells["要素OID1"].Value); int iOID2 = Convert.ToInt32(DataGridErrs.Rows[iRowIndex].Cells["要素OID2"].Value); string strSLayer = DataGridErrs.Rows[iRowIndex].Cells["数据图层1"].Value.ToString(); string strTLayer = DataGridErrs.Rows[iRowIndex].Cells["数据图层2"].Value.ToString(); double d_mapx = -1; double d_mapy = -1; string errFeaGepStr = string.Empty; try { d_mapx = Convert.ToDouble(DataGridErrs.CurrentRow.Cells["定位点X"].FormattedValue.ToString()); d_mapy = Convert.ToDouble(DataGridErrs.CurrentRow.Cells["定位点Y"].FormattedValue.ToString()); } catch { d_mapx = 0; d_mapy = 0; } try { errFeaGepStr = DataGridErrs.CurrentRow.Cells["错误几何形状"].FormattedValue.ToString(); } catch { errFeaGepStr = string.Empty; } ILayer pSLayer = ModDBOperator.GetLayer(_MapControl as ESRI.ArcGIS.Controls.IMapControlDefault, strSLayer); ILayer pTLayer = ModDBOperator.GetLayer(_MapControl as ESRI.ArcGIS.Controls.IMapControlDefault, strTLayer); IFeature pSFeature = null; IFeature pTFeature = null; IList <IFeature> vFeaList = new List <IFeature>(); if (iOID1 != -1) { if (pSLayer != null && pSLayer is IFeatureLayer) { IFeatureClass pSFeatureClass = (pSLayer as IFeatureLayer).FeatureClass; if (pSFeatureClass == null) { return; } try { pSFeature = pSFeatureClass.GetFeature(iOID1); } catch { return; } } } if (iOID2 != -1) { if (pTLayer != null && pTLayer is IFeatureLayer) { IFeatureClass pTFeatureClass = (pTLayer as IFeatureLayer).FeatureClass; if (pTFeatureClass == null) { return; } try { pTFeature = pTFeatureClass.GetFeature(iOID2); } catch { } } } IGeometry pGeometry = null; _MapControl.Map.ClearSelection(); _MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, _MapControl.ActiveView.Extent); if (pTFeature == null) { if (pSFeature != null) { _MapControl.Map.SelectFeature(pSLayer, pSFeature); pGeometry = pSFeature.ShapeCopy; } } else { if (pSFeature.ShapeCopy.GeometryType == esriGeometryType.esriGeometryPoint && pTFeature.ShapeCopy.GeometryType == esriGeometryType.esriGeometryPoint) { object _missing = Type.Missing; IGeometryCollection geometryCollection = new PolylineClass(); IPointCollection pointCollection = new PathClass(); pointCollection.AddPoint(pSFeature.ShapeCopy as IPoint, ref _missing, ref _missing); pointCollection.AddPoint(pTFeature.ShapeCopy as IPoint, ref _missing, ref _missing); geometryCollection.AddGeometry(pointCollection as IGeometry, ref _missing, ref _missing); MakeZAware(geometryCollection as IGeometry); pGeometry = geometryCollection as IGeometry; pGeometry.Project(pSFeature.Shape.SpatialReference); } else { vFeaList.Add(pSFeature); vFeaList.Add(pTFeature); pGeometry = GetLyrUnionPlygon(vFeaList); } _MapControl.Map.SelectFeature(pTLayer, pTFeature); } _MapControl.Map.SelectFeature(pSLayer, pSFeature); ModDBOperator.ZoomToFeature(_MapControl.Map, pGeometry); ShowErrorGeo(d_mapx, d_mapy, errFeaGepStr); _MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, _MapControl.ActiveView.Extent); //ShowErrState(); }