@@ -0,0 +1,1986 @@
+package se.kodapan.osm.jts;%0A%0Aimport com.vividsolutions.jts.geom.Coordinate;%0Aimport com.vividsolutions.jts.geom.GeometryFactory;%0Aimport com.vividsolutions.jts.geom.Point;%0Aimport com.vividsolutions.jts.geom.Polygon;%0Aimport se.kodapan.osm.domain.Node;%0A%0Apublic class CircleOp %7B%0A%0A  public CircleOp() %7B%0A    this(new GeometryFactory());%0A  %7D%0A%0A  private GeometryFactory geometryFactory;%0A%0A  public CircleOp(GeometryFactory geometryFactory) %7B%0A    this.geometryFactory = geometryFactory;%0A  %7D%0A%0A  public Polygon circle(Point point, double radiusKilometers, int circumferenceResolution) %7B%0A    return circle(point.getCoordinate(), radiusKilometers, circumferenceResolution);%0A  %7D%0A%0A  public Polygon circle(Coordinate coordinate, double radiusKilometers, int circumferenceResolution) %7B%0A    return circle(coordinate.x, coordinate.y, radiusKilometers, circumferenceResolution);%0A  %7D%0A%0A  public Polygon circle(Node node, double radiusKilometers, int circumferenceResolution) %7B%0A    return circle(node.getLongitude(), node.getLatitude(), radiusKilometers, circumferenceResolution);%0A  %7D%0A%0A  public Polygon circle(double centroidLongitude, double centroidLatitude, double radiusKilometers, int circumferenceResolution) %7B%0A    Coordinate%5B%5D coordinates = new Coordinate%5BcircumferenceResolution + 1%5D;%0A%0A    double radiusLatitude = (radiusKilometers / 6378.8d) * (180 / Math.PI);%0A    double radiusLongitude = radiusLatitude / Math.cos(centroidLatitude * (Math.PI / 180));%0A%0A    int index = 0;%0A    int step = (int) (360d / (double) circumferenceResolution);%0A    for (int i = 0; i %3C 360; i += step) %7B%0A      double a = i * (Math.PI / 180);%0A      double latitude = centroidLatitude + (radiusLatitude * Math.sin(a));%0A      double longitude = centroidLongitude + (radiusLongitude * Math.cos(a));%0A      coordinates%5Bindex++%5D = new Coordinate(longitude, latitude);%0A    %7D%0A    coordinates%5Bcoordinates.length - 1%5D = coordinates%5B0%5D;%0A%0A    return geometryFactory.createPolygon(geometryFactory.createLinearRing(coordinates), null);%0A  %7D%0A%7D%0A

Creates a polygon in the shape of a circle