[GIS] How to calculate cell tower polygon and get the coordinates in wkt format

javapolygon-creationpythonsoftware-recommendationswell-known-text

I have an use-case where I have to calculate the polygon of cell tower and store the polygon information in wkt format. I have got the following information regarding a cell tower.

  1. latitude
  2. longitude
  3. cell radius
  4. antenna direction (azimuth)
  5. radius extension (width in degree)

I am looking for an algorithm which uses the above attributes and derives the polygon, which I can save it in WKT format. The polygon would be of petal/teardrop shape (refer the diagram below). The cell radius forms the length of the petal and radius extension forms the width of the petal in degrees.

It would be helpful, if I can get a pointer to any library in Java or Python which I can use for the same.

enter image description here

Best Answer

This is a fairly simple operation in Java using GeoTools. All you need to do is start at the tower and travel out a distance (radius) in the direction (azimuth) - probably minus some width parameter, then round the arc (again the width parameter) and back to the tower.

private static final GeodeticCalculator CALC = new GeodeticCalculator(DefaultGeographicCRS.WGS84);
private static final GeometryFactory GF = new GeometryFactory();
private void createPolygon() {

    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[] {}));

  }

Writing the result out as WKT (or any other format) is easy:

  public String toString() {
    WKTWriter writer = new WKTWriter();
    return writer.write(poly);
  }

I've put the complete code here.

Related Question