Map<String, Object> parseAuthority(final Element parent, final String name) throws ParseException { final boolean isRoot = parent.isRoot(); final Element element = parent.pullOptionalElement("AUTHORITY"); Map<String, Object> properties; if (element == null) { if (isRoot) { properties = new HashMap<String, Object>(4); properties.put(NAME_KEY, name); } else { properties = Collections.singletonMap(NAME_KEY, (Object) name); } } else { final String auth = element.pullString("name"); // the code can be annotation marked but could be a number to String code = element.pullOptionalString("code"); if (code == null) { int codeNumber = element.pullInteger("code"); code = String.valueOf(codeNumber); } element.close(); // final Citation authority = Citations.fromName(auth); properties = new HashMap<String, Object>(4); properties.put(NAME_KEY, auth + ":" + name); properties.put(IDENTIFIERS_KEY, auth + ":" + code); } if (isRoot) { // properties = alterProperties(properties); } return properties; }
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; }
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); }
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; }
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(); } }