use of javax.measure.quantity.Length in project sldeditor by robward-scisys.
the class DefaultSymbols method createDefaultTextSymbolizer.
/**
* Creates the default text symbolizer.
*
* @return the text symbolizer
*/
public static TextSymbolizer createDefaultTextSymbolizer() {
Expression fontFamily = ff.literal("Serif");
Expression fontSize = ff.literal(10.0);
Expression fontStyle = ff.literal("normal");
Expression fontWeight = ff.literal("normal");
Expression rotation = ff.literal(0.0);
Expression label = ff.literal("Test");
String geometryFieldName = null;
Expression geometryField = ff.property(geometryFieldName);
String name = Localisation.getString(SLDTreeTools.class, "TreeItem.newText");
AnchorPoint anchor = null;
Displacement displacement = null;
PointPlacement pointPlacement = (PointPlacement) styleFactory.pointPlacement(anchor, displacement, rotation);
Expression fillColour = ff.literal(DEFAULT_COLOUR);
Expression fillColourOpacity = ff.literal(1.0);
Fill fill = styleFactory.fill(null, fillColour, fillColourOpacity);
Halo halo = null;
List<Expression> fontFamilyList = new ArrayList<Expression>();
fontFamilyList.add(fontFamily);
Font font = (Font) styleFactory.font(fontFamilyList, fontStyle, fontWeight, fontSize);
Description description = null;
Unit<Length> unit = null;
TextSymbolizer newTextSymbolizer = (TextSymbolizer) styleFactory.textSymbolizer(name, geometryField, description, unit, label, font, pointPlacement, halo, fill);
return newTextSymbolizer;
}
use of javax.measure.quantity.Length in project sldeditor by robward-scisys.
the class UnitsOfMeasureTest method testConvertUnitOfLength.
/**
* Test method for {@link com.sldeditor.ui.detail.UnitsOfMeasure#convert(javax.measure.unit.Unit)}.
*/
@Test
public void testConvertUnitOfLength() {
UnitsOfMeasure uom = UnitsOfMeasure.getInstance();
Unit<Length> unit = null;
assertTrue("".compareTo(uom.convert(unit)) == 0);
assertTrue("pixel".compareTo(uom.convert(NonSI.PIXEL)) == 0);
assertTrue("metre".compareTo(uom.convert(SI.METRE)) == 0);
assertTrue("foot".compareTo(uom.convert(NonSI.FOOT)) == 0);
}
use of javax.measure.quantity.Length in project sis by apache.
the class QuantitiesTest method testCastOrCopy.
/**
* Tests {@link Quantities#castOrCopy(Quantity)}.
*/
@Test
public void testCastOrCopy() {
Quantity<Length> q = Quantities.create(5, Units.KILOMETRE);
assertSame(q, Quantities.castOrCopy(q));
q = new Quantity<Length>() {
@Override
public Number getValue() {
return 8;
}
@Override
public Unit<Length> getUnit() {
return Units.CENTIMETRE;
}
@Override
public Quantity<Length> add(Quantity<Length> ignored) {
return null;
}
@Override
public Quantity<Length> subtract(Quantity<Length> ignored) {
return null;
}
@Override
public Quantity<?> multiply(Quantity<?> ignored) {
return null;
}
@Override
public Quantity<?> divide(Quantity<?> ignored) {
return null;
}
@Override
public Quantity<Length> multiply(Number ignored) {
return null;
}
@Override
public Quantity<Length> divide(Number ignored) {
return null;
}
@Override
public Quantity<?> inverse() {
return null;
}
@Override
public Quantity<Length> to(Unit<Length> ignored) {
return null;
}
@Override
public <T extends Quantity<T>> Quantity<T> asType(Class<T> ignored) {
return null;
}
};
final Length c = Quantities.castOrCopy(q);
assertNotSame(q, c);
assertEquals("value", 8, c.getValue().doubleValue(), STRICT);
assertSame("unit", Units.CENTIMETRE, c.getUnit());
}
use of javax.measure.quantity.Length in project sis by apache.
the class GeodeticObjectParser method parseMetadataAndClose.
/**
* Parses an <strong>optional</strong> metadata elements and close.
* This include elements like {@code "SCOPE"}, {@code "ID"} (WKT 2) or {@code "AUTHORITY"} (WKT 1).
* This WKT 1 element has the following pattern:
*
* {@preformat wkt
* AUTHORITY["<name>", "<code>"]
* }
*
* <div class="section">Fallback</div>
* The name is a mandatory property, but some invalid WKT with an empty string exist. In such case,
* we will use the name of the enclosed datum. Indeed, it is not uncommon to have the same name for
* a geographic CRS and its geodetic datum.
*
* @param parent the parent element.
* @param name the name of the parent object being parsed.
* @param fallback the fallback to use if {@code name} is empty.
* @return a properties map with the parent name and the optional authority code.
* @throws ParseException if an element can not be parsed.
*/
@SuppressWarnings("ReturnOfCollectionOrArrayField")
private Map<String, Object> parseMetadataAndClose(final Element parent, final String name, final IdentifiedObject fallback) throws ParseException {
properties.clear();
properties.put(IdentifiedObject.NAME_KEY, (name.isEmpty() && fallback != null) ? fallback.getName() : name);
Element element;
while ((element = parent.pullElement(OPTIONAL, ID_KEYWORDS)) != null) {
final String codeSpace = element.pullString("codeSpace");
// Accepts Integer as well as String.
final String code = element.pullObject("code").toString();
// Accepts Number as well as String.
final Object version = element.pullOptional(Object.class);
final Element citation = element.pullElement(OPTIONAL, WKTKeywords.Citation);
final String authority;
if (citation != null) {
authority = citation.pullString("authority");
citation.close(ignoredElements);
} else {
authority = codeSpace;
}
final Element uri = element.pullElement(OPTIONAL, WKTKeywords.URI);
if (uri != null) {
// TODO: not yet stored, since often redundant with other informations.
uri.pullString("URI");
uri.close(ignoredElements);
}
element.close(ignoredElements);
/*
* Note: we could be tempted to assign the authority to the name as well, like below:
*
* if (name instanceof String) {
* name = new NamedIdentifier(authority, (String) name);
* }
* properties.put(IdentifiedObject.NAME_KEY, name);
*
* However experience shows that it is often wrong in practice, because peoples often
* declare EPSG codes but still use WKT names much shorter than the EPSG names
* (for example "WGS84" for the datum instead than "World Geodetic System 1984"),
* so the name in WKT is often not compliant with the name actually defined by the authority.
*/
final ImmutableIdentifier id = new ImmutableIdentifier(Citations.fromName(authority), codeSpace, code, (version != null) ? version.toString() : null, null);
final Object previous = properties.put(IdentifiedObject.IDENTIFIERS_KEY, id);
if (previous != null) {
Identifier[] identifiers;
if (previous instanceof Identifier) {
identifiers = new Identifier[] { (Identifier) previous, id };
} else {
identifiers = (Identifier[]) previous;
final int n = identifiers.length;
identifiers = Arrays.copyOf(identifiers, n + 1);
identifiers[n] = id;
}
properties.put(IdentifiedObject.IDENTIFIERS_KEY, identifiers);
// REMINDER: values associated to IDENTIFIERS_KEY shall be recognized by 'toIdentifier(Object)'.
}
}
/*
* Other metadata (SCOPE, AREA, etc.). ISO 19162 said that at most one of each type shall be present,
* but our parser accepts an arbitrary amount of some kinds of metadata. They can be recognized by the
* 'while' loop.
*
* Most WKT do not contain any of those metadata, so we perform an 'isEmpty()' check as an optimization
* for those common cases.
*/
if (!parent.isEmpty()) {
/*
* Example: SCOPE["Large scale topographic mapping and cadastre."]
*/
element = parent.pullElement(OPTIONAL, WKTKeywords.Scope);
if (element != null) {
// Other types like Datum use the same key.
properties.put(ReferenceSystem.SCOPE_KEY, element.pullString("scope"));
element.close(ignoredElements);
}
/*
* Example: AREA["Netherlands offshore."]
*/
DefaultExtent extent = null;
while ((element = parent.pullElement(OPTIONAL, WKTKeywords.Area)) != null) {
final String area = element.pullString("area");
element.close(ignoredElements);
if (extent == null) {
extent = new DefaultExtent(area, null, null, null);
} else {
extent.getGeographicElements().add(new DefaultGeographicDescription(area));
}
}
/*
* Example: BBOX[51.43, 2.54, 55.77, 6.40]
*/
while ((element = parent.pullElement(OPTIONAL, WKTKeywords.BBox)) != null) {
final double southBoundLatitude = element.pullDouble("southBoundLatitude");
final double westBoundLongitude = element.pullDouble("westBoundLongitude");
final double northBoundLatitude = element.pullDouble("northBoundLatitude");
final double eastBoundLongitude = element.pullDouble("eastBoundLongitude");
element.close(ignoredElements);
if (extent == null)
extent = new DefaultExtent();
extent.getGeographicElements().add(new DefaultGeographicBoundingBox(westBoundLongitude, eastBoundLongitude, southBoundLatitude, northBoundLatitude));
}
/*
* Example: VERTICALEXTENT[-1000, 0, LENGTHUNIT[“metre”, 1]]
*
* Units are optional, default to metres (no "contextual units" here).
*/
while ((element = parent.pullElement(OPTIONAL, WKTKeywords.VerticalExtent)) != null) {
final double minimum = element.pullDouble("minimum");
final double maximum = element.pullDouble("maximum");
Unit<Length> unit = parseScaledUnit(element, WKTKeywords.LengthUnit, Units.METRE);
element.close(ignoredElements);
if (unit == null)
unit = Units.METRE;
if (extent == null)
extent = new DefaultExtent();
verticalElements = new VerticalInfo(verticalElements, extent, minimum, maximum, unit).resolve(verticalCRS);
}
/*
* Example: TIMEEXTENT[2013-01-01, 2013-12-31]
*
* TODO: syntax like TIMEEXTENT[“Jurassic”, “Quaternary”] is not yet supported.
* See https://issues.apache.org/jira/browse/SIS-163
*
* This operation requires the the sis-temporal module. If not available,
* we will report a warning and leave the temporal extent missing.
*/
while ((element = parent.pullElement(OPTIONAL, WKTKeywords.TimeExtent)) != null) {
if (element.peekValue() instanceof String) {
element.pullString("startTime");
element.pullString("endTime");
element.close(ignoredElements);
warning(parent, element, Errors.formatInternational(Errors.Keys.UnsupportedType_1, "TimeExtent[String,String]"), null);
} else {
final Date startTime = element.pullDate("startTime");
final Date endTime = element.pullDate("endTime");
element.close(ignoredElements);
try {
final DefaultTemporalExtent t = new DefaultTemporalExtent();
t.setBounds(startTime, endTime);
if (extent == null)
extent = new DefaultExtent();
extent.getTemporalElements().add(t);
} catch (UnsupportedOperationException e) {
warning(parent, element, null, e);
}
}
}
if (extent != null) {
properties.put(ReferenceSystem.DOMAIN_OF_VALIDITY_KEY, extent);
}
/*
* Example: REMARK["Замечание на русском языке"]
*/
element = parent.pullElement(OPTIONAL, WKTKeywords.Remark);
if (element != null) {
properties.put(IdentifiedObject.REMARKS_KEY, element.pullString("remarks"));
element.close(ignoredElements);
}
}
parent.close(ignoredElements);
return properties;
}
use of javax.measure.quantity.Length in project sis by apache.
the class DefaultEllipsoid method formatTo.
/**
* Formats this ellipsoid as a <cite>Well Known Text</cite> {@code Ellipsoid[…]} element.
*
* @return {@code "Ellipsoid"} (WKT 2) or {@code "Spheroid"} (WKT 1).
*
* @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#52">WKT 2 specification §8.2.1</a>
*/
@Override
protected String formatTo(final Formatter formatter) {
super.formatTo(formatter);
final Convention convention = formatter.getConvention();
final boolean isWKT1 = convention.majorVersion() == 1;
// Gives to users a chance to override properties.
final Unit<Length> unit = getAxisUnit();
double length = getSemiMajorAxis();
if (isWKT1) {
length = unit.getConverterTo(Units.METRE).convert(length);
}
formatter.append(length);
// Gives to users a chance to override properties.
final double inverseFlattening = getInverseFlattening();
formatter.append(isInfinite(inverseFlattening) ? 0 : inverseFlattening);
if (isWKT1) {
return WKTKeywords.Spheroid;
}
if (!convention.isSimplified() || !Units.METRE.equals(unit)) {
formatter.append(unit);
}
return WKTKeywords.Ellipsoid;
}
Aggregations