/** * Creates a elliptical arc, as a LineString. * * @return an elliptical arc */ public LineString createArc(double startAng, double endAng) { Envelope env = dim.getEnvelope(); double xRadius = env.getWidth() / 2.0; double yRadius = env.getHeight() / 2.0; double centreX = env.getMinX() + xRadius; double centreY = env.getMinY() + yRadius; double angSize = (endAng - startAng); if (angSize <= 0.0 || angSize > 2 * Math.PI) angSize = 2 * Math.PI; double angInc = angSize / nPts; Coordinate[] pts = new Coordinate[nPts]; int iPt = 0; for (int i = 0; i < nPts; i++) { double ang = startAng + i * angInc; double x = xRadius * Math.cos(ang) + centreX; double y = yRadius * Math.sin(ang) + centreY; Coordinate pt = new Coordinate(x, y); geomFact.getPrecisionModel().makePrecise(pt); pts[iPt++] = pt; } LineString line = geomFact.createLineString(pts); return line; }
/** * Creates a rectangular {@link Polygon}. * * @return a rectangular Polygon */ public Polygon createRectangle() { int i; int ipt = 0; int nSide = nPts / 4; if (nSide < 1) nSide = 1; double XsegLen = dim.getEnvelope().getWidth() / nSide; double YsegLen = dim.getEnvelope().getHeight() / nSide; Coordinate[] pts = new Coordinate[4 * nSide + 1]; Envelope env = dim.getEnvelope(); double maxx = env.getMinX() + nSide * XsegLen; double maxy = env.getMinY() + nSide * XsegLen; for (i = 0; i < nSide; i++) { double x = env.getMinX() + i * XsegLen; double y = env.getMinY(); pts[ipt++] = new Coordinate(x, y); } for (i = 0; i < nSide; i++) { double x = env.getMaxX(); double y = env.getMinY() + i * YsegLen; pts[ipt++] = new Coordinate(x, y); } for (i = 0; i < nSide; i++) { double x = env.getMaxX() - i * XsegLen; double y = env.getMaxY(); pts[ipt++] = new Coordinate(x, y); } for (i = 0; i < nSide; i++) { double x = env.getMinX(); double y = env.getMaxY() - i * YsegLen; pts[ipt++] = new Coordinate(x, y); } pts[ipt++] = new Coordinate(pts[0]); LinearRing ring = geomFact.createLinearRing(pts); Polygon poly = geomFact.createPolygon(ring, null); return poly; }
/** * Creates a circular {@link Polygon}. * * @return a circle */ public Polygon createCircle() { Envelope env = dim.getEnvelope(); double xRadius = env.getWidth() / 2.0; double yRadius = env.getHeight() / 2.0; double centreX = env.getMinX() + xRadius; double centreY = env.getMinY() + 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]; LinearRing ring = geomFact.createLinearRing(pts); Polygon poly = geomFact.createPolygon(ring, null); return poly; }