/** * Calls {@link #calcConnectedLatLonBoundaryPoints(int, int)} with {@link Integer#MAX_VALUE} as both arguments. * In effect, the boundary will contain ALL of the points along the edges of the CRS. * * @return the connected latitude/longitude boundary of this CRS. */ public List<LatLonPointNoNormalize> calcConnectedLatLonBoundaryPoints() { return calcConnectedLatLonBoundaryPoints(Integer.MAX_VALUE, Integer.MAX_VALUE); }
/** * Similar to {@link #getLatLonBoundaryAsWKT}, but returns a GeoJSON polygon instead. */ public String getLatLonBoundaryAsGeoJSON(int maxPointsInYEdge, int maxPointsInXEdge) { List<LatLonPointNoNormalize> points = calcConnectedLatLonBoundaryPoints(maxPointsInYEdge, maxPointsInXEdge); StringBuilder sb = new StringBuilder("{ 'type': 'Polygon', 'coordinates': [ [ "); for (LatLonPointNoNormalize point : points) { sb.append(String.format("[%.3f, %.3f], ", point.getLongitude(), point.getLatitude())); } sb.delete(sb.length() - 2, sb.length()); // Nuke trailing comma and space. sb.append(" ] ] }"); return sb.toString(); } }
/** * Returns the {@link #calcConnectedLatLonBoundaryPoints(int, int) latitude/longitude boundary} of this coordinate * reference system as a polygon in WKT. It is used in the OpenLayers map in NCSS, as well as the * "datasetBoundaries" endpoint. * * @param maxPointsInYEdge the maximum number of boundary points to include from the right and left edges. * @param maxPointsInXEdge the maximum number of boundary points to include from the bottom and top edges. * @return the latitude/longitude boundary of this CRS as a polygon in WKT. */ public String getLatLonBoundaryAsWKT(int maxPointsInYEdge, int maxPointsInXEdge) { List<LatLonPointNoNormalize> points = calcConnectedLatLonBoundaryPoints(maxPointsInYEdge, maxPointsInXEdge); StringBuilder sb = new StringBuilder("POLYGON(("); for (LatLonPointNoNormalize point : points) { sb.append(String.format("%.3f %.3f, ", point.getLongitude(), point.getLatitude())); } sb.delete(sb.length() - 2, sb.length()); // Nuke trailing comma and space. sb.append("))"); return sb.toString(); }
/** * Calculates the bounding box of this coordinate reference system, in latitude/longitude. This method properly * handles coverages that straddle the international date line by deriving its bounding box from the * {@link #calcConnectedLatLonBoundaryPoints(int, int) connected latitude/longitude boundary}. * <p> * If this CRS {@link #isProjection is a projection}, its lat/lon boundary is computed by converting each point * in its {@link #calcProjectionBoundaryPoints() projection boundary} to latitude/longitude using the * {@link Projection projection}. * * @return the bounding box of this CRS, in latitude/longitude. */ public LatLonRect calcLatLonBoundingBox() { double minLat = Double.MAX_VALUE; double minLon = Double.MAX_VALUE; double maxLat = -Double.MAX_VALUE; double maxLon = -Double.MAX_VALUE; for (LatLonPointNoNormalize boundaryPoint : calcConnectedLatLonBoundaryPoints()) { minLat = Math.min(minLat, boundaryPoint.getLatitude()); minLon = Math.min(minLon, boundaryPoint.getLongitude()); maxLat = Math.max(maxLat, boundaryPoint.getLatitude()); maxLon = Math.max(maxLon, boundaryPoint.getLongitude()); } return new LatLonRect(new LatLonPointImpl(minLat, minLon), new LatLonPointImpl(maxLat, maxLon)); }