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 IGeometry ConstructRing(IEnumerable <IPoint> points) { var r = new RingClass(); foreach (var point in points) { r.AddPoint(point); } r.Close(); return(r); }
private void EnvelopeToPolygon(IEnvelope ev) //把envelope变为polygon { IRing ring = new RingClass(); object missing1 = Type.Missing; object missing2 = Type.Missing; (ring as IPointCollection).AddPoint(ev.LowerLeft, ref missing1, ref missing2); (ring as IPointCollection).AddPoint(ev.UpperLeft, ref missing1, ref missing2); (ring as IPointCollection).AddPoint(ev.UpperRight, ref missing1, ref missing2); (ring as IPointCollection).AddPoint(ev.LowerRight, ref missing1, ref missing2); (ring as IPointCollection).AddPoint(ev.LowerLeft, ref missing1, ref missing2); ring.Close(); IPolygon p = new PolygonClass(); (p as IGeometryCollection).AddGeometry(ring, ref missing1, ref missing2); p.SimplifyPreserveFromTo(); polygon = p as IPolygon; }
private static IPolygon CreatePunchedSquarePolygon( double xOffset, double yOffset, double sideLength, int holes, int pointsPerPart, double z, int rotateSteps, ISpatialReference sr) { var holesInXAndY = (int)Math.Round(Math.Sqrt(holes)); var pointsPerSide = (int)Math.Round(pointsPerPart / 4.0); IPolygon polygon = new PolygonClass(); polygon.SpatialReference = sr; GeometryUtils.MakeZAware(polygon); var geoColl = (IGeometryCollection)polygon; object missing = Type.Missing; // Create and add the outer ring WKSPointZ[] pointArray = CreateSquare(xOffset, yOffset, sideLength, pointsPerSide, true, z); CollectionUtils.Rotate(pointArray, rotateSteps); IRing ring = new RingClass(); GeometryUtils.SetWKSPointZs((IPointCollection4)ring, pointArray); ring.Close(); geoColl.AddGeometry(ring, ref missing, ref missing); // Create and add inner rings (= holes) double innerSideLength = sideLength / (1 + (2 * holesInXAndY)); for (var i = 0; i < holesInXAndY; i++) { double llx = xOffset + (innerSideLength + 2 * i * innerSideLength); for (var j = 0; j < holesInXAndY; j++) { double lly = yOffset + (innerSideLength + 2 * j * innerSideLength); pointArray = CreateSquare(llx, lly, innerSideLength, pointsPerSide, false, z); CollectionUtils.Rotate(pointArray, rotateSteps); ring = new RingClass(); GeometryUtils.SetWKSPointZs((IPointCollection4)ring, pointArray); ring.Close(); geoColl.AddGeometry(ring, ref missing, ref missing); } } geoColl.GeometriesChanged(); polygon.SimplifyPreserveFromTo(); // We closed each ring: poly must be closed too! Assert.IsTrue(polygon.IsClosed); return(polygon); }
private void btnAddFeature_Click(object sender, EventArgs e) { IPoint pPoint1 = new PointClass(); pPoint1.PutCoords(82.1935, 21.5459); IPoint pPoint2 = new PointClass(); pPoint2.PutCoords(89.0913, 21.6609); IPoint pPoint3 = new PointClass(); pPoint3.PutCoords(88.9763, 15.6828); IPoint pPoint4 = new PointClass(); pPoint4.PutCoords(79.7793, 15.5679); // 创建一个环 IRing pRing = new RingClass(); ISegmentCollection pSegmentCollection = pRing as ISegmentCollection; object Missing1 = Type.Missing; object Missing2 = Type.Missing; ILine pLine = new LineClass(); pLine.PutCoords(pPoint1, pPoint2); pSegmentCollection.AddSegment(pLine as ISegment, ref Missing1, ref Missing2); pLine = new LineClass(); pLine.PutCoords(pPoint2, pPoint3); pSegmentCollection.AddSegment(pLine as ISegment, ref Missing1, ref Missing2); pLine = new LineClass(); pLine.PutCoords(pPoint3, pPoint4); pSegmentCollection.AddSegment(pLine as ISegment, ref Missing1, ref Missing2); pLine = new LineClass(); pLine.PutCoords(pPoint4, pPoint1); pSegmentCollection.AddSegment(pLine as ISegment, ref Missing1, ref Missing2); pRing.Close(); // 创建多边形 IPolygon pPolygon = new PolygonClass(); IGeometryCollection pGeometryCollection = pPolygon as IGeometryCollection; pGeometryCollection.AddGeometry(pRing, ref Missing1, ref Missing2); // 显示多边形 ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Blue = 0; pColor.Green = 0; pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross; pSimpleFillSymbol.Color = pColor; IFillShapeElement pFillShapeElement = new PolygonElementClass(); pFillShapeElement.Symbol = pSimpleFillSymbol; IElement pElement = pFillShapeElement as IElement; pElement.Geometry = pPolygon as IGeometry; IGraphicsContainer pGraphicsContainer = MainMap.Map as IGraphicsContainer; pGraphicsContainer.AddElement(pElement, 0); MainMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
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"); }
private IGeometry ConstructRing(IEnumerable<IPoint> points) { var r = new RingClass(); foreach (var point in points) { r.AddPoint(point); } r.Close(); return r; }