Ellipsoid parseSpheroid(final Element parent) throws ParseException { Element element = parent.pullElement("SPHEROID"); String name = element.pullString("name"); double semiMajorAxis = element.pullDouble("semiMajorAxis"); double inverseFlattening = element.pullDouble("inverseFlattening"); Map<String, ?> properties = parseAuthority(element, name); element.close(); if (inverseFlattening == 0) { // Inverse flattening null is an OGC convention for a sphere. inverseFlattening = Double.POSITIVE_INFINITY; } return new Ellipsoid(name, semiMajorAxis, 0, inverseFlattening, name); }
Object parsePrimem(final Element parent, final Unit angularUnit) throws ParseException { final Element element = parent.pullElement("PRIMEM"); final String name = element.pullString("name"); final double longitude = element.pullDouble("longitude"); final Map<String, ?> properties = parseAuthority(element, name); element.close(); return null; }
Datum parseDatum(final Element parent, final Object meridian) throws ParseException { Element element = parent.pullElement("DATUM"); String name = element.pullString("name"); Ellipsoid ellipsoid = parseSpheroid(element); double[] toWGS84 = parseToWGS84(element); // Optional; may be // null. Map<String, Object> properties = parseAuthority(element, name); if (true /*ALLOW_ORACLE_SYNTAX*/ && (toWGS84 == null) && (element.peek() instanceof Number)) { toWGS84 = new double[7]; toWGS84[0] = element.pullDouble("dx"); toWGS84[1] = element.pullDouble("dy"); toWGS84[2] = element.pullDouble("dz"); toWGS84[3] = element.pullDouble("ex"); toWGS84[4] = element.pullDouble("ey"); toWGS84[5] = element.pullDouble("ez"); toWGS84[6] = element.pullDouble("ppm"); } element.close(); return new Datum(name, toWGS84, ellipsoid, name); }
double[] parseToWGS84(final Element parent) throws ParseException { final Element element = parent.pullOptionalElement("TOWGS84"); if (element == null) { return null; } double dx = element.pullDouble("dx"); double dy = element.pullDouble("dy"); double dz = element.pullDouble("dz"); try { if (element.peek() != null) { double ex = element.pullDouble("ex"); double ey = element.pullDouble("ey"); double ez = element.pullDouble("ez"); double ppm = element.pullDouble("ppm"); return new double[] {dx, dy, dz, ex, ey, ez, ppm}; } else { return new double[] {dx, dy, dz}; } } finally { element.close(); } }
String[] parseParameters(Element e) throws ParseException { Element p = null; List<String> params = new ArrayList<String>(); while ((p = e.pullOptionalElement("PARAMETER")) != null) { String key = p.pullString("name"); Double val = p.pullDouble("value"); Param param = Param.valueOf(key); if (param == null) { throw new IllegalArgumentException("Unsupported projection parameter: " + key); } params.add(String.format("%s=%f", param.proj4, val)); } return params.toArray(new String[params.size()]); }
Unit parseUnit(final Element parent, final Unit unit) throws ParseException { final Element element = parent.pullElement("UNIT"); final String name = element.pullString("name"); final double factor = element.pullDouble("factor"); final Map<String, ?> properties = parseAuthority(element, name); element.close(); if (name != null) { Unit u = Units.findUnits(name.toLowerCase()); if (u != null) { return u; } } return (factor != 1) ? times(unit, factor) : unit; }