/** * Parses a substring as an angle. Default implementation invokes {@link #parse(String, * ParsePosition)}. * * @param source A String whose beginning should be parsed. * @param pos Position where to start parsing. * @return The parsed string as an {@link Angle}, {@link Latitude} or {@link Longitude} object. */ public Angle parseObject(final String source, final ParsePosition pos) { return parse(source, pos); }
if (mt.getUnit() == null) { return mt.doubleValue(); return mt.doubleValue(); UnitConverter converter = mt.getUnit().asType(Length.class).getConverterTo(SI.METRE); double tolMeters = converter.convert(mt.doubleValue()); return tolMeters * OGC_METERS_TO_DEGREES; } else if (targetUnit != null && targetUnit.isCompatible(SI.METRE)) { UnitConverter converter = mt.getUnit().getConverterTo(targetUnit); return converter.convert(mt.doubleValue()); } else { return mt.doubleValue();
/** * Constructs a new coordinate format for the specified locale and coordinate reference system. * * @param locale The locale for formatting coordinates and numbers. * @param crs The output coordinate reference system. */ public CoordinateFormat(final Locale locale, final CoordinateReferenceSystem crs) { this.locale = locale; this.separator = " "; setCoordinateReferenceSystem(crs); }
/** * Test {@link AngleFormat}. * * @throws ParseException If an angle can't be parsed. */ @Test public void testAngleFormat() throws ParseException { AngleFormat f = new AngleFormat("DD.ddd\u00B0", Locale.CANADA); assertFormat("20.000\u00B0", new Angle(20.000), f); assertFormat("20.749\u00B0", new Angle(20.749), f); assertFormat("-12.247\u00B0", new Angle(-12.247), f); assertFormat("13.214\u00B0N", new Latitude(13.214), f); assertFormat("12.782\u00B0S", new Latitude(-12.782), f); f = new AngleFormat("DD.ddd\u00B0", Locale.FRANCE); assertFormat("19,457\u00B0E", new Longitude(19.457), f); assertFormat("78,124\u00B0S", new Latitude(-78.124), f); f = new AngleFormat("DDddd", Locale.CANADA); assertFormat("19457E", new Longitude(19.457), f); assertFormat("78124S", new Latitude(-78.124), f); f = new AngleFormat("DD\u00B0MM.m", Locale.CANADA); assertFormat("12\u00B030.0", new Angle(12.50), f); assertFormat("-10\u00B015.0", new Angle(-10.25), f); }
ft.setSRS("EPSG:4326"); ft.setNativeCRS(CRS.decode("EPSG:4326")); ft.setLinearizationTolerance(new Measure(10, SI.METRE)); assertEquals(ns, ft.getNamespace()); assertEquals("EPSG:4326", ft.getSRS()); assertEquals(new Measure(10, SI.METRE), ft.getLinearizationTolerance()); assertTrue(CRS.equalsIgnoreMetadata(CRS.decode("EPSG:4326"), ft.getNativeCRS()));
protected Angle inverseConvert(final Double value) { return new Angle(value); } });
/** * Constructs a new {@code AngleFormat} for the specified locale. * * @param locale The locale. * @return An angle format in the given locale. */ public static AngleFormat getInstance(final Locale locale) { return new AngleFormat("D\u00B0MM.m'", locale); }
/** * Set the pattern for angles fields. If some ordinates are formatted as angle (for example in * {@linkplain org.geotools.referencing.cs.DefaultEllipsoidalCS ellipsoidal coordinate system}), * then those angles will be formatted using this pattern. * * @param pattern The angle pattern as specified in {@link AngleFormat}. */ public void setAnglePattern(final String pattern) { Format lastFormat = null; for (int i = 0; i < formats.length; i++) { final Format format = formats[i]; if (format != lastFormat && (format instanceof AngleFormat)) { ((AngleFormat) format).applyPattern(pattern); lastFormat = format; } } }
/** * Format an angle. The string will be formatted according the pattern set in the last call to * {@link #applyPattern}. * * @param angle Angle to format, in degrees. * @return The formatted string. */ public final String format(final double angle) { return format(angle, new StringBuffer(), null).toString(); }
/** Returns a string representation of this object. */ @Override public String toString() { return Classes.getShortClassName(this) + '[' + toPattern() + ']'; } }
public EPSGFormat() { super(); initUnits(Units.getDefaultFormat()); epsgLabelsAndAliases(this); } }
/** * Constructs a converter for sexagesimal units. * * @param divider The value to divide DMS unit by. For "degree minute second" (EPSG code 9107), * this is 1. For "sexagesimal degree" (EPSG code 9110), this is 10000. */ private SexagesimalConverter(final int divider) { this.divider = divider; this.inverse = new Inverse(this); }
if (linearizationTolerance == null) { if (other.getLinearizationTolerance() != null) return false; } else if (!linearizationTolerance.equals(other.getLinearizationTolerance())) return false; if (maxFeatures != other.getMaxFeatures()) return false; if (numDecimals != other.getNumDecimals()) return false;
@Override public boolean equals(Object obj) { if (obj instanceof UnitWrapper) { return Units.equals(unit, ((UnitWrapper) obj).getUnit()); } return false; }
/** Checks the conversions using {@link Units#SEXAGESIMAL_DMS}. */ @Test public void testSexagesimal() { checkConversion(10.00, NonSI.DEGREE_ANGLE, 10.0000, SEXAGESIMAL_DMS); checkConversion(10.01, NonSI.DEGREE_ANGLE, 10.0036, SEXAGESIMAL_DMS); checkConversion(10.50, NonSI.DEGREE_ANGLE, 10.3000, SEXAGESIMAL_DMS); checkConversion(10.99, NonSI.DEGREE_ANGLE, 10.5924, SEXAGESIMAL_DMS); }
/** * Returns a shared instance of {@link AngleFormat}. The return type is {@link Format} in order * to avoid class loading before necessary. */ private static Format getAngleFormat() { assert Thread.holdsLock(Angle.class); if (format == null) { format = new AngleFormat("D°MM.m'", Locale.US); } return format; } }
/** * Parses a string as an object. Default implementation invokes {@link #parse(String)}. * * @param source The string to parse. * @return The parsed string as an {@link Angle}, {@link Latitude} or {@link Longitude} object. * @throws ParseException if the string has not been fully parsed. */ @Override public Angle parseObject(final String source) throws ParseException { return parse(source); }
public ESRIFormat() { super(); initUnits(Units.getDefaultFormat()); esriLabelsAndAliases(this); } }
/** * Parses a string as an angle. This method can parse an angle even if it doesn't comply exactly * to the expected pattern. For example, this method will parse correctly string "<code> * 48°12.34'</code>" even if the expected pattern was "{@code DDMM.mm}" (i.e. the string should * have been "{@code 4812.34}"). Spaces between degrees, minutes and secondes are ignored. If * the string ends with an hemisphere symbol "N" or "S", then this method returns an object of * class {@link Latitude}. Otherwise, if the string ends with an hemisphere symbol "E" or "W", * then this method returns an object of class {@link Longitude}. Otherwise, this method returns * an object of class {@link Angle}. * * @param source A String whose beginning should be parsed. * @param pos Position where to start parsing. * @return The parsed string as an {@link Angle}, {@link Latitude} or {@link Longitude} object. */ public Angle parse(final String source, final ParsePosition pos) { return parse(source, pos, false); }
DefaultUnitParser() { initUnits(Units.getDefaultFormat()); esriLabelsAndAliases(this); // add epsg labels the latest, to override esri ones if they collide epsgLabelsAndAliases(this); }