/// <summary> /// Creates a circular Polygon. /// </summary> /// <returns> A circle. </returns> public virtual Polygon CreateCircle() { Envelope env = dim.Envelope; double xRadius = env.Width / 2.0; double yRadius = env.Height / 2.0; double centreX = env.MinX + xRadius; double centreY = env.MinY + yRadius; Coordinate[] pts = new Coordinate[nPts + 1]; int iPt = 0; for (int i = 0; i < nPts; i++) { double ang = i * (2 * Math.PI / nPts); double x = xRadius * Math.Cos(ang) + centreX; double y = yRadius * Math.Sin(ang) + centreY; Coordinate pt = new Coordinate(x, y); pts[iPt++] = pt; } pts[iPt] = pts[0]; if (geomFact != null) { LinearRing ring = geomFact.CreateLinearRing(pts); Polygon poly = geomFact.CreatePolygon(ring, null); return(poly); } else { LinearRing ring = this.CreateLinearRing(pts); Polygon poly = this.CreatePolygon(ring, null); return(poly); } }
/// <summary> /// Constructs a Polygon with the given exterior boundary and /// interior boundaries. /// /// </summary> /// <param name="">shell /// the outer boundary of the new Polygon, or /// null or an empty LinearRing if /// the empty geometry is to be created. /// </param> /// <param name="">holes /// the inner boundaries of the new Polygon, or /// null or empty LinearRing s if /// the empty geometry is to be created. /// </param> public virtual Polygon CreatePolygon(LinearRing shell, LinearRing[] holes) { return(new Polygon(shell, holes, this)); }
/// <summary> /// Creates a rectangular Polygon. /// </summary> /// <returns> A rectangular Polygon </returns> public virtual Polygon CreateRectangle() { int i; int ipt = 0; int nSide = nPts / 4; if (nSide < 1) { nSide = 1; } double XsegLen = dim.Envelope.Width / nSide; double YsegLen = dim.Envelope.Height / nSide; Coordinate[] pts = new Coordinate[4 * nSide + 1]; Envelope env = dim.Envelope; // double maxx = env.MinX + nSide * XsegLen; // double maxy = env.MinY + nSide * XsegLen; for (i = 0; i < nSide; i++) { double x = env.MinX + i * XsegLen; double y = env.MinY; pts[ipt++] = new Coordinate(x, y); } for (i = 0; i < nSide; i++) { double x = env.MaxX; double y = env.MinY + i * YsegLen; pts[ipt++] = new Coordinate(x, y); } for (i = 0; i < nSide; i++) { double x = env.MaxX - i * XsegLen; double y = env.MaxY; pts[ipt++] = new Coordinate(x, y); } for (i = 0; i < nSide; i++) { double x = env.MinX; double y = env.MaxY - i * YsegLen; pts[ipt++] = new Coordinate(x, y); } pts[ipt++] = new Coordinate(pts[0]); if (geomFact != null) { LinearRing ring = geomFact.CreateLinearRing(pts); Polygon poly = geomFact.CreatePolygon(ring, null); return(poly); } else { LinearRing ring = this.CreateLinearRing(pts); Polygon poly = this.CreatePolygon(ring, null); return(poly); } }