Search code examples
javagisgeotools

Creating a wedge shape with Geotools


I am on the hook for creating a service which will create a shape based on data provided with a center point. I am working with geotools which I am not very experienced with, however I am getting more familiar with it.

I am receiving data which looks like this:

{
    "shape": {
    "latitude": 43.87,
    "longitude": -103.45,
    "parameters": [
        0.0,
        120.0,
        1000.0
    ],
    "shapeString": "WEDGE (-103.45,43.87) AZIMUTH:0.0 ANGLE:120.0 RADIUS:1000.0"
  }
}

I am assuming there is a way to create this shape in geotools but I am just so unfamiliar with it I haven't been able to do it. I have seen the ability to create polygons, however it looks like I would have to have several sets of lat,lon to create that type of shape.


Solution

  • I wrote a program to solve a similar problem some time ago.

    Basically, the trick is to use the GeodeticCalculator to work out the coordinates of the curved section of the wedge and the join the start and end to the starting point.

    ArrayList<Coordinate> coords = new ArrayList<>();
    // start at the tower
    coords.add(point.getCoordinate());
    // next the edge of the wedge
    int nSteps = 10;
    // assume width of 10 degrees
    double width = 10.0;
    double dStep = width/nSteps;
    for (int i = -nSteps; i < nSteps; i++) {
      CALC.setStartingGeographicPoint(point.getX(), point.getY());
      CALC.setDirection((azimuth +(i*dStep)), radius);
      Point2D p = CALC.getDestinationGeographicPoint();
      coords.add(new Coordinate(p.getX(), p.getY()));
    }
    // end at the tower
    coords.add(point.getCoordinate());
    poly = GF.createPolygon(coords.toArray(new Coordinate[] {}));