/** * Creates a circular or elliptical {@link Polygon}. * * @return a circle or ellipse */ public Polygon createCircle() { return createEllipse(); }
pts[iPt++] = coord(centreX, centreY); for (int i = 0; i < nPts; i++) { double ang = startAng + angInc * i; pts[iPt++] = coord(x, y); pts[iPt++] = coord(centreX, centreY); LinearRing ring = geomFact.createLinearRing(pts); Polygon poly = geomFact.createPolygon(ring, null); return (Polygon) rotate(poly);
public static Geometry createCircle(double x, double y, final double RADIUS) { GeometricShapeFactory shapeFactory = new GeometricShapeFactory(); shapeFactory.setNumPoints(32); shapeFactory.setCentre(new Coordinate(x, y)); shapeFactory.setSize(RADIUS * 2); return shapeFactory.createCircle(); }
// method to create your rectangles like before (Polygon objects) public static Polygon createPolygon(Coordinate center, double width, double height){ GeometricShapeFactory shapeFactory = new GeometricShapeFactory(); shapeFactory.setNumPoints(4); shapeFactory.setCentre(center); shapeFactory.setWidth(width); shapeFactory.setHeight(height); return shapeFactory.createRectangle(); } // create your rectagles Polygon rectangleA = createPolygon(new Coordinate(0, 0), 5, 10); Polygon rectangleB = createPolygon(new Coordinate(2, 0), 5, 10); // ### check your constraints // 1. rectangle is within the reference rectangle boolean bWithinA = rectangleB.within(rectangleA); // 2. rectangle is overlapping the reference rectangle boolean bOverlappingA = rectangleB.overlaps(rectangleA); // 3. rectangle is only sharing a border with the reference rectangle boolean bSharesBorderA = rectangleB.touches(rectangleA); // 2. rectangle and reference rectangle are distinct boolean bDistinctsA = rectangleB.disjoint(rectangleA);
/** * Make an ellipse centered at the given point with the given width and * height. * * @param p Point * @param width Width * @param height Height * @return An ellipse centered at the given point with the given width and height * @throws SQLException if the width or height is non-positive */ public static Polygon makeEllipse(Point p, double width, double height) throws SQLException { if(p == null){ return null; } if (height < 0 || width < 0) { throw new SQLException("Both width and height must be positive."); } else { GSF.setCentre(new Coordinate(p.getX(), p.getY())); GSF.setWidth(width); GSF.setHeight(height); return GSF.createEllipse(); } } }
import com.vividsolutions.jts.util.* GeometricShapeFactory gsf = new GeometricShapeFactory(); gsf.setSize(100); gsf.setNumPoints(100); gsf.setBase(new Coordinate(100, 100)); //configure the circle as appropriate Polygon circleA = gsf.createCircle(); //configure again and create a separate circle Polygon circleB = gsf.createCircle(); //configure a rectangle this time Polygon rectangle = gsf.createRectangle(); Geometry circleIntersection = circleA.intersection(circleB); return rectangle.intersects(circleIntersection);
public final class GeometryBuilder { private static final int DIAMETER_MULTIPLIER = 2; private static final int TURN_LEFT = 90; //We should start to roll to the right from "North"/"Up"/12 o'clock private GeometryBuilder(){} public static Circle buildCirlce(GeoPoint centerOfCircle, GeoPoint relativeCenter, Distance radiusDistance){ GeometricShapeFactory geometricShapeFactory = new GeometricShapeFactory(); geometricShapeFactory.setCentre(GeometryUtil.toCoordinate(centerOfCircle, relativeCenter)); geometricShapeFactory.setSize(radiusDistance.getMeters() * DIAMETER_MULTIPLIER); return new Circle(geometricShapeFactory.createEllipse()); } public static Sector buildGSMCellSector(GSMCellLocation gsmCellLocation, GeoPoint relativeCenter){ GeometricShapeFactory geometricShapeFactory = new GeometricShapeFactory(); geometricShapeFactory.setCentre(GeometryUtil.toCoordinate(gsmCellLocation.getGeoPoint(), relativeCenter)); geometricShapeFactory.setSize(gsmCellLocation.getMidDist() * DIAMETER_MULTIPLIER); return new Sector(geometricShapeFactory.createArcPolygon(-toRadians(gsmCellLocation.getEndAngle()- TURN_LEFT), toRadians(gsmCellLocation.getAngleWidth()))); } }
protected Coordinate coordTrans(double x, double y, Coordinate trans) { return coord(x + trans.x, y + trans.y); }
private static Geometry createCircle(double x, double y, final double RADIUS) { GeometricShapeFactory shapeFactory = new GeometricShapeFactory(); shapeFactory.setNumPoints(32); shapeFactory.setCentre(new Coordinate(x, y)); shapeFactory.setSize(RADIUS * 2); return shapeFactory.createCircle(); }
/** * Make an ellipse centered at the given point with the given width and * height. * * @param p Point * @param width Width * @param height Height * @return An ellipse centered at the given point with the given width and height * @throws SQLException if the width or height is non-positive */ public static Polygon makeEllipse(Point p, double width, double height) throws SQLException { if(p == null){ return null; } if (height < 0 || width < 0) { throw new SQLException("Both width and height must be positive."); } else { GSF.setCentre(new Coordinate(p.getX(), p.getY())); GSF.setWidth(width); GSF.setHeight(height); return GSF.createEllipse(); } } }
protected Coordinate coordTrans(double x, double y, Coordinate trans) { return coord(x + trans.x, y + trans.y); }
Coordinate center = new Coordinate(entity.getLongitude(), entity.getLatitude()); GeometricShapeFactory gsf = new GeometricShapeFactory(); gsf.setCentre(center); gsf.setNumPoints(20); gsf.setSize(10.2); Polygon poly = gsf.createCircle(); Coordinate[] coordArray = poly.getCoordinates();
/** * Creates an elliptical {@link Polygon}. * If the supplied envelope is square the * result will be a circle. * * @return an ellipse or circle */ public Polygon createEllipse() { 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; pts[iPt++] = coord(x, y); } pts[iPt] = new Coordinate(pts[0]); LinearRing ring = geomFact.createLinearRing(pts); Polygon poly = geomFact.createPolygon(ring, null); return (Polygon) rotate(poly); } /**
/** * Creates a circular or elliptical {@link Polygon}. * * @return a circle or ellipse */ public Polygon createCircle() { return createEllipse(); }
if (circle.getBoundingBox().getCrossesDateLine()) throw new IllegalArgumentException("Doesn't support dateline cross yet: "+circle);//TODO GeometricShapeFactory gsf = new GeometricShapeFactory(geometryFactory); gsf.setSize(circle.getBoundingBox().getWidth()); gsf.setNumPoints(4*25);//multiple of 4 is best gsf.setCentre(new Coordinate(circle.getCenter().getX(), circle.getCenter().getY())); return gsf.createCircle();
if (circle.getBoundingBox().getCrossesDateLine()) throw new IllegalArgumentException("Doesn't support dateline cross yet: "+circle);//TODO GeometricShapeFactory gsf = new GeometricShapeFactory(geometryFactory); gsf.setSize(circle.getBoundingBox().getWidth()); gsf.setNumPoints(4*25);//multiple of 4 is best gsf.setCentre(new Coordinate(circle.getCenter().getX(), circle.getCenter().getY())); return gsf.createCircle();
pts[iPt++] = coord(centreX, centreY); for (int i = 0; i < nPts; i++) { double ang = startAng + angInc * i; pts[iPt++] = coord(x, y); pts[iPt++] = coord(centreX, centreY); LinearRing ring = geomFact.createLinearRing(pts); Polygon poly = geomFact.createPolygon(ring, null); return (Polygon) rotate(poly);
/** * Creates an elliptical {@link Polygon}. * If the supplied envelope is square the * result will be a circle. * * @return an ellipse or circle */ public Polygon createEllipse() { 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; pts[iPt++] = coord(x, y); } pts[iPt] = new Coordinate(pts[0]); LinearRing ring = geomFact.createLinearRing(pts); Polygon poly = geomFact.createPolygon(ring, null); return (Polygon) rotate(poly); } /**