use of org.apache.sis.measure.Latitude in project sis by apache.
the class SpecialCasesTest method testSet.
/**
* Tests {@link SpecialCases#set(int, Object, Object, int)} in {@code RETURN_PREVIOUS} mode.
*/
@Test
@DependsOnMethod("testGet")
public void testSet() {
createBox();
assertPreviousEquals("westBoundLongitude", new Longitude(-20), new Longitude(-15));
assertPreviousEquals("eastBoundLongitude", new Longitude(30), new Longitude(25));
assertPreviousEquals("southBoundLatitude", new Latitude(-10), new Latitude(-5));
assertPreviousEquals("northBoundLatitude", new Latitude(40), new Latitude(35));
assertPreviousEquals("extentTypeCode", Boolean.TRUE, Boolean.FALSE);
assertEquals("westBoundLongitude", -15, box.getWestBoundLongitude(), STRICT);
assertEquals("eastBoundLongitude", 25, box.getEastBoundLongitude(), STRICT);
assertEquals("southBoundLatitude", -5, box.getSouthBoundLatitude(), STRICT);
assertEquals("northBoundLatitude", 35, box.getNorthBoundLatitude(), STRICT);
assertEquals("extentTypeCode", Boolean.FALSE, box.getInclusion());
}
use of org.apache.sis.measure.Latitude in project sis by apache.
the class SpecialCasesTest method testAppend.
/**
* Tests {@link SpecialCases#set(int, Object, Object, int)} in {@code APPEND} mode.
*/
@Test
@DependsOnMethod("testSet")
public void testAppend() {
createBox();
assertAppendResultEquals("westBoundLongitude", null, new Longitude(-20));
assertAppendResultEquals("eastBoundLongitude", null, new Longitude(24));
assertAppendResultEquals("southBoundLatitude", null, new Latitude(-6));
assertAppendResultEquals("northBoundLatitude", null, 40.0);
assertAppendResultEquals("extentTypeCode", false, Boolean.TRUE);
assertEquals("westBoundLongitude", -20, box.getWestBoundLongitude(), STRICT);
assertEquals("eastBoundLongitude", 30, box.getEastBoundLongitude(), STRICT);
assertEquals("southBoundLatitude", -10, box.getSouthBoundLatitude(), STRICT);
assertEquals("northBoundLatitude", 40, box.getNorthBoundLatitude(), STRICT);
assertEquals("extentTypeCode", Boolean.TRUE, box.getInclusion());
}
use of org.apache.sis.measure.Latitude in project sis by apache.
the class SpecialCasesTest method testSetAsPrimitive.
/**
* Tests {@link SpecialCases#set(int, Object, Object, int)} in {@code RETURN_PREVIOUS} mode
* with {@link Double} values instead than {@link Longitude} or {@link Latitude}.
*/
@Test
@DependsOnMethod("testSet")
public void testSetAsPrimitive() {
createBox();
assertPreviousEquals("westBoundLongitude", new Longitude(-20), -14.0);
assertPreviousEquals("eastBoundLongitude", new Longitude(30), 26);
assertPreviousEquals("southBoundLatitude", new Latitude(-10), -7f);
assertPreviousEquals("northBoundLatitude", new Latitude(40), (short) 33);
assertEquals("westBoundLongitude", -14, box.getWestBoundLongitude(), STRICT);
assertEquals("eastBoundLongitude", 26, box.getEastBoundLongitude(), STRICT);
assertEquals("southBoundLatitude", -7, box.getSouthBoundLatitude(), STRICT);
assertEquals("northBoundLatitude", 33, box.getNorthBoundLatitude(), STRICT);
assertEquals("extentTypeCode", Boolean.TRUE, box.getInclusion());
}
use of org.apache.sis.measure.Latitude in project sis by apache.
the class CoordinateFormat method format.
/**
* Formats the given coordinate and appends the resulting text to the given stream or buffer.
*
* @param position the coordinate to format.
* @param toAppendTo where the text is to be appended.
* @throws IOException if an error occurred while writing to the given appendable.
*/
@Override
@SuppressWarnings("UnnecessaryBoxing")
public void format(final DirectPosition position, final Appendable toAppendTo) throws IOException {
ArgumentChecks.ensureNonNull("position", position);
ArgumentChecks.ensureNonNull("toAppendTo", toAppendTo);
CoordinateReferenceSystem crs = position.getCoordinateReferenceSystem();
if (crs == null) {
// May still be null.
crs = defaultCRS;
}
if (crs != lastCRS) {
initialize(crs);
}
/*
* Standard java.text.Format API can only write into a StringBuffer. If the given Appendable is not a
* StringBuffer, then we will need to format in a temporary buffer before to copy to the Appendable.
*/
final StringBuffer destination;
if (toAppendTo instanceof StringBuffer) {
destination = (StringBuffer) toAppendTo;
} else {
if (buffer == null) {
buffer = new StringBuffer();
}
destination = buffer;
destination.setLength(0);
}
if (dummy == null) {
dummy = new FieldPosition(0);
}
/*
* The format to use for each ordinate has been computed by 'initialize'. The format array length
* should match the number of dimensions in the given position if the DirectPosition is consistent
* with its CRS, but we will nevertheless verify has a paranoiac check. If there is no CRS, or if
* the DirectPosition dimension is (illegally) greater than the CRS dimension, then we will format
* the ordinate as a number.
*/
final int dimension = position.getDimension();
for (int i = 0; i < dimension; i++) {
double value = position.getOrdinate(i);
final Object object;
final Format f;
if (formats != null && i < formats.length) {
f = formats[i];
if (isNegative(i)) {
value = -value;
}
if (toFormatUnit != null) {
final UnitConverter c = toFormatUnit[i];
if (c != null) {
value = c.convert(value);
}
}
switch(types[i]) {
default:
object = Double.valueOf(value);
break;
case LONGITUDE:
object = new Longitude(value);
break;
case LATITUDE:
object = new Latitude(value);
break;
case ANGLE:
object = new Angle(value);
break;
case DATE:
object = new Date(Math.round(value) + epochs[i]);
break;
}
} else {
object = value;
f = getFormat(Number.class);
}
/*
* At this point we got the value to format together with the Format instance to use.
*/
if (i != 0) {
toAppendTo.append(separator);
}
if (f.format(object, destination, dummy) != toAppendTo) {
toAppendTo.append(destination);
destination.setLength(0);
}
if (unitSymbols != null && i < unitSymbols.length) {
final String symbol = unitSymbols[i];
if (symbol != null) {
toAppendTo.append(Characters.NO_BREAK_SPACE).append(symbol);
}
}
}
}
use of org.apache.sis.measure.Latitude in project sis by apache.
the class CoordinateOperationMethods method writeIdentification.
/**
* Writes identification info about the given method.
* This method writes the following information:
*
* <ul>
* <li>EPSG codes</li>
* <li>Aliases</li>
* <li>Domain of validity</li>
* </ul>
*/
private void writeIdentification(final OperationMethod method) throws IOException {
final int table = openTag("table class=\"info\"");
/*
* ──────────────── EPSG IDENTIFIERS ────────────────────────────────────
*/
final StringBuilder buffer = new StringBuilder();
for (final ReferenceIdentifier id : method.getIdentifiers()) {
if (Constants.EPSG.equalsIgnoreCase(id.getCodeSpace())) {
if (buffer.length() != 0) {
buffer.append(", ");
}
final boolean isDeprecated = isDeprecated(id);
if (isDeprecated) {
buffer.append("<del>");
}
buffer.append(id.getCode());
if (isDeprecated) {
buffer.append("</del>");
}
}
}
if (buffer.length() != 0) {
final int tr = openTag("tr");
println("th", "EPSG code:");
println("td", buffer);
closeTags(tr);
}
/*
* ──────────────── ALIASES ─────────────────────────────────────────────
*/
buffer.setLength(0);
for (final GenericName alias : method.getAlias()) {
if (buffer.length() != 0) {
buffer.append(", ");
}
final GenericName head = alias.head();
if (head == alias || Constants.EPSG.equalsIgnoreCase(head.toString())) {
buffer.append(alias.tip());
} else {
buffer.append("<span class=\"non-epsg\">").append(head).append(":</span>").append("<code>").append(alias.tip()).append("</code>");
}
}
if (buffer.length() != 0) {
final int tr = openTag("tr");
println("th", "Aliases:");
println("td", buffer);
closeTags(tr);
}
/*
* ──────────────── DOMAIN OF VALIDITY ──────────────────────────────────
*/
buffer.setLength(0);
final DefaultGeographicBoundingBox domain = getDomainOfValidity(method);
if (domain != null) {
openTag("tr");
println("th", "Domain of validity:");
println("td", buffer.append(new Latitude(domain.getSouthBoundLatitude())).append(" to ").append(new Latitude(domain.getNorthBoundLatitude())).append(" and ").append(new Longitude(domain.getWestBoundLongitude())).append(" to ").append(new Longitude(domain.getEastBoundLongitude())));
}
closeTags(table);
}
Aggregations