/// <summary> /// 更新圆心 /// </summary> /// <param name="centerDot"></param> public void UpdatePosition(MapLngLat centerDot) { centerPoint = new PointClass() { X = centerDot.Lng, Y = centerDot.Lat }; centerPoint.Z = centerDot.Alt; IZAware zAware = (IGeometry)centerPoint as IZAware; zAware.ZAware = true; upperAxisVector3D = new Vector3DClass(); upperAxisVector3D.SetComponents(0, 0, 10); lowerAxisVector3D = new Vector3DClass(); lowerAxisVector3D.SetComponents(0, 0, -10); lowerAxisVector3D.XComponent -= vectorComponentOffset; normalVector3D = upperAxisVector3D.CrossProduct(lowerAxisVector3D) as IVector3D; normalVector3D.Magnitude = this.radius; double rotationAngleInRadians = 2 * (Math.PI / 180); pointCollection.RemovePoints(0, pointCollection.PointCount); for (int i = 0; i < 180; i++) { normalVector3D.Rotate(-1 * rotationAngleInRadians, upperAxisVector3D); IPoint vertexPoint = new PointClass(); vertexPoint.X = centerPoint.X + normalVector3D.XComponent; vertexPoint.Y = centerPoint.Y + normalVector3D.YComponent; vertexPoint.Z = centerPoint.Z; pointCollection.AddPoint(vertexPoint, missing, missing); //if (i == 0) pointCollection.AddPoint(vertexPoint, missing, missing); } base.Geometry = pointCollection as IGeometry; this.Update(); }
/// <summary> /// 更新多边形的某一点坐标 /// </summary> /// <param name="oldLngLat">老坐标</param> /// <param name="newLngLat">新坐标</param> /// <returns></returns> public bool UpdatePosition(Core.Model.MapLngLat oldLngLat, Core.Model.MapLngLat newLngLat) { Dosomething((Action)(delegate { IPoint oldPoint = new PointClass() { X = oldLngLat.Lng, Y = oldLngLat.Lat }; IPoint newPoint = new PointClass() { X = newLngLat.Lng, Y = newLngLat.Lat }; for (int i = 0; i < pointCollection.PointCount; i++) { if (pointCollection.get_Point(i).Compare(oldPoint) == 0) { pointCollection.RemovePoints(i, 1); pointCollection.AddPoint(newPoint); //坐标点集合 pointList.Remove(oldLngLat); pointList.Add(newLngLat); break; } } base.Geometry = (IGeometry)pointCollection; }), true); Update(); return(true); }
private void RecreateLineGeometry(IElement elem, IAGAnimationTrack pTrack, IAGKeyframe pKeyframe, IPoint new_pos) { IGeometry newGeometry = new PolylineClass(); IPointCollection newPointCol = (IPointCollection)newGeometry; IAGAnimationTrackKeyframes trackKeyframes = (IAGAnimationTrackKeyframes)pTrack; int tCount = trackKeyframes.KeyframeCount; object missing = Type.Missing; for (int i = 0; i < tCount; i++) { IAGKeyframe tempKeyframe = trackKeyframes.get_Keyframe(i); newPointCol.AddPoint((IPoint)tempKeyframe.get_PropertyValue(0), ref missing, ref missing); if ((IPoint)tempKeyframe.get_PropertyValue(0) == (IPoint)pKeyframe.get_PropertyValue(0)) { break; } } if (new_pos != null) { newPointCol.AddPoint(new_pos, ref missing, ref missing); } elem.Geometry = newGeometry; }
private void createFeatureClass() { string ftClsPath = rsUtil.TempMosaicDir + "\\catBnd.shp"; IFields flds = new FieldsClass(); IFieldsEdit fldsE = (IFieldsEdit)flds; IField fld = new FieldClass(); IFieldEdit fldE = (IFieldEdit)fld; fldE.Name_2 = "catIndex"; fldE.Type_2 = esriFieldType.esriFieldTypeSmallInteger; fldsE.AddField(fldE); ftCls = geoUtil.createFeatureClass(ftClsPath, fldsE, esriGeometryType.esriGeometryPolygon, sr); int catInd = ftCls.FindField("catIndex"); int cnt = 0; foreach (IRaster rs in inrs) { IFeature ftr = ftCls.CreateFeature(); ftr.set_Value(catInd, cnt); IEnvelope ext = ((IRasterProps)rs).Extent; IPolygon poly = new PolygonClass(); IPointCollection pColl = (IPointCollection)poly; pColl.AddPoint(ext.UpperLeft); pColl.AddPoint(ext.UpperRight); pColl.AddPoint(ext.LowerRight); pColl.AddPoint(ext.LowerLeft); poly.Close(); ftr.Shape = poly; ftr.Store(); cnt++; } }
private IElement method_1() { object missing = System.Type.Missing; IPointCollection points = null; IElement element = new PolygonElementClass(); IFillShapeElement element2 = element as IFillShapeElement; new RgbColorClass(); IGeometry inGeometry = new RingClass(); IGeometry geometry2 = null; IGeometryCollection geometrys = new PolygonClass(); IGeometry geometry3 = null; points = (IPointCollection)inGeometry; points.AddPoint(base.LeftLow, ref missing, ref missing); points.AddPoint(base.RightLow, ref missing, ref missing); points.AddPoint(base.RightUp, ref missing, ref missing); points.AddPoint(base.LeftUp, ref missing, ref missing); points.AddPoint(base.LeftLow, ref missing, ref missing); geometry2 = this.method_2(); if (!geometry2.IsEmpty) { geometrys.AddGeometry(inGeometry, ref missing, ref missing); geometrys.AddGeometry(geometry2, ref missing, ref missing); } geometry3 = geometrys as IGeometry; if (!geometry3.IsEmpty) { geometry3.SpatialReference = geometry2.SpatialReference; element.Geometry = geometry3; element2.Symbol = this.method_7(); } return(element); }
//GradientFillSymbol private void button15_Click(object sender, EventArgs e) { IGradientFillSymbol gradientFillSymbol = new GradientFillSymbolClass(); IAlgorithmicColorRamp algorithcColorRamp = new AlgorithmicColorRampClass(); algorithcColorRamp.FromColor = getRGB(255, 0, 0); algorithcColorRamp.ToColor = getRGB(0, 255, 0); algorithcColorRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; gradientFillSymbol.ColorRamp = algorithcColorRamp; gradientFillSymbol.GradientAngle = 45; gradientFillSymbol.GradientPercentage = 0.9; gradientFillSymbol.Style = esriGradientFillStyle.esriGFSLinear; object Missing = Type.Missing; IPolygon polygon = new PolygonClass(); IPointCollection pointCollection = polygon as IPointCollection; IPoint point = new PointClass(); point.PutCoords(5, 5); pointCollection.AddPoint(point, ref Missing, ref Missing); point.PutCoords(5, 10); pointCollection.AddPoint(point, ref Missing, ref Missing); point.PutCoords(10, 10); pointCollection.AddPoint(point, ref Missing, ref Missing); point.PutCoords(10, 5); pointCollection.AddPoint(point, ref Missing, ref Missing); polygon.SimplifyPreserveFromTo(); IActiveView activeView = this.axMapControl1.ActiveView; activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache); activeView.ScreenDisplay.SetSymbol(gradientFillSymbol as ISymbol); activeView.ScreenDisplay.DrawPolygon(polygon as IGeometry); activeView.ScreenDisplay.FinishDrawing(); }
/// <summary> /// 更新线位置 /// </summary> /// <param name="pList"></param> /// <returns></returns> public bool UpdatePosition(List <Core.Model.MapLngLat> pList) { if (mapControl.InvokeRequired) { mapControl.Invoke((Action) delegate() { IPoint p = new PointClass(); pointCollection.RemovePoints(0, pointCollection.PointCount); for (int i = 0; i < pList.Count; i++) { p.PutCoords(pList[i].Lng, pList[i].Lat); pointCollection.AddPoint(p); } base.Geometry = pointCollection as IGeometry; }); } else { IPoint p = new PointClass(); pointCollection.RemovePoints(0, pointCollection.PointCount); for (int i = 0; i < pList.Count; i++) { p.PutCoords(pList[i].Lng, pList[i].Lat); pointCollection.AddPoint(p); } base.Geometry = pointCollection as IGeometry; } Update(); pointList = pList;//更新坐标集合 return(true); }
private IPolygon method_3() { IGeometryCollection geometrys = new PolygonClass(); IRing inGeometry = new RingClass(); IRing ring2 = new RingClass(); IPointCollection points = null; IPointCollection points2 = null; object missing = System.Type.Missing; IPoint inPoint = new PointClass(); IPoint point2 = new PointClass(); IPoint point3 = new PointClass(); IPoint point4 = new PointClass(); points = inGeometry as IPointCollection; points.AddPoint(base.LeftUp, ref missing, ref missing); points.AddPoint(base.RightUp, ref missing, ref missing); points.AddPoint(base.RightLow, ref missing, ref missing); points.AddPoint(base.LeftLow, ref missing, ref missing); inGeometry.Close(); geometrys.AddGeometry(inGeometry, ref missing, ref missing); inPoint.PutCoords(base.LeftUp.X - base.InOutDist, base.LeftUp.Y + base.InOutDist); point4.PutCoords(base.LeftLow.X - base.InOutDist, base.LeftLow.Y - base.InOutDist); point3.PutCoords(base.RightLow.X + base.InOutDist, base.RightLow.Y - base.InOutDist); point2.PutCoords(base.RightUp.X + base.InOutDist, base.RightUp.Y + base.InOutDist); points2 = ring2 as IPointCollection; points2.AddPoint(inPoint, ref missing, ref missing); points2.AddPoint(point2, ref missing, ref missing); points2.AddPoint(point3, ref missing, ref missing); points2.AddPoint(point4, ref missing, ref missing); ring2.Close(); geometrys.AddGeometry(ring2, ref missing, ref missing); return(geometrys as IPolygon); }
private void QueryBoundsFromGeom(int hDC, ref IDisplayTransformation transform, ref IPolygon boundary, ref IPoint point) { IPointCollection pointCollection = null; pointCollection = (IPointCollection)boundary; try { IPolygon polygonClass = new Polygon() as IPolygon; (this.m_NumeratorTextSymbol as ISymbol).QueryBoundary(hDC, transform, point, polygonClass); IEnvelope envelope = polygonClass.Envelope; IPolygon polygon = new Polygon() as IPolygon; (this.m_DenominatorTextSymbol as ISymbol).QueryBoundary(hDC, transform, point, polygon); envelope.Union(polygon.Envelope); envelope.Expand(4, 0, false); object value = Missing.Value; object obj = Missing.Value; pointCollection.AddPoint(envelope.LowerLeft, ref value, ref value); pointCollection.AddPoint(envelope.LowerRight, ref value, ref value); pointCollection.AddPoint(envelope.UpperRight, ref value, ref value); pointCollection.AddPoint(envelope.UpperLeft, ref value, ref value); pointCollection.AddPoint(envelope.LowerLeft, ref value, ref value); ITransform2D transform2D = null; if (this.m_Angle + this.m_dMapRotation != 0) { transform2D = boundary as ITransform2D; transform2D.Rotate(point, Utility.Radians(this.m_Angle + this.m_dMapRotation)); } } catch (Exception exception) { exception.ToString(); } }
IPoint IntersectPointExtendedTo(IPolyline pPolyline, IPolygon pCirclePoly) { ICurve pCurve; ILine pLine; IPolyline pPLine; ITopologicalOperator pTopoOpt; IGeometryCollection pGeoCol; pCurve = pPolyline; pLine = new Line(); double gridWidth = _mapTemplate.Width * _scale / 100.0; pCurve.QueryTangent(esriSegmentExtension.esriExtendTangentAtTo, 1, true, gridWidth * 1.1, pLine); pPLine = new Polyline() as IPolyline; IPointCollection pPnts = pPLine as IPointCollection; IClone pClone = pLine.FromPoint as IClone; pPnts.AddPoint(pClone.Clone() as IPoint); pClone = pLine.ToPoint as IClone; pPnts.AddPoint(pClone.Clone() as IPoint); pTopoOpt = pPLine as ITopologicalOperator; pGeoCol = new GeometryBag() as IGeometryCollection; pGeoCol = pTopoOpt.Intersect(pCirclePoly, esriGeometryDimension.esriGeometry0Dimension) as IGeometryCollection; if (pGeoCol.GeometryCount == 0) { return(null); } return(pGeoCol.Geometry[0] as IPoint); }
private void DrawLineOnActiveView(List <int> lstIndices, double[][] arrValue, IActiveView pActiveView) { try { int intLstCnt = lstIndices.Count; IGraphicsContainer pGraphicContainer = pActiveView.GraphicsContainer; pGraphicContainer.DeleteAllElements(); IRgbColor pRgbColor = m_pSnippet.getRGB(0, 255, 255); //IRgbColor pRgbColor = new RgbColorClass(); //pRgbColor.Red = 0; //pRgbColor.Green = 255; //pRgbColor.Blue = 255; //pRgbColor.Transparency = 255; ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Width = 2; pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; pSimpleLineSymbol.Color = pRgbColor; for (int i = 0; i < intLstCnt; i++) { int intIdx = lstIndices[i]; double[] arrSelValue = arrValue[intIdx]; //drawing a polyline IPoint FromP = new PointClass(); FromP.X = arrSelValue[0]; FromP.Y = arrSelValue[1]; IPoint ToP = new PointClass(); ToP.X = arrSelValue[2]; ToP.Y = arrSelValue[3]; IPolyline polyline = new PolylineClass(); IPointCollection pointColl = polyline as IPointCollection; pointColl.AddPoint(FromP); pointColl.AddPoint(ToP); IElement pElement = new LineElementClass(); ILineElement pLineElement = (ILineElement)pElement; pLineElement.Symbol = pSimpleLineSymbol; pElement.Geometry = polyline; pGraphicContainer.AddElement(pElement, 0); } pActiveView.Refresh(); } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
//MultilayerFillSymbol private void button17_Click(object sender, EventArgs e) { IMultiLayerFillSymbol multiLayerFillSymbol = new MultiLayerFillSymbolClass(); IGradientFillSymbol gradientFillSymbol = new GradientFillSymbolClass(); IAlgorithmicColorRamp algorithcColorRamp = new AlgorithmicColorRampClass(); algorithcColorRamp.FromColor = getRGB(255, 0, 0); algorithcColorRamp.ToColor = getRGB(0, 255, 0); algorithcColorRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; gradientFillSymbol.ColorRamp = algorithcColorRamp; gradientFillSymbol.GradientAngle = 45; gradientFillSymbol.GradientPercentage = 0.9; gradientFillSymbol.Style = esriGradientFillStyle.esriGFSLinear; ICartographicLineSymbol cartoLine = new CartographicLineSymbol(); cartoLine.Cap = esriLineCapStyle.esriLCSButt; cartoLine.Join = esriLineJoinStyle.esriLJSMitre; cartoLine.Color = getRGB(255, 0, 0); cartoLine.Width = 2; //Create the LineFillSymbo ILineFillSymbol lineFill = new LineFillSymbol(); lineFill.Angle = 45; lineFill.Separation = 10; lineFill.Offset = 5; lineFill.LineSymbol = cartoLine; multiLayerFillSymbol.AddLayer(gradientFillSymbol); multiLayerFillSymbol.AddLayer(lineFill); object Missing = Type.Missing; IPolygon polygon = new PolygonClass(); IPointCollection pointCollection = polygon as IPointCollection; IPoint point = new PointClass(); point.PutCoords(5, 5); pointCollection.AddPoint(point, ref Missing, ref Missing); point.PutCoords(5, 10); pointCollection.AddPoint(point, ref Missing, ref Missing); point.PutCoords(10, 10); pointCollection.AddPoint(point, ref Missing, ref Missing); point.PutCoords(10, 5); pointCollection.AddPoint(point, ref Missing, ref Missing); polygon.SimplifyPreserveFromTo(); IActiveView activeView = this.axMapControl1.ActiveView; activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache); activeView.ScreenDisplay.SetSymbol(multiLayerFillSymbol as ISymbol); activeView.ScreenDisplay.DrawPolygon(polygon as IGeometry); activeView.ScreenDisplay.FinishDrawing(); }
public static IPolyline create_line(IPoint point1, IPoint point2) { IPolyline polyline = new Polyline() as IPolyline; IPointCollection pt_cl = polyline as IPointCollection; object o = Type.Missing; pt_cl.AddPoint(point1, ref o, ref o); pt_cl.AddPoint(point2, ref o, ref o); polyline = pt_cl as IPolyline; return(polyline); }
private void QueryBoundsFromGeom(int hDC, ref IDisplayTransformation transform, ref IPolygon boundary, ref IPointCollection points) { double map = 0; double num = 0; double map1 = 0; num = this.PointsToMap(transform, this.m_dSize); if (this.m_dXOffset != 0) { map = this.PointsToMap(transform, this.m_dXOffset); } if (this.m_dYOffset != 0) { map1 = this.PointsToMap(transform, this.m_dYOffset); } this.SetupDeviceRatio(hDC, transform); IPointCollection pointCollection = null; ISegmentCollection segmentCollection = null; double num1 = 0; double num2 = 0; pointCollection = (IPointCollection)boundary; segmentCollection = (ISegmentCollection)boundary; num2 = num / 2; num1 = Math.Sqrt(num2 * num2 / 2); object value = Missing.Value; IEnvelope envelope = (points as IGeometry).Envelope; double num3 = 100; double num4 = 200; double num5 = -100; double num6 = 400; this.QueryBound(points, transform, out num3, out num4, out num5, out num6); IPoint pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(num3, num4); pointCollection.AddPoint(pointClass, ref value, ref value); pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(num5, num4); pointCollection.AddPoint(pointClass, ref value, ref value); pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(num5, num6); pointCollection.AddPoint(pointClass, ref value, ref value); pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(num3, num6); pointCollection.AddPoint(pointClass, ref value, ref value); pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(num3, num4); pointCollection.AddPoint(pointClass, ref value, ref value); }
private static IGeometry CreateTurnGeometry(IPoint ptStart, IPoint ptVia, IPoint ptEnd, ISpatialReference sr) { IPolyline lineTurn = new PolylineClass(); lineTurn.SpatialReference = sr; IPointCollection pcTurn = lineTurn as IPointCollection; pcTurn.AddPoint(ptStart); pcTurn.AddPoint(ptVia); pcTurn.AddPoint(ptEnd); return((IGeometry)lineTurn); }
private void BuildTriangleGeometry(IPoint pointGeometry) { try { if (null == m_triangle || null == pointGeometry || null == m_cachedDisplay) { return; } m_triangle.SpatialReference = pointGeometry.SpatialReference; m_triangle.SetEmpty(); object missing = System.Reflection.Missing.Value; IPointCollection pointCollection = (IPointCollection)m_triangle; double radius = PointsToMap(m_cachedDisplay.DisplayTransformation, m_size); double X = pointGeometry.X; double Y = pointGeometry.Y; IPoint point = new PointClass(); point.X = X + radius * c_Cosine30; point.Y = Y - 0.5 * radius; pointCollection.AddPoint(point, ref missing, ref missing); point = new PointClass(); point.X = X; point.Y = Y + radius; pointCollection.AddPoint(point, ref missing, ref missing); point = new PointClass(); point.X = X - radius * c_Cosine30; point.Y = Y - 0.5 * radius; pointCollection.AddPoint(point, ref missing, ref missing); m_triangle.Close(); if (m_rotation != 0.0) { ((ITransform2D)pointCollection).Rotate(pointGeometry, m_rotation * c_Deg2Rad); } return; } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } }
/// <summary> /// </summary> /// <param name="Display"></param> /// <param name="Outline"></param> public void QueryOutline(IDisplay Display, IPolygon Outline) { if (this.m_resetGeometry) { int mPCachedDisplay = this.m_pCachedDisplay.hDC; Graphics graphic = null; IntPtr hdc = (IntPtr)0; if (mPCachedDisplay == 0) { graphic = Graphics.FromHwnd(new IntPtr((this.m_pCachedDisplay as IScreenDisplay).hWnd)); hdc = graphic.GetHdc(); mPCachedDisplay = hdc.ToInt32(); } IPoint pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords((this.m_pGeometry.XMin + this.m_pGeometry.XMax) / 2, (this.m_pGeometry.YMax + this.m_pGeometry.YMin) / 2); (this.m_NumeratorTextSymbol as ISymbol).QueryBoundary(mPCachedDisplay, this.m_pCachedDisplay.DisplayTransformation, pointClass, Outline); double width = Outline.Envelope.Width; double height = Outline.Envelope.Height; (this.m_DenominatorTextSymbol as ISymbol).QueryBoundary(mPCachedDisplay, this.m_pCachedDisplay.DisplayTransformation, pointClass, Outline); double num = Outline.Envelope.Width; double height1 = Outline.Envelope.Height; if (graphic != null) { graphic.ReleaseHdc(hdc); } double num1 = (width > num ? width : num) * 1.1; double num2 = (height + height1) * 1.1; this.m_pGeometry = new Envelope() as IEnvelope; this.m_pGeometry.PutCoords(pointClass.X - num1 / 2, pointClass.X + num1 / 2, pointClass.Y - num2 / 2, pointClass.Y + num2 / 2); this.m_pGeometry.CenterAt(pointClass); this.m_resetGeometry = false; } IDisplayTransformation displayTransformation = this.m_pCachedDisplay.DisplayTransformation; Outline.SetEmpty(); object value = Missing.Value; IPointCollection outline = Outline as IPointCollection; outline.AddPoint(this.m_pGeometry.LowerLeft, ref value, ref value); outline.AddPoint(this.m_pGeometry.LowerRight, ref value, ref value); outline.AddPoint(this.m_pGeometry.UpperRight, ref value, ref value); outline.AddPoint(this.m_pGeometry.UpperLeft, ref value, ref value); outline.AddPoint(this.m_pGeometry.LowerLeft, ref value, ref value); }
private void BuildTriangleGeometry(IPoint pointGeometry) { try { if ((this.m_triangle == null || pointGeometry == null ? false : null != this.m_cachedDisplay)) { this.m_triangle.SpatialReference = pointGeometry.SpatialReference; this.m_triangle.SetEmpty(); object value = Missing.Value; IPointCollection mTriangle = (IPointCollection)this.m_triangle; double map = this.PointsToMap(this.m_cachedDisplay.DisplayTransformation, this.m_size); double x = pointGeometry.X; double y = pointGeometry.Y; IPoint pointClass = new ESRI.ArcGIS.Geometry.Point() { X = x + map * 0.866025403784439, Y = y - 0.5 * map }; mTriangle.AddPoint(pointClass, ref value, ref value); pointClass = new ESRI.ArcGIS.Geometry.Point() { X = x, Y = y + map }; mTriangle.AddPoint(pointClass, ref value, ref value); pointClass = new ESRI.ArcGIS.Geometry.Point() { X = x - map * 0.866025403784439, Y = y - 0.5 * map }; mTriangle.AddPoint(pointClass, ref value, ref value); this.m_triangle.Close(); if (this.m_rotation != 0) { ((ITransform2D)mTriangle).Rotate(pointGeometry, this.m_rotation * 0.0174532925199433); } return; } else { return; } } catch (Exception exception) { Trace.WriteLine(exception.Message); } }
/// <summary> /// 更新位置 /// </summary> /// <param name="pList">点集合</param> /// <returns></returns> public bool UpdatePosition(List <MapLngLat> pList) { IPointCollection pointCollection = base.Geometry as IPointCollection; if (pointCollection == null) { return(false); } this.Dosomething((Action) delegate() { pointCollection.RemovePoints(0, pointCollection.PointCount);//清除集合内所有坐标点 IPoint p = new PointClass(); foreach (var item in pList) { p.PutCoords(item.Lng, item.Lat); p.Z = item.Alt; pointCollection.AddPoint(p); } if (this.Rasterize) //判断图元是否为栅格化 { this.Rasterize = false; base.Geometry = pointCollection as IGeometry; this.Rasterize = true; } else { base.Geometry = pointCollection as IGeometry; } Update(); }, true); return(true); }
private static void ReadPointCollection(BinaryReader reader, WkbByteOrder byteOrder, IPointCollection pColl, bool hasZ, bool hasM) { if (pColl == null) { return; } // Get the number of points in this linestring. int numPoints = (int)ReadUInt32(reader, byteOrder); // Loop on the number of points in the ring. for (int i = 0; i < numPoints; i++) { // Add the coordinate. Point p = new Point(ReadDouble(reader, byteOrder), ReadDouble(reader, byteOrder)); pColl.AddPoint(p); if (hasZ == true && hasM == true) { p.Z = ReadDouble(reader, byteOrder); p.M = ReadDouble(reader, byteOrder); } else if (hasM == true) { p.M = ReadDouble(reader, byteOrder); } else if (hasZ == true) { p.Z = ReadDouble(reader, byteOrder); } } }
public void ClosePart() { if (Part != null && Part.PointCount > 2) { Part.AddPoint(Part[0]); } }
public void ShowNavi() { IGraphicsContainer pGraphicsContainer = axMapControl1.Map as IGraphicsContainer; IActiveView pActiveView = axMapControl1.Map as IActiveView; // 得到“城市”图层 IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(0) as IFeatureLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; int indexFlield = pFeatureClass.Fields.FindField("PointName"); IPolyline pPolyline = new PolylineClass(); IPointCollection pPointCollection = pPolyline as IPointCollection; IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField("PointName"); foreach (string staString in opPath) { pQueryFilter.WhereClause = "PointName='" + staString + "'"; IFeatureCursor pCursor = pFeatureClass.Search(pQueryFilter, true); IFeature pFeature = pCursor.NextFeature(); System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor); GC.Collect(); GC.WaitForPendingFinalizers(); if (pFeature != null) { ESRI.ArcGIS.Geometry.Point pPoint = pFeature.Shape as ESRI.ArcGIS.Geometry.Point; pPointCollection.AddPoint(pPoint); } } object pSym = null; IRgbColor pColor; pColor = new RgbColorClass(); pColor.Red = 0; pColor.Blue = 255; pColor.Green = 0; pSym = new SimpleLineSymbolClass(); ISimpleLineSymbol pSym1 = pSym as ISimpleLineSymbol; pSym1.Width = 6; pSym1.Style = esriSimpleLineStyle.esriSLSDash; pSym1.Color = pColor; ILineElement pLienElement = new LineElementClass(); pLienElement.Symbol = pSym1; IElement pElement = pLienElement as IElement; pElement.Geometry = pPolyline as IGeometry; pGraphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private IGeometry GetGeometry(IGeometry baseGeometry) { IGeometry geometry; IPolyline polyline = new PolylineClass(); polyline.SpatialReference = baseGeometry.SpatialReference; geometry = polyline as IGeometry; IPointCollection targetPointCollection = geometry as IPointCollection; IPointCollection basePointCollection = baseGeometry as IPointCollection; object missing = Type.Missing; for (int i = 0; i < basePointCollection.PointCount; i++) { targetPointCollection.AddPoint(basePointCollection.get_Point(i), ref missing, ref missing); } MakeZAware(geometry); return(geometry); }
private IPolyline ConvertFrom(GeoAPI.Geometries.IMultiLineString lines) { if (lines == null) { return(null); } IPolyline polyline = new PolylineClass(); IGeometryCollection paths = lines as IGeometryCollection; foreach (GeoAPI.Geometries.ILineString line in lines.Geometries) { IPath path = new PathClass(); IPointCollection pointCollection = path as IPointCollection; object Missing = Type.Missing; IPoint point = new PointClass(); foreach (GeoAPI.Geometries.ICoordinate coordinate in line.Coordinates) { point.X = coordinate.X; point.Y = coordinate.Y; point.Z = coordinate.Z; pointCollection.AddPoint(point, ref Missing, ref Missing); } paths.AddGeometry(path, ref Missing, ref Missing); } return(polyline); }
//添加控制点 private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { if (IsAddingPoint && e.button == 1) { if (!AddingToPoint) { IPoint fromP = new PointClass(); fromP.PutCoords(e.mapX, e.mapY); fromPoint.AddPoint(fromP); DrawPoints(); AddingToPoint = true; ApplyButton.Enabled = false; } else { IPoint toP = new PointClass(); toP.PutCoords(e.mapX, e.mapY); toPoint.AddPoint(toP); DrawPoints(); AddingToPoint = false; ApplyButton.Enabled = true; AddPoint(); } } if (e.button == 4) { axMapControl1.Pan(); } }
//---------------------------------------------------------------------------------- public static IPolyline MaakPolyline() { //Declaraties en initialisaties IPolyline pPolyline = new PolylineClass(); IGeometryCollection pGCol = (IGeometryCollection)pPolyline; IZAware pZAware = (IZAware)pPolyline; pZAware.ZAware = ImportInArcscene.ZBoolean; int aantalpaths = ImportInArcscene.binReader.ReadInt32(); for (int i = 1; i <= aantalpaths; i++) { IPath pPath = new PathClass(); IPointCollection pPointCol = (IPointCollection)pPath; int aantalvertices = ImportInArcscene.binReader.ReadInt32(); for (int k = 1; k <= aantalvertices; k++) { double ptx = ImportInArcscene.binReader.ReadSingle(); double pty = ImportInArcscene.binReader.ReadSingle(); double ptz = ImportInArcscene.binReader.ReadSingle(); pPointCol.AddPoint(PuntTransformatie(ptx, pty, ptz), ref _missing, ref _missing); } pGCol.AddGeometry(pPath, ref _missing, ref _missing); } return(pPolyline); }
/// <summary> /// 更新线的位置 /// </summary> /// <param name="pList">经纬度列表</param> /// <returns></returns> public bool UpdatePosition(List <MapLngLat> pList) { IPointCollection pointCollection = base.Geometry as IPointCollection; if (pointCollection != null) { pointCollection.RemovePoints(0, pointCollection.PointCount); // 清空之前的点,再添加新点 for (int i = 0; i < pList.Count; i++) { IPoint point = new PointClass(); point.PutCoords(pList[i].Lng, pList[i].Lat); point.Z = pList[i].Alt; (point as IZAware).ZAware = true; pointCollection.AddPoint(point); } Dosomething((Action) delegate() { int outIndex = -1; graphcisLayer.FindElementIndex(this, out outIndex); if (outIndex > 0) { base.Geometry = pointCollection as IGeometry; graphcisLayer.UpdateElementByIndex(outIndex); } }, true); return(true); } return(false); }
private IPolygon GetRegionPolygon(string fileName) { try { object Missing = Type.Missing; double dblX, dblY; string strXY; IPoint p; IPolygon pPlyRegion = new PolygonClass(); IPointCollection pPointCol = pPlyRegion as IPointCollection; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); sr = new StreamReader(fs, Encoding.Default); this.Read(); for (int i = 0; i < m_arrVertex.Count; i++) { strXY = m_arrVertex[i].ToString(); dblX = double.Parse(strXY.Split(new char[] { ',' })[0]); dblY = double.Parse(strXY.Split(new char[] { ',' })[1]); p = new PointClass(); p.PutCoords(dblX, dblY); pPointCol.AddPoint(p, ref Missing, ref Missing); } m_arrVertex.Clear(); return(pPlyRegion); } catch (System.Exception ex) { return(null); } }
/// <summary> /// 更新位置 /// </summary> /// <param name="oldLngLat">原来的位置</param> /// <param name="newLngLat">新的位置</param> /// <returns></returns> public bool UpdatePosition(MapLngLat oldLngLat, MapLngLat newLngLat) { this.Dosomething((Action) delegate() { IPoint newPoint = new PointClass(); newPoint.PutCoords(newLngLat.Lng, newLngLat.Lat); newPoint.Z = newLngLat.Alt; IPoint oldPoint = new PointClass() { X = oldLngLat.Lng, Y = oldLngLat.Lat, Z = oldLngLat.Alt }; IPointCollection pointCollection = base.Geometry as IPointCollection; for (int i = 0; i < pointCollection.PointCount; i++) { if (pointCollection.get_Point(i).Compare(oldPoint) == 0) { pointCollection.RemovePoints(i, 1); pointCollection.AddPoint(newPoint); break; } } base.Geometry = pointCollection as IGeometry; Update(); }, true); return(true); }
/// <summary> /// 单机时运行 /// </summary> /// <param name="clickPT">单机的地图点</param> public void OnMouseDownRun(IPoint clickPT) { if (polygonFeedback == null) { polygonFeedback = new NewPolygonFeedbackClass(); polygonFeedback.Display = (mapControl.Map as IActiveView).ScreenDisplay; pointCollection.RemovePoints(0, pointCollection.PointCount); polygonFeedback.Start(clickPT); pointCollection.AddPoint(clickPT, Type.Missing, Type.Missing); } else { polygonFeedback.AddPoint(clickPT); pointCollection.AddPoint(clickPT, Type.Missing, Type.Missing); } }
/// <summary> /// ��ȡ�ַ�ͼ����ָ��Ŀ��ͼ��ķ�Χ��С������ͼ�����ֶε�ֵ /// </summary> /// <param name="ipFeatrueClass">�ӱ�Ҫ����</param> /// <param name="ipBoundFeatureClass">��ΧҪ����</param> /// <param name="strTuFuNumFieldName">ͼ�����ֶ���</param> /// <param name="ipEnvelope"></param> /// <param name="nTuFuFieldIndex"></param> /// <param name="aryNumber">ͼ��������</param> /// <param name="ipPointCollection"></param> /// <returns>�ɹ�����true,����false</returns> private IEnvelope GetCutlineNumber(IFeatureClass ipFeatrueClass, IFeatureClass ipBoundFeatureClass, string strTuFuNumFieldName, IEnvelope ipEnvelope, ref int nTuFuFieldIndex, ref List<string> aryNumber, IPointCollection ipPointCollection) { try { if (ipEnvelope == null) return null; // //���Դ��� // BSTR bstrTuFuNum = strTuFuNumFieldName.AllocSysString(); //ipTable.FindField(bstrTuFuNum,&nIndex); //���ͼ�����ֶε����� ITable ipTable = (ITable) ipBoundFeatureClass; int nIndex = ipTable.FindField(strTuFuNumFieldName); if (nIndex == -1) { return null; } IEnvelope ipTuFuMaxEnvelope = new EnvelopeClass(); nTuFuFieldIndex = nIndex; //���ÿռ����� ISpatialFilter ipSpatialFilter = new SpatialFilterClass(); ipSpatialFilter.AddField(strTuFuNumFieldName); IGeometry ipGeo = ipEnvelope; ipSpatialFilter.Geometry = ipGeo; string bstrSharpFieldName = ipBoundFeatureClass.ShapeFieldName; ipSpatialFilter.GeometryField = bstrSharpFieldName; ipSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; //���пռ��ѯ,����ȡ��ͼ�����ֶε�ֵ IFeatureCursor ipFeatureCursor = ipBoundFeatureClass.Search(ipSpatialFilter, false); if (ipFeatureCursor == null) { return null; } IGeometry ipGeometry; IGeometry ipPolygonGeometry; IPolygon2 ipPolygon; IRing ipRing; IFeature ipFeature = ipFeatureCursor.NextFeature(); IEnvelope ipTuFuEnvelope = ipFeature.Extent; double dMinX = 0.0; double dMaxX = 0.0; double dMinY = 0.0; double dMaxY = 0.0; double dTMinX = 0.0; double dTMaxX = 0.0; double dTMinY = 0.0; double dTMaxY = 0.0; dMinX = ipTuFuEnvelope.XMin; dMaxX = ipTuFuEnvelope.XMax; dMinY = ipTuFuEnvelope.YMin; dMaxY = ipTuFuEnvelope.YMax; IPoint ipPoint = new PointClass(); int nPointCount = 0; while (ipFeature != null) { object varTuFu = ipFeature.get_Value(nIndex); string str = varTuFu.ToString(); aryNumber.Add(str); ipTuFuEnvelope = ipFeature.Extent; dTMinX = ipTuFuEnvelope.XMin; dTMaxX = ipTuFuEnvelope.XMax; dTMinY = ipTuFuEnvelope.YMin; dTMaxY = ipTuFuEnvelope.YMax; if (dTMinX < dMinX) dMinX = dTMinX; if (dTMaxX > dMaxX) dMaxX = dTMaxX; if (dTMinY < dMinY) dMinY = dTMinY; if (dTMaxY > dMaxY) dMaxY = dTMaxY; object obj = Type.Missing; ipPoint.X = dTMinX; ipPoint.Y = dTMinY; ipPointCollection.AddPoint(ipPoint, ref obj, ref obj); ipPoint.X = dTMinX; ipPoint.Y = dTMaxY; ipPointCollection.AddPoint(ipPoint, ref obj, ref obj); ipPoint.X = dTMaxX; ipPoint.Y = dTMinY; ipPointCollection.AddPoint(ipPoint, ref obj, ref obj); ipPoint.X = dTMaxX; ipPoint.Y = dTMaxY; ipPointCollection.AddPoint(ipPoint, ref obj, ref obj); ipFeature = ipFeatureCursor.NextFeature(); } ipTuFuMaxEnvelope.XMin = dMinX; ipTuFuMaxEnvelope.XMax = dMaxX; ipTuFuMaxEnvelope.YMin = dMinY; ipTuFuMaxEnvelope.YMax = dMaxY; return ipTuFuMaxEnvelope; } catch (Exception ex) { SendMessage(enumMessageType.Exception, ex.ToString()); return null; } }
// Adds Directions points to point collection private void AddPointsToPolyline(ISMDirections objDirections, ref IPointCollection objPoints) { Point objPoint = new PointClass(); // copy points from DD to line int nItemsCount = objDirections.Count; for (int i = 0; i < nItemsCount; i++) { // get shape from Direction ISMDirItem objItem = null; objItem = objDirections.get_Item(i) as ISMDirItem; ISMPointsCollection objShape = null; objShape = objItem.Shape; // Add point from Direction to received collection int nPointsCount = objShape.Count - 1; for (int j = 0; j <= nPointsCount; j++) { // get point from route SMRouterPoint objRouterPoint = objShape.get_Item(j); // Optimization: Not add point if last added point has similar coords bool bAddPoint = false; if (objPoint.IsEmpty) bAddPoint = true; else if ((objPoint.X != objRouterPoint.X) & (objPoint.Y != objRouterPoint.Y)) bAddPoint = true; if (bAddPoint) { // Add point if need objPoint.X = objRouterPoint.X; objPoint.Y = objRouterPoint.Y; objPoint.SpatialReference = m_objSpatialReference; object missing = System.Reflection.Missing.Value; objPoints.AddPoint(objPoint, ref missing, ref missing); } } } }
private void createpolygon(IPointCollection ippoints) { ISegmentCollection ppath = new PathClass(); IGeometryCollection ppolyline = new PolylineClass(); if (ippoints.PointCount >= 3) { int i; object o = Type.Missing; if (ippoints.PointCount >= 4) { ippoints.RemovePoints(ippoints.PointCount - 2, 1); } ippoints.AddPoint(ippoints.get_Point(0)); for (i = 0; i < ippoints.PointCount - 1; i++) { ILine pline = new LineClass(); pline.PutCoords(ippoints.get_Point(i), ippoints.get_Point(i + 1)); ISegment psegment = pline as ISegment; ppath.AddSegment(psegment, ref o, ref o); ppolyline.AddGeometry(ppath as IGeometry, ref o, ref o); } ipPolyResult = ppolyline as IPolyline; ISegmentCollection pRing = new RingClass(); IGeometryCollection pGeometryColl = new PolygonClass(); for (int j = 0; j < ppolyline.GeometryCount; j++) { pRing.AddSegmentCollection(ppolyline.get_Geometry(j) as ISegmentCollection); pGeometryColl.AddGeometry(pRing as IGeometry, ref o, ref o); } ipolygon = pGeometryColl as IPolygon; } }
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) { //If left hand mouse button if (e.button == 1) { //Create a point and grab hold of the IPoint interface IPoint point = new PointClass(); //Set point properties point.X = e.mapX; point.Y = e.mapY; //If this is the first point of a new line if (m_Polyline == null) { //Create the forms private polyline member and grab hold of the IPolyline interface m_Polyline = new PolylineClass(); } //QI for the IPointsCollection interface using the IPolyline interface object o = Type.Missing; //object o1 = m_PointCollection.PointCount-1; m_PointCollection = (IPointCollection) m_Polyline; m_PointCollection.AddPoint(point, ref o, ref o); //Refresh the foreground thereby removing any text annotation axMapControl1.Refresh(esriViewDrawPhase.esriViewForeground, Type.Missing,Type.Missing); } else { //If right or middle mouse button zoom to user defined rectangle //Create an envelope and grab hold of the IEnvelope interface IEnvelope envelope = axMapControl1.TrackRectangle(); //If user dragged a rectangle if (envelope != null) { //Set map controls extent property axMapControl1.Extent = envelope; } } }
private void buildPolyline(IPointCollection pGonColl, double x, double y) { m_workPts[0].PutCoords(x - 500, y - 500); m_workPts[1].PutCoords(x + 500, y - 500); m_workPts[2].PutCoords(x + 500, y + 500); m_workPts[3].PutCoords(x - 500, y + 500); m_workPts[4].PutCoords(x, y); try { bool add = (pGonColl.PointCount == 0); object missingVal = System.Reflection.Missing.Value; for (int i = 0; i< m_workPts.Length; i++) { ((IZAware)m_workPts[i]).ZAware = m_bZ; ((IMAware)m_workPts[i]).MAware = m_bM; if (m_bM) m_workPts[i].M = i; if (m_bZ) m_workPts[i].Z = i * 100; //add it point by point - .Net IDL limitation to do batch update? if (add) //pGonColl.AddPoints(5, ref m_workPts[0]);//strange error of type mismatch pGonColl.AddPoint(m_workPts[i], ref missingVal, ref missingVal); //The Add method only accepts either a before index or an after index. else pGonColl.UpdatePoint(i, m_workPts[i]); } //Can I user replace point collection or addPointcollection? } catch (Exception Ex) {System.Diagnostics.Debug.WriteLine(Ex.Message);} //Attempted to store an element of the incorrect type into the array. }
private void buildPolygon(IPointCollection pGonColl, double x, double y) { m_workPts[0].PutCoords(x - 500, y - 500); m_workPts[1].PutCoords(x + 500, y - 500); m_workPts[2].PutCoords(x + 500, y + 500); m_workPts[3].PutCoords(x - 500, y + 500); m_workPts[4].PutCoords(x - 500, y - 500); try { bool add = (pGonColl.PointCount == 0); object missingVal = System.Reflection.Missing.Value; for (int i = 0; i< m_workPts.Length; i++) { ((IZAware)m_workPts[i]).ZAware = m_bZ; ((IMAware)m_workPts[i]).MAware = m_bM; if (m_bM) m_workPts[i].M = i % 4; if (m_bZ) m_workPts[i].Z = (i % 4) * 100; //match start and end points if (add) pGonColl.AddPoint(m_workPts[i], ref missingVal, ref missingVal); //The Add method only accepts either a before index or an after index. else pGonColl.UpdatePoint(i, m_workPts[i]); } } catch (Exception Ex) {System.Diagnostics.Debug.WriteLine(Ex.Message);} //Attempted to store an element of the incorrect type into the array. }