/// <summary> /// 将字符串格式转化为Geometry /// </summary> /// <param name="geom"> 客户端传递多边形格式 1) x1,y1;x2,y2;x3,y3.......xn,yn;x1,y1;保证起始闭合 为无环 /// 2) x1,y1,flag3;x2,y2,flag3;x3,y3,flag3.......xn,yn,,flagn; /// </param> /// <returns></returns> public static IPolygon BuildPolygon(string geom) { if (string.IsNullOrEmpty(geom) == true) { throw new Exception(sErroCoordinatesIsNull); } string[] points = geom.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (points != null && points.Length > 2) { int pointCount = points.Length; IPolygon polygon = null; IPoint point = null; object missing = Type.Missing; IGeometryCollection pGeoColl = new PolygonClass() as IGeometryCollection; IPointCollection pPointCol = new RingClass(); for (int i = 0; i < pointCount; i++) { string[] pts = points[i].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); point = new PointClass(); double x = 0.0; double y = 0.0; int flag = 0; bool bX = double.TryParse(pts[0], out x); bool bY = double.TryParse(pts[1], out y); bool bFlag = int.TryParse(pts[2], out flag); if (bX && bY && bFlag) { pPointCol.AddPoint(point, ref missing, ref missing); if (flag == -1 || i == (pointCount - 1)) { pGeoColl.AddGeometry(pPointCol as IRing, ref missing, ref missing); pPointCol = null; break; } else if (flag == -2) { pGeoColl.AddGeometry(pPointCol as IRing, ref missing, ref missing); pPointCol = new RingClass(); continue; } } else { throw new Exception(sErroCoordinatesValueIllegal); } } if (pPointCol.PointCount > 0) { pGeoColl.AddGeometry(pPointCol as IRing, ref missing, ref missing); } polygon = pGeoColl as IPolygon; SimplifyGeometry(polygon); return polygon; } else { throw new Exception(sErroCoordinatesValueIllegal); } }
/// <summary> /// 多部分(多外环)的多边形转成多个单部分的多边形 /// </summary> /// <param name="polygon"></param> /// <returns></returns> public static IPolygon[] MultiPartToSinglePart(this IPolygon4 polygon) { List <IPolygon> polygons = new List <IPolygon>(); //外部环 IGeometryBag exteriorRingGeometryBag = polygon.ExteriorRingBag; IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection; for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++) { IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i); IRing ring = exteriorRingGeometry as IRing; ring.Close(); IGeometryCollection pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(ring); //内部环 IGeometryBag interiorRingGeometryBag = polygon.get_InteriorRingBag(exteriorRingGeometry as IRing); IGeometryCollection interiorRingGeometryCollection = interiorRingGeometryBag as IGeometryCollection; for (int k = 0; k < interiorRingGeometryCollection.GeometryCount; k++) { IGeometry interiorRingGeometry = interiorRingGeometryCollection.get_Geometry(k); IRing ring2 = interiorRingGeometry as IRing; ring2.Close(); pGeometryColl.AddGeometry(ring2); } ITopologicalOperator pTopological = pGeometryColl as ITopologicalOperator; pTopological.Simplify(); IPolygon p = pGeometryColl as IPolygon; polygons.Add(p); } return(polygons.ToArray()); }
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); }
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 static IPolygon PolylineToPolygon(ref IPolyline pPolyline) { try { //创建一个新的Polygon geometry. IGeometryCollection pPolygonGeometryCol = new PolygonClass(); //克隆即将要操作的Polyline IClone pClone = pPolyline as IClone; IGeometryCollection pGeoms_Polyline = pClone.Clone() as IGeometryCollection; object pBObj = Type.Missing; object pAObj = Type.Missing; for (int i = 0; i < pGeoms_Polyline.GeometryCount; i++) { //通过Polyline的每个Path创建为一个新的Ring,并把Ring增加到一个新的Polygon ISegmentCollection pSegs_Ring = new RingClass(); pSegs_Ring.AddSegmentCollection(pGeoms_Polyline.get_Geometry(i) as ISegmentCollection); pPolygonGeometryCol.AddGeometry(pSegs_Ring as IGeometry, ref pBObj, ref pAObj); } //生成的Polygon旋转的顺序可能不正确,为确保正确调用SimplifyPreserveFromTo IPolygon pNewPolygon = new PolygonClass(); pNewPolygon = pPolygonGeometryCol as IPolygon; pNewPolygon.SimplifyPreserveFromTo(); return(pNewPolygon); } catch { return(null); } }
public static IGeometryCollection ConstructPolygon(List <IPoint> pointArray) { //创建一个Ring对象,通过ISegmentCollection接口向其中添加Segment对象 object o = Type.Missing; ISegmentCollection pSegCollection = new RingClass(); for (int i = 0; i < pointArray.Count - 1; i++) { IPoint from = pointArray[i]; IPoint to = pointArray[i + 1]; ILine pLine = new LineClass(); //设置Line对象的起始终止点 pLine.PutCoords(from, to); //QI到ISegment ISegment pSegment = pLine as ISegment; pSegCollection.AddSegment(pSegment, ref o, ref o); } //QI到IRing接口封闭Ring对象,使其有效 IRing pRing = pSegCollection as IRing; pRing.Close(); //使用Ring对象构建Polygon对象 IGeometryCollection pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(pRing, ref o, ref o); return(pGeometryColl); }
private IGeometry mergeSmallGeos(IGeometry geo) { ITopologicalOperator4 tp4 = (ITopologicalOperator4)geo; IGeometryCollection geoCol = new PolygonClass(); IGeometry bGeo = tp4.Boundary; ISpatialFilter spFilt = new SpatialFilter(); spFilt.Geometry = bGeo; spFilt.SearchOrder = esriSearchOrder.esriSearchOrderSpatial; spFilt.GeometryField = ftrCls.ShapeFieldName; spFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; spFilt.WhereClause = "Shape_Area <= " + minarea; spFilt.SubFields = ftrCls.ShapeFieldName; IFeatureCursor ftrCur = ftrCls.Search(spFilt, false); IFeature ftr = ftrCur.NextFeature(); int cntTest = 0; while (ftr != null) { IGeometry sGeo = ftr.ShapeCopy; geoCol.AddGeometry(sGeo); ftr.Delete(); ftr = ftrCur.NextFeature(); cntTest++; } if (cntTest > 0) { tp4.ConstructUnion((IEnumGeometry)geoCol); } return((IGeometry)tp4); }
public static IGeometryCollection ConstructPolygon(IPoint[] pointArray) { //创建一个Ring对象,通过ISegmentCollection接口向其中添加Segment对象 object o = Type.Missing; ISegmentCollection pSegCollection = new RingClass(); for (int i = 0; i < pointArray.Length - 1; i++) { IPoint from = pointArray[i]; IPoint to = pointArray[i + 1]; ILine pLine = new LineClass(); //设置Line对象的起始终止点 pLine.PutCoords(from, to); //QI到ISegment ISegment pSegment = pLine as ISegment; pSegCollection.AddSegment(pSegment, ref o, ref o); } //QI到IRing接口封闭Ring对象,使其有效 IRing pRing = pSegCollection as IRing; pRing.Close(); //使用Ring对象构建Polygon对象 IGeometryCollection pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(pRing, ref o, ref o); //释放AO对象 System.Runtime.InteropServices.Marshal.ReleaseComObject(pRing); return(pGeometryColl); }
private IPolygon GeneratePolygonFromRing(Ring ring) { IGeometryCollection pointPolygon = new PolygonClass(); object missing = Type.Missing; pointPolygon.AddGeometry(ring as IGeometry, ref missing, ref missing); IPolygon polyGonGeo = pointPolygon as IPolygon; polyGonGeo.SimplifyPreserveFromTo(); return polyGonGeo; }
/// <summary> /// 重新构造面对象 /// </summary> /// <param name="pPolygon"></param> /// <returns></returns> public static PolygonClass ReNew(IPolygon geo) { object obj = Type.Missing; PolygonClass p = null; IRing[] ExtRingArray = GetExteriorRings(geo as IPolygon4); if (ExtRingArray != null && ExtRingArray.Length > 0) { p = new PolygonClass(); foreach (IRing r in ExtRingArray) { p.AddGeometry(r, ref obj, ref obj); foreach (IRing ir in GetInteriorRingsByExterior(r, geo)) { p.AddGeometry(ir, ref obj, ref obj); } } p.SimplifyPreserveFromTo(); } return(p); }
//根据读取出来的坐标,创建新要素 private void CreateFeatures(IFeatureClass targetClass, List <List <Vertex> > polygons, string TBBHFieldName) { //编辑器 IWorkspaceEdit m_WorkspaceEdit = (targetClass as IDataset).Workspace as IWorkspaceEdit; m_WorkspaceEdit.StartEditing(true); m_WorkspaceEdit.StartEditOperation(); //一个一个多边形地处理,对应一个要素 foreach (List <Vertex> polygon in polygons) { IFeature newFeature = targetClass.CreateFeature(); Ring ring = new RingClass(); object missing = Type.Missing; //把每个顶点添加到环 foreach (Vertex vertex in polygon) { IPoint pt = new PointClass(); double X = vertex.X; double Y = vertex.Y; pt.PutCoords(X, Y); ring.AddPoint(pt, ref missing, ref missing); } //投影 IGeometry geometry = ring as IGeometry; IGeoDataset pGeoDataset = targetClass as IGeoDataset; if (pGeoDataset.SpatialReference != null) { geometry.Project(pGeoDataset.SpatialReference); } else { geometry.Project(pMapControl.SpatialReference); } //环构成多边形 IGeometryCollection newPolygon = new PolygonClass(); newPolygon.AddGeometry(geometry, ref missing, ref missing); IPolygon newPolygon2 = newPolygon as IPolygon; newPolygon2.SimplifyPreserveFromTo(); newFeature.Shape = newPolygon2 as IGeometry; //加上TBBH属性 int fieldIndex = newFeature.Fields.FindField(TBBHFieldName); newFeature.set_Value(fieldIndex, polygon[0].TBBH);//取任意一个顶点的tbbh newFeature.Store(); } //保存 m_WorkspaceEdit.StopEditOperation(); m_WorkspaceEdit.StopEditing(true); IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = targetClass; }
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); }
private int ReportError([NotNull] IPolygon footPrint, [NotNull] IMultiPatch multiPatch, [NotNull] IRow row) { IGeometryCollection innerRings = new PolygonClass(); var rings = (IGeometryCollection)footPrint; int ringCount = rings.GeometryCount; for (int index = 0; index < ringCount; index++) { var ring = (IRing)rings.Geometry[index]; if (ring.IsExterior) { continue; } object missing = Type.Missing; innerRings.AddGeometry(GeometryFactory.Clone(ring), ref missing, ref missing); } ((IZAware)innerRings).ZAware = true; ((IZ)innerRings).SetConstantZ(multiPatch.Envelope.ZMin); int errorCount = 0; foreach (IRing ring in GeometryUtils.GetRings((IPolygon)innerRings)) { double area = Math.Abs(((IArea)ring).Area); if (_minimumArea > 0 && area >= _minimumArea) { continue; } string description = string.Format("Footprint has inner ring (area: {0})", FormatArea(area, _spatialReference)); errorCount += ReportError(description, GeometryFactory.CreatePolygon(ring), Codes[Code.FootprintHasInnerRing], _shapeFieldName, new object[] { area }, row); } return(errorCount); }
private IGeometry WKTCoordinateInfo2Polygon(string WKTCoor, out string message) { string[] polygons; if (WKTCoor.Contains("),(")) { polygons = WKTCoor.Split(new string[] { "),(" }, StringSplitOptions.RemoveEmptyEntries); } else { polygons = new string[] { WKTCoor }; } IGeometryCollection polygon = new PolygonClass(); foreach (var item in polygons) { string[] split = item.Split(','); if (split.Length < 3) { message = "坐标点太少." + WKTCoor; return(null); } Ring ring = new RingClass(); int len = split.Length; for (int i = 0; i < len; i++) { _coorStr = split[i].Split(' '); if (_coorStr.Length != 2) { message = "坐标点不能正确分割." + WKTCoor; return(null); } if (!double.TryParse(_coorStr[0], out _x) || !double.TryParse(_coorStr[1], out _y)) { message = "坐标点不能转换为double." + WKTCoor; return(null); } _point.PutCoords(x, y); ring.AddPoint(_point, ref missing, ref missing); } polygon.AddGeometry(ring as IGeometry, ref missing, ref missing); } IPolygon poly = polygon as IPolygon; poly.SimplifyPreserveFromTo(); IGeometry geometry = poly as IGeometry; message = ""; return(geometry); }
//由点集生成面(环形Polygon) private IGeometry getGeometry(IPointCollection Points) { Ring ring = new RingClass(); object missing = Type.Missing; ring.AddPointCollection(Points); IGeometryCollection pointPolygon = new PolygonClass(); pointPolygon.AddGeometry(ring as IGeometry, ref missing, ref missing); IPolygon polyGonGeo = pointPolygon as IPolygon; //polyGonGeo.Close(); polyGonGeo.SimplifyPreserveFromTo(); return(polyGonGeo as IGeometry); }
//cast the polyline object to the polygon xisheng 20110926 private IPolygon GetPolygonFormLine(IPolyline pPolyline) { ISegmentCollection pRing; IGeometryCollection pPolygon = new PolygonClass(); IGeometryCollection pPolylineC = pPolyline as IGeometryCollection; object o = Type.Missing; for (int i = 0; i < pPolylineC.GeometryCount; i++) { pRing = new RingClass(); pRing.AddSegmentCollection(pPolylineC.get_Geometry(i) as ISegmentCollection); pPolygon.AddGeometry(pRing as IGeometry, ref o, ref o); } IPolygon polygon = pPolygon as IPolygon; return(polygon); }
private IGeometry EllipticArcTransPolygon(IEllipticArc pEll) { try { object missing = Type.Missing; ISegmentCollection pSegmentColl = new RingClass(); pSegmentColl.AddSegment((ISegment)pEll, ref missing, ref missing); IRing pRing = (IRing)pSegmentColl; pRing.Close(); //得到闭合的环 IGeometryCollection pGeometryCollection = new PolygonClass(); pGeometryCollection.AddGeometry(pRing, ref missing, ref missing); //环转面 IPolygon pPolygon = (IPolygon)pGeometryCollection; return(pPolygon); } catch (Exception ex) { throw ex; } }
private IPolygon Arc2Polygon(ICircularArc Arc) { ISegmentCollection pSegCol = new RingClass(); object obj = Type.Missing; pSegCol.AddSegment((ISegment)Arc, ref obj, ref obj); //enclose ring make it valid IRing pRing; pRing = pSegCol as IRing; pRing.Close(); IGeometryCollection pPolygonCol = new PolygonClass(); pPolygonCol.AddGeometry(pRing, ref obj, ref obj); IPolygon circlePolygon = (IPolygon)pPolygonCol; // mirror spatial referrence ISpatialReference spr = Arc.SpatialReference; circlePolygon.SpatialReference = spr; return(circlePolygon); }
public static IPolygon GetVisilityPolygon(List <IPolyline> polylines) { IGeometryCollection geometryCollection = new PolygonClass(); ISegmentCollection ringSegColl1 = new RingClass(); foreach (var polyline in polylines) { ILine line = new LineClass() { FromPoint = polyline.FromPoint, ToPoint = polyline.ToPoint, SpatialReference = polyline.SpatialReference }; var polylineSeg = (ISegment)line; ringSegColl1.AddSegment(polylineSeg); } var ringGeometry = ringSegColl1 as IGeometry; IZAware zAwareRing = ringGeometry as IZAware; zAwareRing.ZAware = true; IRing ring1 = ringSegColl1 as IRing; ring1.Close(); IGeometryCollection polygon = new PolygonClass(); polygon.AddGeometry(ring1 as IGeometry); var geometry = polygon as IGeometry; IZAware zAware = geometry as IZAware; zAware.ZAware = true; var result = polygon as IPolygon; result.SpatialReference = polylines[0].SpatialReference; return(result); }
private void DrawEllipse() { IEnvelope envelope = this.m_mapControl.TrackRectangle(); if (!envelope.IsEmpty) { IConstructEllipticArc constructEllipticArc = new EllipticArcClass(); constructEllipticArc.ConstructEnvelope(envelope); ISegment inSegment = constructEllipticArc as ISegment; ISegmentCollection segmentCollection = new RingClass(); object missing = Type.Missing; segmentCollection.AddSegment(inSegment, ref missing, ref missing); IRing ring = segmentCollection as IRing; ring.Close(); IGeometryCollection geometryCollection = new PolygonClass(); geometryCollection.AddGeometry(ring, ref missing, ref missing); this.AppendNodeToTreeList(new EllipseElementClass { Geometry = (geometryCollection as IGeometry) }); } }
public static IGeometryCollection ConstructPolygon(ISegment[] segmentArray) { //创建一个Ring对象,通过ISegmentCollection接口向其中添加Segment对象 object o = Type.Missing; ISegmentCollection pSegCollection = new RingClass(); for (int i = 0; i < segmentArray.Length; i++) { pSegCollection.AddSegment(segmentArray[i], ref o, ref o); } //QI到IRing接口封闭Ring对象,使其有效 IRing pRing = pSegCollection as IRing; pRing.Close(); //使用Ring对象构建Polygon对象 IGeometryCollection pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(pRing, ref o, ref o); return(pGeometryColl); }
/// <summary> /// 通过点集构成多边形(只适用单环多边形) /// </summary> /// <param name="pointList">按顺序构成一个环的点集</param> /// <returns></returns> public static IPolygon CreatePolygon(IEnumerable <IPoint> pointList) { if (pointList.Count() < 3) { throw new Exception("地块点数小于3,不能构成多边形!"); } IGeometryCollection pointPolygon = new PolygonClass(); Ring ring = new RingClass(); object missing = Type.Missing; foreach (var pt in pointList) { ring.AddPoint(pt, ref missing, ref missing); } pointPolygon.AddGeometry(ring as IGeometry, ref missing, ref missing); IPolygon polygon = pointPolygon as IPolygon; polygon.SimplifyPreserveFromTo(); return(polygon); }
public IPolygon ConvertPolylineToPolygon(IPolyline pPolyline) { try { if (pPolyline == null) { return(null); } IClone clone = pPolyline as IClone; IGeometryCollection geometrys = null; geometrys = clone.Clone() as IGeometryCollection; if (geometrys.GeometryCount < 0) { return(null); } IGeometryCollection geometrys2 = null; geometrys2 = new PolygonClass(); ISegmentCollection segments = null; int index = 0; object before = null; object after = null; for (index = 0; index <= (geometrys.GeometryCount - 1); index++) { segments = new RingClass(); segments.AddSegmentCollection(geometrys.get_Geometry(index) as ISegmentCollection); geometrys2.AddGeometry(segments as IGeometry, ref before, ref after); } (geometrys2 as ITopologicalOperator).Simplify(); return(geometrys2 as IPolygon); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.GeometryFun", "ConvertPolylineToPolygon", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(null); } }
static private IPolygon ConstructPolygonFromPolyline(IPolyline pPolyline) { IGeometryCollection pPolygonGeoCol = new PolygonClass(); if ((pPolyline != null) && (!pPolyline.IsEmpty)) { IGeometryCollection pPolylineGeoCol = pPolyline as IGeometryCollection; ISegmentCollection pSegCol = new RingClass(); ISegment pSegment = null; object missing = Type.Missing; for (int i = 0; i < pPolylineGeoCol.GeometryCount; i++) { ISegmentCollection pPolylineSegCol = pPolylineGeoCol.get_Geometry(i) as ISegmentCollection; for (int j = 0; j < pPolylineSegCol.SegmentCount; j++) { pSegment = pPolylineSegCol.get_Segment(j); pSegCol.AddSegment(pSegment, ref missing, ref missing); } pPolygonGeoCol.AddGeometry(pSegCol as IGeometry, ref missing, ref missing); } } return(pPolygonGeoCol as IPolygon); }
private IPolygon ContructGeometry(out PolygonClass polygon1) { polygon1 = new PolygonClass(); var polygon = new PolygonClass(); var p00 = ConstructPoint(_centerPoint, Angle0, Angle1, _height4, 0); var p01 = ConstructPoint(_centerPoint, Angle2, Angle1, _height4); var p04 = ConstructPoint(_centerPoint, Angle0, Angle1, _height4); var list0 = new List <IPoint> { p01, ConstructPoint2(p01, Angle3, p00, Angle2 - Angle3), ConstructPoint2(p00, -Angle3, p04, Angle2 + Angle3), p04, ConstructPoint(_centerPoint, Angle0, Angle1, _height3), ConstructPoint(_centerPoint, Angle2, Angle1, _height3), p01 }; polygon1.AddGeometry(ConstructRing(list0)); var list1 = new List <IPoint> { p00, ConstructPoint2(p00, Angle3, p04, Angle2 - Angle3), p04, ConstructPoint2(p00, -Angle3, p04, Angle2 + Angle3), p00 }; polygon.AddGeometry(ConstructRing(list1)); var list2 = new List <IPoint> { ConstructPoint(_centerPoint, Angle2, Angle1, _height3), ConstructPoint(_centerPoint, Angle0, Angle1, _height3), ConstructPoint(_centerPoint, Angle0, Angle1, _halfHeight), ConstructPoint(_centerPoint, Angle2, Angle1, _halfHeight), ConstructPoint(_centerPoint, Angle2, Angle1, _height3) }; polygon.AddGeometry(ConstructRing(list2)); var list3 = new List <IPoint> { ConstructPoint(_centerPoint, Angle2, -Angle1, _height3), ConstructPoint(_centerPoint, Angle0, -Angle1, _height3), ConstructPoint(_centerPoint, Angle0, -Angle1, _halfHeight), ConstructPoint(_centerPoint, Angle2, -Angle1, _halfHeight), ConstructPoint(_centerPoint, Angle2, -Angle1, _height3) }; polygon.AddGeometry(ConstructRing(list3)); var p20 = ConstructPoint(_centerPoint, Angle0, -Angle1, _height4, 0); var p21 = ConstructPoint(_centerPoint, Angle2, -Angle1, _height4); var p24 = ConstructPoint(_centerPoint, Angle0, -Angle1, _height4); var list4 = new List <IPoint> { p21, ConstructPoint2(p21, Angle3, p20, Angle2 - Angle3), ConstructPoint2(p20, -Angle3, p24, Angle2 + Angle3), p24, ConstructPoint(_centerPoint, Angle0, -Angle1, _height3), ConstructPoint(_centerPoint, Angle2, -Angle1, _height3), p21 }; polygon1.AddGeometry(ConstructRing(list4)); var list5 = new List <IPoint> { p20, ConstructPoint2(p20, Angle2 - Angle3, p21, Angle3), p21, ConstructPoint2(p20, Angle2 + Angle3, p21, -Angle3), p20 }; polygon.AddGeometry(ConstructRing(list5)); polygon.Close(); return(polygon); }
private void Coordinate_Load(object sender, EventArgs e) { //定义点集环形 Ring ring1 = new RingClass(); object missing = Type.Missing; //新建一个datatable用于保存读入的数据 DataTable dt = new DataTable(); OpenFileDialog ofd = new OpenFileDialog(); ofd.Multiselect = false; //单选 ofd.Title = "选择坐标文件"; ofd.Filter = "txt文件|*.txt"; // ofd.InitialDirectory = Environment.SpecialFolder.Desktop.ToString(); ofd.InitialDirectory = SystemSet.Base_Map + "\\处理数据库\\坐标数据"; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //IGeometryCollection pointPolygon = new PolygonClass(); FileInfo fi = new FileInfo(ofd.FileName); try { paths1 = ofd.FileName; lengh = paths1.Length - ofd.InitialDirectory.Length; String paths = ofd.FileName; int i = 0; //给datatable添加5个列 dt.Columns.Add("编号", typeof(int)); dt.Columns.Add("坐标X", typeof(double)); dt.Columns.Add("坐标Y", typeof(double)); dt.Columns.Add("高程Z", typeof(double)); dt.Columns.Add("日期", typeof(string)); //读入文件 StreamReader sr = new StreamReader(paths, Encoding.Default); //循环读取所有行 while (!sr.EndOfStream)//(line = sr.ReadLine()) != null) { i++; //将每行数据,用-分割成2段 //sr.ReadLine().TrimStart();//消除前面空格 //sr.ReadLine().TrimEnd();//消除尾部空格 string[] data = sr.ReadLine().Split(',', ' '); //新建一行,并将读出的数据分段,分别存入5个对应的列中 DataRow dr = dt.NewRow(); dr[0] = i; dr[1] = data[0]; dr[2] = data[1]; dr[3] = 0; dr[4] = DateTime.Now.ToLongDateString().ToString(); //将这行数据加入到datatable中 dt.Rows.Add(dr); //点上生成面 IPoint ppp = new PointClass(); ppp.PutCoords((double)dr[1], (double)dr[2]); ring1.AddPoint(ppp, ref missing, ref missing); //调用画点工具 GISHandler.GISTools.CreatPoint(this.mapControl, (double)dr[1], (double)dr[2], i); } } catch { MessageBox.Show("坐标文件内容错误!请检查格式是否为:x,y或者x y"); return; } IGeometryCollection pointPolygon = new PolygonClass(); pointPolygon.AddGeometry(ring1 as IGeometry, ref missing, ref missing); IPolygon polyGonGeo = pointPolygon as IPolygon; ply = polyGonGeo; polyGonGeo.SimplifyPreserveFromTo(); //object miss = Type.Missing; //this.mapControl.DrawShape(polyGonGeo, ref miss); } else this.Close(); gridControl1.DataSource = dt; dataGridView1.DataSource = dt; gridView1.OptionsView.ShowGroupPanel = false; }
private IElement DrawCircle(double radius, double x, double y) { IPoint centralPoint = new PointClass(); centralPoint.PutCoords(x, y); // 创建园 ICircularArc circularArc = new CircularArcClass(); IConstructCircularArc construtionCircularArc = circularArc as IConstructCircularArc; construtionCircularArc.ConstructCircle(centralPoint, radius, true); ISegment pSegment1 = circularArc as ISegment; //通过ISegmentCollection构建Ring对象 ISegmentCollection pSegCollection = new RingClass(); object o = Type.Missing; //添加Segement对象即圆 pSegCollection.AddSegment(pSegment1, ref o, ref o); //QI到IRing接口封闭Ring对象,使其有效 IRing pRing = pSegCollection as IRing; pRing.Close(); //通过Ring对象使用IGeometryCollection构建Polygon对象 IGeometryCollection pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(pRing, ref o, ref o); //构建一个CircleElement对象 IElement pElement = new CircleElementClass(); pElement.Geometry = pGeometryColl as IGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; ISimpleFillSymbol pFillSymbol = new SimpleFillSymbolClass(); //pFillSymbol.Color = pCircleColor; ILineSymbol pLineSymbol = new SimpleLineSymbolClass(); // pLineSymbol.Color = DefineColor(0, 255, 0); pFillSymbol.Outline = pLineSymbol; pFillShapeElement.Symbol = pFillSymbol; IFillShapeElement circleElement = pElement as IFillShapeElement; circleElement.Symbol = pFillSymbol; IGraphicsContainer pGC = this.axMapControl.ActiveView.GraphicsContainer; pGC.AddElement(pElement, 0); axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); return pElement; }
static void CopyAndLabel(IFeatureClass inFC, IFeatureWorkspace destination, String name) { IFieldsEdit outFields = new FieldsClass(); ISpatialReference outSR = null; for (int i = 0; i < inFC.Fields.FieldCount; i += 1) { IField field = inFC.Fields.get_Field(i); if (field.Type == esriFieldType.esriFieldTypeGeometry) { outSR = field.GeometryDef.SpatialReference; } else { outFields.AddField(field); } } outSR.SetMDomain(-137434824702, 137434824702); IGeometryDefEdit geom = new GeometryDefClass(); geom.GeometryType_2 = esriGeometryType.esriGeometryPolygon; geom.SpatialReference_2 = outSR; geom.HasM_2 = true; geom.HasZ_2 = false; IFieldEdit geomField = new FieldClass(); geomField.Name_2 = "SHAPE"; geomField.AliasName_2 = "SHAPE"; geomField.Type_2 = esriFieldType.esriFieldTypeGeometry; geomField.GeometryDef_2 = geom; outFields.AddField(geomField); IFeatureClass outFC = destination.CreateFeatureClass(name, outFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", ""); // Start numbering from 1, because index 0 is used by clipping cell int vIndex = 1; IFeatureCursor featureCursor = inFC.Search(null, true); IFeature inFeature; while ((inFeature = featureCursor.NextFeature()) != null) { IFeature outFeature = outFC.CreateFeature(); for (int i = 0; i < outFields.FieldCount; i += 1) { IField field = outFields.Field[i]; if (field.Editable && (field.Type != esriFieldType.esriFieldTypeGeometry)) { outFeature.set_Value(i, inFeature.get_Value(i)); } } IPolygon4 inShape = inFeature.Shape as IPolygon4; PolygonClass outShape = new PolygonClass(); IGeometryBag extRingBag = inShape.ExteriorRingBag; IGeometryCollection extRings = extRingBag as IGeometryCollection; for (int i = 0; i < extRings.GeometryCount; i += 1) { IGeometry inExtRingGeom = extRings.get_Geometry(i); IPointCollection inExtRing = inExtRingGeom as IPointCollection; RingClass outExtRing = new RingClass(); for (int j = 0; j < inExtRing.PointCount; j += 1) { IPoint point = inExtRing.get_Point(j); point.M = vIndex; vIndex += 2; outExtRing.AddPoint(point); } outShape.AddGeometry(outExtRing); IGeometryBag intRingBag = inShape.get_InteriorRingBag(inExtRingGeom as IRing); IGeometryCollection intRings = intRingBag as IGeometryCollection; for (int j = 0; j < intRings.GeometryCount; j += 1) { IGeometry intRingGeom = intRings.get_Geometry(j); IPointCollection inIntRing = intRingGeom as IPointCollection; RingClass outIntRing = new RingClass(); for (int k = 0; k < inIntRing.PointCount; k += 1) { IPoint point = inExtRing.get_Point(k); point.M = vIndex; vIndex += 2; outIntRing.AddPoint(point); } outShape.AddGeometry(outIntRing); } } outFeature.Shape = outShape; outFeature.Store(); } }
public static IPolygon MakePolygonFromRing(Ring ring) { object missing = Type.Missing; IGeometryCollection pointPolygon = new PolygonClass(); pointPolygon.AddGeometry(ring as IGeometry, ref missing, missing); IPolygon polygon = pointPolygon as IPolygon; polygon.SimplifyPreserveFromTo(); return polygon; }
//} /// <summary> /// 矢量转换函数 /// </summary> private void exprotMatrix() { ClsGDBDataCommon comm = new ClsGDBDataCommon(); if (!textOutData.Text.EndsWith("shp")) { //timerShow.Start(); MessageBox.Show("输出文件名不是shp文件!"); return; } object featureOID; String strFullName = textOutData.Text; string strPath = System.IO.Path.GetDirectoryName(strFullName); string strName = System.IO.Path.GetFileName(strFullName); ILayer player = null; for (int i = 0; i < pMapControl.Map.LayerCount; i++) { if (pMapControl.Map.Layer[i].Name == cmbLayer.Text) { player = pMapControl.Map.Layer[i]; break; } } IFeatureLayer pFlayer = player as IFeatureLayer; IFeatureClass pFclass = pFlayer.FeatureClass; IFields pFields = pFclass.Fields; //设置空间参考 ISpatialReference pSpatialRef; IGeoDataset pGeo = (IGeoDataset)pFlayer; pSpatialRef = pGeo.SpatialReference; IFeatureClass pFtClassNew = comm.CreateShapefile(strPath, strName, pFields, pSpatialRef); //for (int i = 0; i < pFtClassNew.Fields.FieldCount;i++ ) //{ // if (pFtClassNew.Fields.get_Field(i).Type != esriFieldType.esriFieldTypeGeometry && // pFtClassNew.Fields.get_Field(i).Type != esriFieldType.esriFieldTypeOID) // { // pFtClassNew.Fields.get_Field(i).IsNullable = true; // } //} IFeatureCursor pFC = pFlayer.FeatureClass.Search(null, false); IFeature pF = pFC.NextFeature(); while (pF != null) { if (pFclass.ShapeType == esriGeometryType.esriGeometryMultipoint || pFclass.ShapeType == esriGeometryType.esriGeometryPoint) { double[] oldarray = new double[3]; double[] newarray = new double[3]; Matrix matrix = new Matrix(); IPoint pPointOld = pF.Shape as IPoint; IPoint pPointNew = new PointClass(); oldarray[0] = pPointOld.X; oldarray[1] = pPointOld.Y; if (pPointOld.Z.ToString() == "NaN" || pPointOld.Z.ToString() == "非数字") { oldarray[2] = 0;//pPointOld.Z; } else { oldarray[2] = pPointOld.Z; } matrix.coord_Trans(oldarray, rotateMat, tranVec, newarray); pPointNew.X = newarray[0]; pPointNew.Y = newarray[1]; if (pPointOld.Z.ToString() == "NaN" || pPointOld.Z.ToString() == "非数字") { pPointNew.Z = 0; } else { pPointNew.Z = newarray[2]; } IFeature pFeatureTemp = pFtClassNew.CreateFeature(); pFeatureTemp.Shape = pPointNew as IGeometry; ClsGDBDataCommon.CopyFeatureFieldValue(pF, pFeatureTemp); pFeatureTemp.Store(); } else if (pFclass.ShapeType == esriGeometryType.esriGeometryLine || pFclass.ShapeType == esriGeometryType.esriGeometryPolyline) { double[] oldarrayS = new double[3]; double[] oldarrayT = new double[3]; double[] newarrayS = new double[3]; double[] newarrayT = new double[3]; Matrix matrix = new Matrix(); ISegmentCollection pSegCOld = pF.Shape as ISegmentCollection; ISegmentCollection pSegCNew = new PolylineClass(); // ISegment pSegmentNEW = new LineClass(); //ILine pLine = new LineClass(); IPoint pPointF = new PointClass(); IPoint pPointT = new PointClass(); for (int i = 0; i < pSegCOld.SegmentCount; i++) { ISegment pSegmentNEW = new LineClass(); ISegment pseg = pSegCOld.Segment[i]; oldarrayS[0] = pseg.FromPoint.X; oldarrayS[1] = pseg.FromPoint.Y; if (pseg.FromPoint.Z.ToString() == "NaN" || pseg.FromPoint.Z.ToString() == "非数字") { oldarrayS[2] = 0; } else { oldarrayS[2] = pseg.FromPoint.Z; } matrix.coord_Trans(oldarrayS, rotateMat, tranVec, newarrayS); pPointF.X = newarrayS[0]; pPointF.Y = newarrayS[1]; if (pseg.FromPoint.Z.ToString() == "NaN" || pseg.FromPoint.Z.ToString() == "非数字") { pPointF.Z = 0; } else { pPointF.Z = newarrayS[2]; } pSegmentNEW.FromPoint = pPointF; oldarrayT[0] = pseg.ToPoint.X; oldarrayT[1] = pseg.ToPoint.Y; if (pseg.ToPoint.Z.ToString() == "NaN" || pseg.ToPoint.Z.ToString() == "非数字") { oldarrayT[2] = 0; } else { oldarrayT[2] = pseg.ToPoint.Z; } matrix.coord_Trans(oldarrayT, rotateMat, tranVec, newarrayT); pPointT.X = newarrayT[0]; pPointT.Y = newarrayT[1]; if (pseg.ToPoint.Z.ToString() == "NaN" || pseg.ToPoint.Z.ToString() == "非数字") { pPointT.Z = 0; } else { pPointT.Z = newarrayT[2]; } pSegmentNEW.ToPoint = pPointT; pSegCNew.AddSegment(pSegmentNEW); } IFeature pFeatureTemp = pFtClassNew.CreateFeature(); pFeatureTemp.Shape = pSegCNew as IGeometry; ClsGDBDataCommon.CopyFeatureFieldValue(pF, pFeatureTemp); pFeatureTemp.Store(); } else if (pFclass.ShapeType == esriGeometryType.esriGeometryPolygon) { double[] oldarrayS = new double[3]; double[] oldarrayT = new double[3]; double[] newarrayS = new double[3]; double[] newarrayT = new double[3]; Matrix matrix = new Matrix(); IGeometryCollection pGCollectionOld = pF.Shape as IGeometryCollection; IGeometryCollection pGCollectionNew = new PolygonClass(); ISegmentCollection psegCOld = new RingClass(); //ILine pLine = new LineClass(); IPoint pPointF = new PointClass(); IPoint pPointT = new PointClass(); //IPointCollection pPointCOld = new PolygonClass(); //IPointCollection pPointCNew = new PolygonClass(); //pPointCOld=pF.Shape as IPointCollection; //for (int i = 0; i < pPointCOld.PointCount;i++ ) //{ // pPointF = pPointCOld.Point[i]; // oldarrayS[0] = pPointF.X; // oldarrayS[0] = pPointF.Y; // if (pPointF.Z.ToString() == "NaN" || pPointF.Z.ToString() == "非数字") // { // oldarrayS[2] = 0;//pPointOld.Z; // } // else // { // oldarrayS[2] = pPointF.Z; // } // matrix.coord_Trans(oldarrayS, rotateMat, tranVec, newarrayT); // pPointT.X = newarrayT[0]; // pPointT.Y = newarrayT[1]; // if (pPointF.Z.ToString() == "NaN" || pPointF.Z.ToString() == "非数字") // { // pPointT.Z = 0; // } // else // { // pPointT.Z = newarrayT[2]; // } // pPointCNew.AddPoint(pPointT); //} //IPolygon pPolygon = pPointCNew as IPolygon; //pPolygon.Close(); //IFeature pFeatureTemp = pFtClassNew.CreateFeature(); //pFeatureTemp.Shape = pPolygon as IGeometry; //CopyFeatureField(pF, pFeatureTemp); //pFeatureTemp.Store(); ///方法一 //IPolygon pPolygon=pF.Shape as IPolygon; //IRing pExterRingOld = new RingClass(); //IRing pExterRingNew = new RingClass(); //for (int i = 0; i<pPolygon.ExteriorRingCount;i++ ) //{ // pExterRingOld = pPolygon.FindExteriorRing(null); //} //方法二 for (int i = 0; i < pGCollectionOld.GeometryCount; i++) { psegCOld = pGCollectionOld.Geometry[i] as ISegmentCollection; ISegmentCollection pSegCNew = new RingClass(); for (int j = 0; j < psegCOld.SegmentCount - 1; j++) { ISegment pSegmentNEW = new LineClass(); ISegment pseg = psegCOld.Segment[j]; oldarrayS[0] = pseg.FromPoint.X; oldarrayS[1] = pseg.FromPoint.Y; if (pseg.FromPoint.Z.ToString() == "NaN" || pseg.FromPoint.Z.ToString() == "非数字") { oldarrayS[2] = 0; } else { oldarrayS[2] = pseg.FromPoint.Z; } matrix.coord_Trans(oldarrayS, rotateMat, tranVec, newarrayS); pPointF.X = newarrayS[0]; pPointF.Y = newarrayS[1]; if (pseg.FromPoint.Z.ToString() == "NaN" || pseg.FromPoint.Z.ToString() == "非数字") { pPointF.Z = 0; } else { pPointF.Z = newarrayS[2]; } pSegmentNEW.FromPoint = pPointF; oldarrayT[0] = pseg.ToPoint.X; oldarrayT[1] = pseg.ToPoint.Y; if (pseg.ToPoint.Z.ToString() == "NaN" || pseg.ToPoint.Z.ToString() == "非数字") { oldarrayT[2] = 0; } else { oldarrayT[2] = pseg.ToPoint.Z; } matrix.coord_Trans(oldarrayT, rotateMat, tranVec, newarrayT); pPointT.X = newarrayT[0]; pPointT.Y = newarrayT[1]; if (pseg.ToPoint.Z.ToString() == "NaN" || pseg.ToPoint.Z.ToString() == "非数字") { pPointT.Z = 0; } else { pPointT.Z = newarrayT[2]; } pSegmentNEW.ToPoint = pPointT; pSegCNew.AddSegment(pSegmentNEW); } IRing pRing = pSegCNew as IRing; pRing.Close(); object ob = Type.Missing; pGCollectionNew.AddGeometry(pRing as IGeometry, ref ob, ref ob); } IFeature pFeatureTemp = pFtClassNew.CreateFeature(); pFeatureTemp.Shape = pGCollectionNew as IGeometry; ClsGDBDataCommon.CopyFeatureFieldValue(pF, pFeatureTemp); pFeatureTemp.Store(); } pF = pFC.NextFeature(); } IFeatureLayer ppFeatureLayer = new FeatureLayerClass(); ppFeatureLayer.FeatureClass = pFtClassNew; ppFeatureLayer.Name = strName; pMapControl.AddLayer(ppFeatureLayer as ILayer); //pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); this.Close(); }
/// <summary> /// 根据传入的左邦点数组和右邦点数组生成巷道 /// </summary> /// <param name="tunnel"></param> /// <param name="pts"></param> /// <param name="editlayer"></param> public void DrawHuDong(TunnelEntity tunnel, WirePointInfoEntity[] pts, IFeatureLayer editlayer) { IPoint point = new PointClass(); IPointCollection4 pointCollection = new PolygonClass(); TunnelPointsCalculation TPC = new TunnelPointsCalculation(); Vector3_DW[] lstLeftBtmVertices = null; Vector3_DW[] lstRightBtmVertices = null; TPC.CalcLeftAndRightVertics(pts, ref lstLeftBtmVertices, ref lstRightBtmVertices); for (int intI = 0; intI < lstLeftBtmVertices.Length; intI++) { point.X = lstLeftBtmVertices[intI].X; point.Y = lstLeftBtmVertices[intI].Y; point.Z = lstLeftBtmVertices[intI].Z; pointCollection.AddPoint(point); } for (int intI = lstRightBtmVertices.Length; intI >= 0; intI--) { point.X = lstRightBtmVertices[intI].X; point.Y = lstRightBtmVertices[intI].Y; point.Z = lstRightBtmVertices[intI].Z; pointCollection.AddPoint(point); } IFeature f; IGeometryCollection polygon; //定义一个地物类,把要编辑的图层转化为定义的地物类 IFeatureClass fc = editlayer.FeatureClass; //先定义一个编辑的工作空间,然后把转化为数据集,最后转化为编辑工作空间, IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit; //开始事务操作 w.StartEditing(false); //开始编辑 w.StartEditOperation(); //创建一个地物 //绘制巷道 polygon = new PolygonClass(); IGeometryCollection pGeoColl = pointCollection as IGeometryCollection; ISegmentCollection pRing = new RingClass(); pRing.AddSegmentCollection(pGeoColl as ISegmentCollection); polygon.AddGeometry(pRing as IGeometry); IPolygon polyGonGeo = polygon as IPolygon; polyGonGeo.SimplifyPreserveFromTo(); f = fc.CreateFeature(); //polygon.PutCoords(Convert.ToDouble(ge.CoordinateX), Convert.ToDouble(ge.CoordinateY)); //确定图形类型 f.Shape = (IGeometry)polyGonGeo; //给巷道赋属性值 int num3; //num3 = editlayer.FeatureClass.Fields.FindField("OBJECTID"); //f.set_Value(num3, tunnel.TunnelID); num3 = editlayer.FeatureClass.Fields.FindField("MINE_NAME"); f.set_Value(num3, tunnel.MineName); num3 = editlayer.FeatureClass.Fields.FindField("HORIZONTAL"); f.set_Value(num3, tunnel.HorizontalName); num3 = editlayer.FeatureClass.Fields.FindField("MINING_AREA"); f.set_Value(num3, tunnel.MiningAreaName); num3 = editlayer.FeatureClass.Fields.FindField("WORKING_FACE"); f.set_Value(num3, tunnel.WorkingFaceName); num3 = editlayer.FeatureClass.Fields.FindField("TUNNEL_NAME"); f.set_Value(num3, tunnel.TunnelName); num3 = editlayer.FeatureClass.Fields.FindField("SUPPORT_PATTERN"); f.set_Value(num3, tunnel.TunnelSupportPattern); num3 = editlayer.FeatureClass.Fields.FindField("LITHOLOGY_ID"); f.set_Value(num3, tunnel.TunnelLithologyID); num3 = editlayer.FeatureClass.Fields.FindField("FAULTAGETYPE"); f.set_Value(num3, tunnel.TunnelSectionType); num3 = editlayer.FeatureClass.Fields.FindField("PARAM"); f.set_Value(num3, tunnel.TunnelParam); num3 = editlayer.FeatureClass.Fields.FindField("DESIGNLENGTH"); f.set_Value(num3, tunnel.TunnelDesignLength); //num3 = editlayer.FeatureClass.Fields.FindField("RULE_CODE"); //f.set_Value(num3, tunnel.r); //保存地物 f.Store(); //渲染巷道样式 ISimpleFillSymbol pFillSymbol; pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = getRGB(60, 100, 50); pFillSymbol.Outline.Color = getRGB(60, 100, 50); pFillSymbol.Outline.Width = 1; pFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; RenderfeatureLayer(editlayer, pFillSymbol as ISymbol); //结束编辑 w.StopEditOperation(); //结束事务操作 w.StopEditing(true); }
/// <summary> /// ������ʵ�� /// </summary> /// <param name="pITable">���ݱ����</param> /// <param name="entinyNode">VCT�ռ�ʵ��ڵ�</param> public override void CreateFeature(ITable pITable, EntityNode entinyNode) { PolygonNode pPolygonNode = entinyNode as PolygonNode; if (pPolygonNode != null) { IFeatureClass pFeatureCls = pITable as IFeatureClass; this.Feature = pFeatureCls.CreateFeature(); ///��ʶ�븳ֵ int dBSMIndex = -1; dBSMIndex = this.Feature.Fields.FindField(m_strEntityIDFiled); if (dBSMIndex != -1) this.Feature.set_Value(dBSMIndex, pPolygonNode.EntityID); ///Ҫ�ش��븳ֵ int dSYDMIndex = -1; dSYDMIndex = this.Feature.Fields.FindField(m_strYSDMField); if (dSYDMIndex != -1) this.Feature.set_Value(dSYDMIndex, pPolygonNode.FeatureCode); //���������������� bool bGetGeometry = false;///ָʾ�Ƿ��ȡͼ������ ///�����ñ��ȡ�������InDireCoordinatePolygon��ʾ������깹�� if (Metadata.MetaDataFile.GraphConfig.GetGraphMark("POLYGONFEATURETYPE", pPolygonNode.PolygonType.ToString()) == "InDireCoordinatePolygon") { IGeometryCollection pGeoCollection = new PolygonClass(); IPointCollection pPtCollection = new RingClass(); ///���ü�ӹ���ķ�ʽLineStructPolygon��ʾ�����߹��� if (Metadata.MetaDataFile.GraphConfig.GetGraphMark("POLYGONTYPE", pPolygonNode.ComposeType.ToString()) == "LineStructPolygon") { for (int i = 0; i < pPolygonNode.LineNodes.Count; i++) { LineNodeEx pLineNodeEx = pPolygonNode.LineNodes[i]; if (pLineNodeEx == null) continue; ///��ʶ��Ϊ0��ʾ����ָ��ʶ if (pLineNodeEx.EntityID != 0) { IPoint pPrePoint=null; if (pPtCollection.PointCount > 0) pPrePoint = pPtCollection.get_Point(pPtCollection.PointCount-1); IPointCollection pPointCollection=GetPointCollection(pLineNodeEx, pPrePoint); if (pPointCollection != null) pPtCollection.AddPointCollection(pPointCollection); if (i == pPolygonNode.LineNodes.Count - 1) { IRing pRing = pPtCollection as IRing; pRing.Close();///�պϵ�ǰ�� object oTypeMissing = Type.Missing; pGeoCollection.AddGeometry(pRing as IGeometry, ref oTypeMissing, ref oTypeMissing); bGetGeometry = true; pPtCollection = new RingClass();///��յ㼯���� } } else///������ʶ��Ϊ0ʱ�պ�ͼ�� { IRing pRing = pPtCollection as IRing; pRing.Close();///�պϵ�ǰ�� object oTypeMissing = Type.Missing; pGeoCollection.AddGeometry(pRing as IGeometry, ref oTypeMissing, ref oTypeMissing); bGetGeometry = true; pPtCollection = new RingClass();///��յ㼯���� } } if (bGetGeometry) { (this.Feature as IFeature).Shape = pGeoCollection as IGeometry; } } } else if (pPolygonNode.PolygonType == 1) { } this.Feature.Store(); } }
private IGeometry mergeSmallGeos(IGeometry geo) { ITopologicalOperator4 tp4 = (ITopologicalOperator4)geo; IGeometryCollection geoCol = new PolygonClass(); IGeometry bGeo = tp4.Boundary; ISpatialFilter spFilt = new SpatialFilter(); spFilt.Geometry = bGeo; spFilt.SearchOrder = esriSearchOrder.esriSearchOrderSpatial; spFilt.GeometryField = ftrCls.ShapeFieldName; spFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; spFilt.WhereClause = "Shape_Area <= " + minarea; spFilt.SubFields = ftrCls.ShapeFieldName; IFeatureCursor ftrCur = ftrCls.Search(spFilt, false); IFeature ftr = ftrCur.NextFeature(); int cntTest = 0; while (ftr != null) { IGeometry sGeo = ftr.ShapeCopy; geoCol.AddGeometry(sGeo); ftr.Delete(); ftr = ftrCur.NextFeature(); cntTest++; } if (cntTest > 0) { tp4.ConstructUnion((IEnumGeometry)geoCol); } return (IGeometry)tp4; }
public void ContructGeometry(IPoint point, List<KeyValuePair<int, double>> datasources, out List<KeyValuePair<string, IPolygon>> polygons, out List<IPoint> lineStartPoints, out List<IPoint> txtPoints) { _centerPoint = new PointClass { X = point.X, Y = point.Y }; polygons = new List<KeyValuePair<string, IPolygon>>(); lineStartPoints = new List<IPoint>(); txtPoints = new List<IPoint>(); var polygonBlack = new PolygonClass(); var polygonWhite = new PolygonClass(); _linepoints = lineStartPoints; _points = txtPoints; var indexLine = 0; var length = datasources.Sum(s => s.Value) * BL; var totalLength = length / 2; _halfHeight = length / 2; _height3 = _halfHeight + GeometryHeight1; _height4 = _halfHeight + GeometryHeight0 + GeometryHeight1; IPoint lastFromPoint = null; //IPoint lastToPoint = null; foreach (var d in datasources) { double dd = d.Value * BL; var list30 = new List<IPoint> { ConstructPoint(_centerPoint, 180, 90, totalLength), ConstructPoint(_centerPoint, 0, 90, totalLength), ConstructPoint(_centerPoint, 0, 90, totalLength - dd), ConstructPoint(_centerPoint, 180, 90, totalLength - dd), ConstructPoint(_centerPoint, 180, 90, totalLength) }; // 生成面 var geometry = ConstructRing(list30); if (d.Key == 0) { polygonWhite.AddGeometry(geometry); } else { polygonBlack.AddGeometry(geometry); } //int angleLine = indexLine % 2 == 0 ? 0 : 180; var fromPoint = list30[indexLine % 2 + 2]; //var toPoint = ConstructPoint3(fromPoint, angleLine, LineWidth); // 生成线 _linepoints.Add(fromPoint); lastFromPoint = list30[3]; //lastToPoint = ConstructPoint3(lastFromPoint, Angle2, LineWidth * 2); var txtPoint = new PointClass(); txtPoint.ConstructAngleDistance(fromPoint, (TextOffsetAngle + indexLine % 2 * 180) * Deg2Rad, TextOffsetDistance); // 生成点 _points.Add(txtPoint); totalLength -= dd; indexLine++; } if (lastFromPoint != null) { var txtLastPoint = new PointClass(); txtLastPoint.ConstructAngleDistance(lastFromPoint, 180 * Deg2Rad, LastTextOffsetDistance); // 生成点 _points.Add(txtLastPoint); // 生成线 _linepoints.Add(lastFromPoint); } polygonWhite.Close(); polygonBlack.Close(); var tPolygon = new PolygonClass(); polygons.Add(new KeyValuePair<string, IPolygon>("top", ContructGeometry(out tPolygon))); polygons.Add(new KeyValuePair<string, IPolygon>("top", tPolygon)); polygons.Add(new KeyValuePair<string, IPolygon>("white", polygonWhite)); polygons.Add(new KeyValuePair<string, IPolygon>("black", polygonBlack)); }
/// <summary> /// 创建面实体 /// </summary> /// <param name="pITable">数据表对象</param> /// <param name="entinyNode">VCT空间实体节点</param> public override void CreateFeature(ITable pITable, EntityNode entinyNode) { PolygonNode pPolygonNode = entinyNode as PolygonNode; if (pPolygonNode != null) { IFeatureClass pFeatureCls = pITable as IFeatureClass; this.Feature = pFeatureCls.CreateFeature(); ///标识码赋值 int dBSMIndex = -1; dBSMIndex = this.Feature.Fields.FindField(m_strEntityIDFiled); if (dBSMIndex != -1) this.Feature.set_Value(dBSMIndex, pPolygonNode.EntityID); ///要素代码赋值 int dSYDMIndex = -1; dSYDMIndex = this.Feature.Fields.FindField(m_strYSDMField); if (dSYDMIndex != -1) this.Feature.set_Value(dSYDMIndex, pPolygonNode.FeatureCode); //根据面特征类型构面 bool bGetGeometry = false;///指示是否获取图形数据 ///从配置表获取面的类型InDireCoordinatePolygon表示间接坐标构面 if (Metadata.MetaDataFile.GraphConfig.GetGraphMark("POLYGONFEATURETYPE", pPolygonNode.PolygonType.ToString()) == "InDireCoordinatePolygon") { IGeometryCollection pGeoCollection = new PolygonClass(); IPointCollection pPtCollection = new RingClass(); ///采用间接构面的方式LineStructPolygon表示引用线构面 if (Metadata.MetaDataFile.GraphConfig.GetGraphMark("POLYGONTYPE", pPolygonNode.ComposeType.ToString()) == "LineStructPolygon") { for (int i = 0; i < pPolygonNode.LineNodes.Count; i++) { LineNodeEx pLineNodeEx = pPolygonNode.LineNodes[i]; if (pLineNodeEx == null) continue; ///标识码为0表示对象分割标识 if (pLineNodeEx.EntityID != 0) { IPoint pPrePoint=null; if (pPtCollection.PointCount > 0) pPrePoint = pPtCollection.get_Point(pPtCollection.PointCount-1); IPointCollection pPointCollection=GetPointCollection(pLineNodeEx, pPrePoint); if (pPointCollection != null) pPtCollection.AddPointCollection(pPointCollection); if (i == pPolygonNode.LineNodes.Count - 1) { IRing pRing = pPtCollection as IRing; pRing.Close();///闭合当前环 object oTypeMissing = Type.Missing; pGeoCollection.AddGeometry(pRing as IGeometry, ref oTypeMissing, ref oTypeMissing); bGetGeometry = true; pPtCollection = new RingClass();///清空点集数据 } } else///独到标识码为0时闭合图形 { IRing pRing = pPtCollection as IRing; pRing.Close();///闭合当前环 object oTypeMissing = Type.Missing; pGeoCollection.AddGeometry(pRing as IGeometry, ref oTypeMissing, ref oTypeMissing); bGetGeometry = true; pPtCollection = new RingClass();///清空点集数据 } } if (bGetGeometry) { (this.Feature as IFeature).Shape = pGeoCollection as IGeometry; } } } else if (pPolygonNode.PolygonType == 1) { } this.Feature.Store(); } }
public static IPolygon CreatePolygon(object[] rings) { IPolygon result = null; IGeometryCollection pGeomCol = new PolygonClass(); object objMissing = Type.Missing; foreach (object o in rings)//part { object[] ringpoints = o as object[]; if (ringpoints != null) { ISegmentCollection pSegCol = new RingClass(); ISegment pSeg = new LineClass(); IPoint pFromPt = new PointClass(); IPoint pToPt = new PointClass(); IPoint pEndPt = new PointClass(); List <PointObject> poList = new List <PointObject>(); foreach (object po in ringpoints) { PointObject pObj = new PointObject(); object[] ptxya = po as object[]; if (ptxya != null) { if (ptxya.Length == 3) { pObj.X = double.Parse(ptxya[0].ToString()); pObj.Y = double.Parse(ptxya[1].ToString()); pObj.A = int.Parse(ptxya[2].ToString()); } else if (ptxya.Length == 2) { pObj.X = double.Parse(ptxya[0].ToString()); pObj.Y = double.Parse(ptxya[1].ToString()); pObj.A = 0; } else { throw new Exception("坐标串输入错误!"); } poList.Add(pObj); } } if (poList.Count < 3) { throw new Exception("至少保证三个点来确定一个面!"); } for (int i = 0; i < poList.Count - 1; i++) { if (poList[i].A.Equals(1))//处理狐段 { PointObject poF = null; PointObject poT = null; PointObject poE = null; if (i - 1 < 0) { poF = poList[poList.Count - 2]; } else { poF = poList[i - 1]; } poT = poList[i]; poE = poList[i + 1]; pFromPt.PutCoords(poF.X, poF.Y); pToPt.PutCoords(poT.X, poT.Y); pEndPt.PutCoords(poE.X, poE.Y); //圆弧 ICircularArc cirularArc = new CircularArcClass(); IConstructCircularArc constructCircularArc = cirularArc as IConstructCircularArc; constructCircularArc.ConstructThreePoints(pFromPt, pToPt, pEndPt, true); pSeg = cirularArc as ISegment; pSegCol.AddSegment(pSeg, ref objMissing, ref objMissing); } else { if (poList[i + 1].A.Equals(0))//处理直线,否则不处理 { pFromPt.PutCoords(poList[i].X, poList[i].Y); pToPt.PutCoords(poList[i + 1].X, poList[i + 1].Y); pSeg = new LineClass(); pSeg.FromPoint = pFromPt; pSeg.ToPoint = pToPt; //一根线段 pSegCol.AddSegment(pSeg, ref objMissing, ref objMissing); } } } //QI到IRing接口封闭Ring对象,使其有效 IRing pRing = pSegCol as IRing; pRing.Close(); //一个part pGeomCol.AddGeometry(pSegCol as IGeometry, ref objMissing, ref objMissing); } } result = pGeomCol as IPolygon; ITopologicalOperator pTop = result as ITopologicalOperator; pTop.Simplify(); return(result); }
public override void DrawOutFrame() { IPoint inPoint = new PointClass(); IPoint point2 = new PointClass(); IPoint point3 = new PointClass(); IPoint point4 = new PointClass(); IElement item = new PolygonElementClass(); IFillShapeElement element2 = item as IFillShapeElement; IGeometryCollection geometrys = new PolygonClass(); IElementProperties2 properties = null; object missing = System.Type.Missing; IGeometry inGeometry = new RingClass(); IGeometry geometry2 = new RingClass(); IPointCollection points = inGeometry as IPointCollection; try { if (!((base.LeftUp == null) || base.LeftUp.IsEmpty)) { inPoint.PutCoords(base.LeftUp.X - base.InOutDist, base.LeftUp.Y + base.InOutDist); points.AddPoint(inPoint, ref missing, ref missing); } if (!((base.LeftLow == null) || base.LeftLow.IsEmpty)) { point2.PutCoords(base.LeftLow.X - base.InOutDist, base.LeftLow.Y - base.InOutDist); points.AddPoint(point2, ref missing, ref missing); } if (!((base.RightLow == null) || base.RightLow.IsEmpty)) { point4.PutCoords(base.RightLow.X + base.InOutDist, base.RightLow.Y - base.InOutDist); points.AddPoint(point4, ref missing, ref missing); } if (!((base.RightUp == null) || base.RightUp.IsEmpty)) { point3.PutCoords(base.RightUp.X + base.InOutDist, base.RightUp.Y + base.InOutDist); points.AddPoint(point3, ref missing, ref missing); } if (!((base.LeftUp == null) || base.LeftUp.IsEmpty)) { inPoint.PutCoords(base.LeftUp.X - base.InOutDist, base.LeftUp.Y + base.InOutDist); points.AddPoint(inPoint, ref missing, ref missing); } geometrys.AddGeometry(inGeometry, ref missing, ref missing); points = geometry2 as IPointCollection; if (!((base.LeftUp == null) || base.LeftUp.IsEmpty)) { inPoint.PutCoords((base.LeftUp.X - base.InOutDist) - this.double_2, (base.LeftUp.Y + base.InOutDist) + this.double_2); points.AddPoint(inPoint, ref missing, ref missing); } if (!((base.LeftLow == null) || base.LeftLow.IsEmpty)) { point2.PutCoords((base.LeftLow.X - base.InOutDist) - this.double_2, (base.LeftLow.Y - base.InOutDist) - this.double_2); points.AddPoint(point2, ref missing, ref missing); } if (!((base.RightLow == null) || base.RightLow.IsEmpty)) { point4.PutCoords((base.RightLow.X + base.InOutDist) + this.double_2, (base.RightLow.Y - base.InOutDist) - this.double_2); points.AddPoint(point4, ref missing, ref missing); } if (!((base.RightUp == null) || base.RightUp.IsEmpty)) { point3.PutCoords((base.RightUp.X + base.InOutDist) + this.double_2, (base.RightUp.Y + base.InOutDist) + this.double_2); points.AddPoint(point3, ref missing, ref missing); } if (!((base.LeftUp == null) || base.LeftUp.IsEmpty)) { inPoint.PutCoords((base.LeftUp.X - base.InOutDist) - this.double_2, (base.LeftUp.Y + base.InOutDist) + this.double_2); points.AddPoint(inPoint, ref missing, ref missing); } geometrys.AddGeometry(geometry2, ref missing, ref missing); item.Geometry = geometrys as IGeometry; element2.Symbol = this.method_6(); properties = item as IElementProperties2; properties.Type = "外框"; this.ilist_0.Add(item); } catch (Exception exception) { MessageBox.Show(exception.Message); } }
private IPolygon ContructGeometry(out PolygonClass polygon1) { polygon1 = new PolygonClass(); var polygon = new PolygonClass(); var p00 = ConstructPoint(_centerPoint, Angle0, Angle1, _height4, 0); var p01 = ConstructPoint(_centerPoint, Angle2, Angle1, _height4); var p04 = ConstructPoint(_centerPoint, Angle0, Angle1, _height4); var list0 = new List<IPoint> { p01, ConstructPoint2(p01, Angle3, p00, Angle2 - Angle3), ConstructPoint2(p00, -Angle3, p04, Angle2 + Angle3), p04, ConstructPoint(_centerPoint, Angle0, Angle1, _height3), ConstructPoint(_centerPoint, Angle2, Angle1, _height3), p01 }; polygon1.AddGeometry(ConstructRing(list0)); var list1 = new List<IPoint> { p00, ConstructPoint2(p00, Angle3, p04, Angle2 - Angle3), p04, ConstructPoint2(p00, -Angle3, p04, Angle2 + Angle3), p00 }; polygon.AddGeometry(ConstructRing(list1)); var list2 = new List<IPoint> { ConstructPoint(_centerPoint, Angle2, Angle1, _height3), ConstructPoint(_centerPoint, Angle0, Angle1, _height3), ConstructPoint(_centerPoint, Angle0, Angle1, _halfHeight), ConstructPoint(_centerPoint, Angle2, Angle1, _halfHeight), ConstructPoint(_centerPoint, Angle2, Angle1, _height3) }; polygon.AddGeometry(ConstructRing(list2)); var list3 = new List<IPoint> { ConstructPoint(_centerPoint, Angle2, -Angle1, _height3), ConstructPoint(_centerPoint, Angle0, -Angle1, _height3), ConstructPoint(_centerPoint, Angle0, -Angle1, _halfHeight), ConstructPoint(_centerPoint, Angle2, -Angle1, _halfHeight), ConstructPoint(_centerPoint, Angle2, -Angle1, _height3) }; polygon.AddGeometry(ConstructRing(list3)); var p20 = ConstructPoint(_centerPoint, Angle0, -Angle1, _height4, 0); var p21 = ConstructPoint(_centerPoint, Angle2, -Angle1, _height4); var p24 = ConstructPoint(_centerPoint, Angle0, -Angle1, _height4); var list4 = new List<IPoint> { p21, ConstructPoint2(p21, Angle3, p20, Angle2 - Angle3), ConstructPoint2(p20, -Angle3, p24, Angle2 + Angle3), p24, ConstructPoint(_centerPoint, Angle0, -Angle1, _height3), ConstructPoint(_centerPoint, Angle2, -Angle1, _height3), p21 }; polygon1.AddGeometry(ConstructRing(list4)); var list5 = new List<IPoint> { p20, ConstructPoint2(p20, Angle2 - Angle3, p21, Angle3), p21, ConstructPoint2(p20, Angle2 + Angle3, p21, -Angle3), p20 }; polygon.AddGeometry(ConstructRing(list5)); polygon.Close(); return polygon; }
private IGeometry MakePolygonFromPointsList(List<IPoint> ptsList) { Ring ring = new RingClass(); object missing = Type.Missing; for (int i = 0; i < ptsList.Count; i++) { ring.AddPoint(ptsList[i]); } IGeometryCollection pointPolygon = new PolygonClass(); pointPolygon.AddGeometry(ring as IGeometry, ref missing, ref missing); IPolygon polygon = pointPolygon as IPolygon; polygon.SimplifyPreserveFromTo(); return polygon; }
/// <summary>Convert a GeoJSON Polygon geometry to Arcgis Geometry </summary> /// <param name="JSpoint">The deserialised GeoJson Object</param> /// <param name="epsg">The EPSG-code of the spatial reference, -1 is unknown</param> /// <returns>A Arcgis Polygon goemetry</returns> public static IPolygon geojson2esriPolygon(datacontract.geojsonPolygon JSPolygon, int epsg = -1) { Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment"); System.Object obj = Activator.CreateInstance(factoryType); ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3; IGeometryBridge2 pGeoBrg = new GeometryEnvironment() as IGeometryBridge2; IGeometryCollection esriGeometryCol = new PolygonClass(); for (int n = 0; n < JSPolygon.coordinates.Count; n++) { List<List<double>> JSring = JSPolygon.coordinates[n]; IPointCollection4 ring = new RingClass(); ESRI.ArcGIS.esriSystem.WKSPoint[] aWKSPointBuffer = new ESRI.ArcGIS.esriSystem.WKSPoint[JSring.Count]; for (int i = 0; i < JSring.Count; i++) { double[] xy = JSring[i].ToArray(); aWKSPointBuffer[i].X = xy[0]; aWKSPointBuffer[i].Y = xy[1]; } pGeoBrg.SetWKSPoints(ring , aWKSPointBuffer); esriGeometryCol.AddGeometry(ring as IGeometry, Type.Missing, Type.Missing); } IPolygon esriPolygon = esriGeometryCol as IPolygon; if (epsg != -1) { ISpatialReference srs = spatialReferenceFactory.CreateSpatialReference(epsg); esriPolygon.SpatialReference = srs; } return esriPolygon; }
public void OnMouseDown(int button, int shift, int x, int y) { if (button != 2) { try { IFeatureLayer targetLayer = Editor.UniqueInstance.TargetLayer; if (targetLayer != null) { IFeatureClass featureClass = targetLayer.FeatureClass; if (featureClass != null) { IPoint pGeometry = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); ISpatialFilter queryFilter = new SpatialFilterClass { Geometry = pGeometry, GeometryField = featureClass.ShapeFieldName, SubFields = featureClass.ShapeFieldName, SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin }; IFeatureCursor o = targetLayer.Search(queryFilter, false); IFeature feature = o.NextFeature(); IFeature feature2 = o.NextFeature(); Marshal.ReleaseComObject(o); o = null; if ((feature != null) && (feature2 != null)) { feature = featureClass.GetFeature(feature.OID); feature2 = featureClass.GetFeature(feature2.OID); ITopologicalOperator2 shape = feature.Shape as ITopologicalOperator2; IGeometry geometry1 = feature2.Shape; IGeometry other = shape.Intersect(feature2.Shape, esriGeometryDimension.esriGeometry2Dimension); if (!other.IsEmpty) { pGeometry = GISFunFactory.UnitFun.ConvertPoject(pGeometry, other.SpatialReference) as IPoint; IGeometryCollection geometrys = other as IGeometryCollection; if (geometrys.GeometryCount > 1) { for (int i = 0; i < geometrys.GeometryCount; i++) { IGeometry inGeometry = geometrys.get_Geometry(i); if (!inGeometry.IsEmpty) { if (inGeometry.GeometryType == esriGeometryType.esriGeometryRing) { object missing = System.Type.Missing; IGeometryCollection geometrys2 = new PolygonClass(); geometrys2.AddGeometry(inGeometry, ref missing, ref missing); IPolygon polygon = geometrys2 as IPolygon; inGeometry = polygon; } IRelationalOperator operator2 = inGeometry as IRelationalOperator; if ((operator2 != null) && operator2.Contains(pGeometry)) { other = inGeometry; break; } } } } else { IRelationalOperator operator3 = other as IRelationalOperator; if (!operator3.Contains(pGeometry)) { return; } } if (other != null) { feature = Editor.UniqueInstance.TargetLayer.FeatureClass.GetFeature(feature.OID); feature2 = Editor.UniqueInstance.TargetLayer.FeatureClass.GetFeature(feature2.OID); IList <IFeature> pList = new List <IFeature> { feature, feature2 }; OverlapSublot sublot = new OverlapSublot(this.m_hookHelper.Hook, pList) { Text = "合并", Tip = "请选择要保留重叠部分的小班ID" }; if (sublot.ShowDialog() == DialogResult.OK) { int selectedIndex = sublot.SelectedIndex; IFeature feature3 = null; if (selectedIndex == 0) { feature3 = feature2; } else { feature3 = feature; } if (other.GeometryType != esriGeometryType.esriGeometryPolygon) { IPolygon polygon2 = new PolygonClass { SpatialReference = other.SpatialReference }; IPointCollection newPoints = other as IPointCollection; (polygon2 as IPointCollection).AddPointCollection(newPoints); other = polygon2; } IGeometry geometry3 = (feature3.Shape as ITopologicalOperator2).Difference(other); if (geometry3.IsEmpty) { Editor.UniqueInstance.StartEditOperation(); feature3.Delete(); Editor.UniqueInstance.StopEditOperation(); } else { Editor.UniqueInstance.StartEditOperation(); feature3.Shape = geometry3; feature3.Store(); Editor.UniqueInstance.StopEditOperation(); IFeatureSelection selection = Editor.UniqueInstance.TargetLayer as IFeatureSelection; selection.Add(feature); selection.Add(feature2); } this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGeography, null, this.m_hookHelper.ActiveView.Extent); } sublot = null; MessageBox.Show("修改完成!", "提示"); } } } } } } catch (Exception exception) { Editor.UniqueInstance.AbortEditOperation(); this.mErrOpt.ErrorOperate(this.mSubSysName, "ShapeEdit.OverlapCombine", "OnMouseDown", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); MessageBox.Show("修改出错!", "提示"); } } }
static void CreateGrid(TileInfo tiles, int level, IFeatureWorkspace destination, String name) { ISpatialReferenceFactory2 sEnv = new SpatialReferenceEnvironment() as ISpatialReferenceFactory2; ISpatialReference sr = sEnv.CreateSpatialReference((int)tiles.spatialReference); sr.SetMDomain(-137434824702, 0); IFeatureClass fc = CreateFeatureClass(destination, name, sr); LOD lod = tiles.lods[level]; double width = tiles.width * lod.resolution; double height = tiles.height * lod.resolution; double y = tiles.originY; long row = 0; double maxX = -(tiles.originX + width); double minY = -(tiles.originY - height); while (y > minY) { double x = tiles.originX; long col = 0; while (x < maxX) { RingClass ring = new RingClass(); IPoint tl = new PointClass(); tl.PutCoords(x, y); tl.M = -(((col & 0xFFFF) << 16) + (row & 0xFFFF)); ring.AddPoint(tl); IPoint tr = new PointClass(); tr.PutCoords(x + width, y); tr.M = -((((col + 1) & 0xFFFF) << 16) + (row & 0xFFFF)); ring.AddPoint(tr); IPoint br = new PointClass(); br.PutCoords(x + width, y - width); br.M = -((((col + 1) & 0xFFFF) << 16) + ((row + 1) & 0xFFFF)); ring.AddPoint(br); IPoint bl = new PointClass(); bl.PutCoords(x, y - width); bl.M = -(((col & 0xFFFF) << 16) + ((row + 1) & 0xFFFF)); ring.AddPoint(bl); ring.AddPoint(tl); ring.Close(); PolygonClass polygon = new PolygonClass(); polygon.AddGeometry(ring); IFeature polyFeature = fc.CreateFeature(); polyFeature.Shape = polygon; polyFeature.Store(); x += width; col += 1; } row += 1; y -= height; } IFeatureClassDescriptor fd = new FeatureClassDescriptorClass(); fd.Create(fc, null, "OBJECTID"); }
public IPolygon GetBoundaryAsPolygon(IRasterProps props) { double left = props.Extent.XMin; double top = props.Extent.YMax; IPnt cellSize = props.MeanCellSize(); PolygonClass result = new PolygonClass(); object missing = Type.Missing; for (int x = 0; x <= m_Width; x += 1) { for (int y = 0; y <= m_Height; y += 1) { if ((!CellVisited(x, y)) && IsFilled(x, y) && (!IsFilled(x - 1, y))) { List<IntPoint> bmRing = GetCurve(x, y); RingClass ring = new RingClass(); foreach (IntPoint bmPt in bmRing) { PointClass point = new PointClass(); point.PutCoords(left + bmPt.X * cellSize.X, top - bmPt.Y * cellSize.Y); ring.AddPoint(point, ref missing, ref missing); } result.AddGeometry(ring, ref missing, ref missing); } } } return result; }
/// <summary> /// ��ת�� /// </summary> /// <params name="pPolyline"></params> /// <returns></returns> public static IPolygon PolylineToPolygon(IPolyline pPolyline) { IPolygon pPolygon = null; IGeometryCollection pGeometryCollection = new PolygonClass(); if (pPolyline != null && pPolyline.IsEmpty == false) { IGeometryCollection pPolylineGeoCol = pPolyline as IGeometryCollection; ISegmentCollection pSegCol = new RingClass(); ISegment pSegment = null; object missing = Type.Missing; for (int i = 0; i < pPolylineGeoCol.GeometryCount; i++) { ISegmentCollection pPolylineSegCol = pPolylineGeoCol.get_Geometry(i) as ISegmentCollection; for (int j = 0; j < pPolylineSegCol.SegmentCount; j++) { pSegment = pPolylineSegCol.get_Segment(j); pSegCol.AddSegment(pSegment, ref missing, ref missing); } pGeometryCollection.AddGeometry(pSegCol as IGeometry, ref missing, ref missing); } } pPolygon = pGeometryCollection as IPolygon; if (pPolygon.IsClosed == false) pPolygon.Close(); pPolygon.SpatialReference = DataEditCommon.g_pMyMapCtrl.SpatialReference; return pPolygon; }
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; } }
/// <summary> /// 根据传入的左邦点数组和右邦点数组生成巷道 /// </summary> /// <param name="tunnel"></param> /// <param name="pts"></param> /// <param name="editlayer"></param> public void DrawHuDong(TunnelEntity tunnel, WirePointInfoEntity[] pts, IFeatureLayer editlayer) { IPoint point = new PointClass(); IPointCollection4 pointCollection = new PolygonClass(); TunnelPointsCalculation TPC = new TunnelPointsCalculation(); Vector3_DW[] lstLeftBtmVertices = null; Vector3_DW[] lstRightBtmVertices = null; TPC.CalcLeftAndRightVertics(pts, ref lstLeftBtmVertices,ref lstRightBtmVertices); for (int intI = 0; intI < lstLeftBtmVertices.Length; intI++) { point.X = lstLeftBtmVertices[intI].X; point.Y = lstLeftBtmVertices[intI].Y; point.Z = lstLeftBtmVertices[intI].Z; pointCollection.AddPoint(point); } for (int intI = lstRightBtmVertices.Length; intI >=0; intI--) { point.X = lstRightBtmVertices[intI].X; point.Y = lstRightBtmVertices[intI].Y; point.Z = lstRightBtmVertices[intI].Z; pointCollection.AddPoint(point); } IFeature f; IGeometryCollection polygon; //定义一个地物类,把要编辑的图层转化为定义的地物类 IFeatureClass fc = editlayer.FeatureClass; //先定义一个编辑的工作空间,然后把转化为数据集,最后转化为编辑工作空间, IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit; //开始事务操作 w.StartEditing(false); //开始编辑 w.StartEditOperation(); //创建一个地物 //绘制巷道 polygon = new PolygonClass(); IGeometryCollection pGeoColl = pointCollection as IGeometryCollection; ISegmentCollection pRing = new RingClass(); pRing.AddSegmentCollection(pGeoColl as ISegmentCollection); polygon.AddGeometry(pRing as IGeometry); IPolygon polyGonGeo = polygon as IPolygon; polyGonGeo.SimplifyPreserveFromTo(); f = fc.CreateFeature(); //polygon.PutCoords(Convert.ToDouble(ge.CoordinateX), Convert.ToDouble(ge.CoordinateY)); //确定图形类型 f.Shape = (IGeometry)polyGonGeo; //给巷道赋属性值 int num3; //num3 = editlayer.FeatureClass.Fields.FindField("OBJECTID"); //f.set_Value(num3, tunnel.TunnelID); num3 = editlayer.FeatureClass.Fields.FindField("MINE_NAME"); f.set_Value(num3, tunnel.MineName); num3 = editlayer.FeatureClass.Fields.FindField("HORIZONTAL"); f.set_Value(num3, tunnel.HorizontalName); num3 = editlayer.FeatureClass.Fields.FindField("MINING_AREA"); f.set_Value(num3, tunnel.MiningAreaName); num3 = editlayer.FeatureClass.Fields.FindField("WORKING_FACE"); f.set_Value(num3, tunnel.WorkingFaceName); num3 = editlayer.FeatureClass.Fields.FindField("TUNNEL_NAME"); f.set_Value(num3, tunnel.TunnelName); num3 = editlayer.FeatureClass.Fields.FindField("SUPPORT_PATTERN"); f.set_Value(num3, tunnel.TunnelSupportPattern); num3 = editlayer.FeatureClass.Fields.FindField("LITHOLOGY_ID"); f.set_Value(num3, tunnel.TunnelLithologyID); num3 = editlayer.FeatureClass.Fields.FindField("FAULTAGETYPE"); f.set_Value(num3, tunnel.TunnelSectionType); num3 = editlayer.FeatureClass.Fields.FindField("PARAM"); f.set_Value(num3, tunnel.TunnelParam); num3 = editlayer.FeatureClass.Fields.FindField("DESIGNLENGTH"); f.set_Value(num3, tunnel.TunnelDesignLength); //num3 = editlayer.FeatureClass.Fields.FindField("RULE_CODE"); //f.set_Value(num3, tunnel.r); //保存地物 f.Store(); //渲染巷道样式 ISimpleFillSymbol pFillSymbol; pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = getRGB(60, 100, 50); pFillSymbol.Outline.Color = getRGB(60, 100, 50); pFillSymbol.Outline.Width = 1; pFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; RenderfeatureLayer(editlayer, pFillSymbol as ISymbol); //结束编辑 w.StopEditOperation(); //结束事务操作 w.StopEditing(true); }
private IList <IGeometry> GetGeometrys(IGeometry pGeo) { IList <IGeometry> list = new List <IGeometry>(); try { if (pGeo.GeometryType == esriGeometryType.esriGeometryPolyline) { IGeometryCollection geometrys = pGeo as IGeometryCollection; int geometryCount = geometrys.GeometryCount; for (int i = 0; i < geometryCount; i++) { IGeometry inGeometry = geometrys.get_Geometry(i); if (!inGeometry.IsEmpty) { IGeometryCollection geometrys2 = new PolylineClass(); object missing = System.Type.Missing; geometrys2.AddGeometry(inGeometry, ref missing, ref missing); IGeometry item = geometrys2 as IGeometry; item.SpatialReference = pGeo.SpatialReference; list.Add(item); } } return(list); } if (pGeo.GeometryType == esriGeometryType.esriGeometryPolygon) { IPolygon4 polygon = pGeo as IPolygon4; if (polygon.ExteriorRingCount < 2) { list.Add(pGeo); return(list); } IEnumGeometry exteriorRingBag = polygon.ExteriorRingBag as IEnumGeometry; exteriorRingBag.Reset(); for (IRing ring = exteriorRingBag.Next() as IRing; ring != null; ring = exteriorRingBag.Next() as IRing) { IGeometryBag bag2 = polygon.get_InteriorRingBag(ring); object before = System.Type.Missing; IGeometryCollection geometrys3 = null; geometrys3 = new PolygonClass(); geometrys3.AddGeometry(ring, ref before, ref before); IPolygon polygon2 = geometrys3 as IPolygon; polygon2.SpatialReference = pGeo.SpatialReference; ITopologicalOperator2 @operator = (ITopologicalOperator2)polygon2; @operator.IsKnownSimple_2 = false; @operator.Simplify(); if (!bag2.IsEmpty) { IGeometryCollection geometrys4 = new PolygonClass(); IEnumGeometry geometry4 = bag2 as IEnumGeometry; geometry4.Reset(); for (IRing ring2 = geometry4.Next() as IRing; ring2 != null; ring2 = geometry4.Next() as IRing) { geometrys4.AddGeometry(ring2, ref before, ref before); } IPolygon other = geometrys4 as IPolygon; other.SpatialReference = pGeo.SpatialReference; ITopologicalOperator2 operator2 = (ITopologicalOperator2)other; operator2.IsKnownSimple_2 = false; operator2.Simplify(); IGeometry geometry5 = @operator.Difference(other); list.Add(geometry5); } else { list.Add(polygon2); } } } return(list); } catch { return(null); } return(list); }
/// <summary> /// 通过线创建面 /// </summary> /// <param name="pPolyline">线</param> /// <returns>面</returns> IPolygon ConstructPolygonFromPolyline(IPolyline _pPolyline) { IGeometryCollection pPolygonGeoCol = new PolygonClass(); if ((_pPolyline != null) && (!_pPolyline.IsEmpty)) { IGeometryCollection pPolylineGeoCol = _pPolyline as IGeometryCollection; ISegmentCollection pSegCol = new RingClass(); ISegment pSegment = null; object missing = Type.Missing; for (int i = 0; i < pPolylineGeoCol.GeometryCount; i++) { ISegmentCollection pPolylineSegCol = pPolylineGeoCol.get_Geometry(i) as ISegmentCollection; for (int j = 0; j < pPolylineSegCol.SegmentCount; j++) { pSegment = pPolylineSegCol.get_Segment(j); pSegCol.AddSegment(pSegment, ref missing, ref missing); } pPolygonGeoCol.AddGeometry(pSegCol as IGeometry, ref missing, ref missing); } } return pPolygonGeoCol as IPolygon; }