All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opengis.cite.ogcapifeatures10.util.BBox Maven / Gradle / Ivy

package org.opengis.cite.ogcapifeatures10.util;

import static org.opengis.cite.ogcapifeatures10.OgcApiFeatures10.DEFAULT_CRS;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Objects;

import org.opengis.cite.ogcapifeatures10.conformance.crs.query.crs.CoordinateSystem;

/**
 * 

* BBox class. *

* * @author Lyn Goltz */ public class BBox { private static final String PATTERN = "###.0000000"; private final double minX; private final double minY; private final double maxX; private final double maxY; private final CoordinateSystem crs; /** *

* Constructor for BBox. *

* @param minX Lower left corner, coordinate axis 1 * @param minY Lower left corner, coordinate axis 2 * @param maxX Upper right corner, coordinate axis 1 * @param maxY Upper right corner, coordinate axis 2 */ public BBox(double minX, double minY, double maxX, double maxY) { this(minX, minY, maxX, maxY, DEFAULT_CRS); } /** *

* Constructor for BBox. *

* @param minX Lower left corner, coordinate axis 1 * @param minY Lower left corner, coordinate axis 2 * @param maxX Upper right corner, coordinate axis 1 * @param maxY Upper right corner, coordinate axis 2 * @param crs CRS of the bbox, may be null */ public BBox(double minX, double minY, double maxX, double maxY, CoordinateSystem crs) { this.minX = minX; this.minY = minY; this.maxX = maxX; this.maxY = maxY; this.crs = crs; } /** *

* Getter for the field minX. *

* @return Lower left corner, coordinate axis 1 */ public double getMinX() { return minX; } /** *

* Getter for the field minY. *

* @return Lower left corner, coordinate axis 2 */ public double getMinY() { return minY; } /** *

* Getter for the field maxX. *

* @return Upper right corner, coordinate axis 1 */ public double getMaxX() { return maxX; } /** *

* Getter for the field maxY. *

* @return Upper right corner, coordinate axis 2 */ public double getMaxY() { return maxY; } /** *

* Getter for the field crs. *

* @return CRS of the bbox, never null */ public CoordinateSystem getCrs() { return crs; } /** *

* asQueryParameter. *

* @return the bbox as query string like '-12,10, 12,20' */ public String asQueryParameter() { StringBuilder sb = new StringBuilder(); DecimalFormat formatter = formatter(); sb.append(formatter.format(minX)).append(","); sb.append(formatter.format(minY)).append(","); sb.append(formatter.format(maxX)).append(","); sb.append(formatter.format(maxY)); return sb.toString(); } /** {@inheritDoc} */ @Override public String toString() { return asQueryParameter(); } /** {@inheritDoc} */ @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; BBox bBox = (BBox) o; return Double.compare(bBox.minX, minX) == 0 && Double.compare(bBox.minY, minY) == 0 && Double.compare(bBox.maxX, maxX) == 0 && Double.compare(bBox.maxY, maxY) == 0; } /** {@inheritDoc} */ @Override public int hashCode() { return Objects.hash(minX, minY, maxX, maxY); } private DecimalFormat formatter() { NumberFormat nf = NumberFormat.getNumberInstance(Locale.ENGLISH); DecimalFormat df = (DecimalFormat) nf; df.applyPattern(PATTERN); return df; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy