JsonNode.java

  1. package org.heigit.ors.api.responses.export.json;

  2. import com.fasterxml.jackson.annotation.JsonFormat;
  3. import com.fasterxml.jackson.annotation.JsonProperty;
  4. import io.swagger.v3.oas.annotations.media.Schema;
  5. import org.heigit.ors.util.FormatUtility;
  6. import org.locationtech.jts.geom.Coordinate;

  7. import java.util.Map;

  8. public class JsonNode {
  9.     protected static final int COORDINATE_DECIMAL_PLACES = 6;

  10.     @Schema(description = "Id of the corresponding node in the graph", example = "1")
  11.     @JsonProperty(value = "nodeId")
  12.     @JsonFormat(shape = JsonFormat.Shape.NUMBER)
  13.     protected Integer nodeId;

  14.     @Schema(description = "{longitude},{latitude} coordinates of the closest accessible point on the routing graph",
  15.             example = "[8.678962, 49.40783]")
  16.     @JsonProperty(value = "location")
  17.     @JsonFormat(shape = JsonFormat.Shape.ARRAY)
  18.     protected Coordinate location;

  19.     JsonNode(Map.Entry<Integer, Coordinate> location) {
  20.         this.nodeId = location.getKey();
  21.         this.location = location.getValue();
  22.     }

  23.     public Double[] getLocation() {
  24.         Double[] coord2D = new Double[2];
  25.         coord2D[0] = FormatUtility.roundToDecimals(location.x, COORDINATE_DECIMAL_PLACES);
  26.         coord2D[1] = FormatUtility.roundToDecimals(location.y, COORDINATE_DECIMAL_PLACES);
  27.         // coord2D[3] = location.z; --> example for third dimension
  28.         return coord2D;
  29.     }
  30. }