Example #1
0
 String parseAuthCode(Element e) throws ParseException {
   Element a = e.pullOptionalElement("AUTHORITY");
   if (a != null) {
     return a.pullString("name") + ":" + a.pullString("code");
   }
   return null;
 }
Example #2
0
  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;
  }
Example #3
0
  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;
  }
Example #4
0
  Projection parseProjection(Element e) throws ParseException {
    Element p = e.pullElement("PROJECTION");
    String name = p.pullString("name");

    Projection proj = new Registry().getProjection(name);
    if (proj == null) {
      throw new IllegalArgumentException("Unsupported projection: " + name);
    }

    return proj;
  }
Example #5
0
  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);
  }
Example #6
0
  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()]);
  }
Example #7
0
  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;
  }
Example #8
0
  CoordinateReferenceSystem parseGeoGCS(Element element) throws ParseException {
    // Element            element = parent.pullElement("GEOGCS");
    String name = element.pullString("name");
    Map<String, ?> properties = parseAuthority(element, name);
    Unit angularUnit = parseUnit(element, Units.RADIANS);

    Object meridian = parsePrimem(element, angularUnit);
    Datum datum = parseDatum(element, meridian);

    // String[] params = new String[]{Proj4Keyword.units, angularUnit.abbreviation};
    LongLatProjection proj = new LongLatProjection();

    proj.initialize();

    return new CoordinateReferenceSystem(name, null, datum, proj);
    /*CoordinateSystemAxis axis0 = parseAxis     (element, angularUnit, false);
    CoordinateSystemAxis axis1;
    CoordinateSystemAxis axis2 = null;
    try {
        if (axis0 != null) {
            axis1 = parseAxis(element, angularUnit, true);
            if(axis1 != null) {
                axis2 = parseAxis(element, SI.METER, false);
            }
        } else {
            // Those default values are part of WKT specification.
            axis0 = createAxis(null, "Lon", AxisDirection.EAST,  angularUnit);
            axis1 = createAxis(null, "Lat", AxisDirection.NORTH, angularUnit);
        }
        element.close();
        EllipsoidalCS ellipsoidalCS;
        if(axis2 != null) {
            ellipsoidalCS = csFactory.createEllipsoidalCS(properties, axis0, axis1, axis2);
        } else {
            ellipsoidalCS = csFactory.createEllipsoidalCS(properties, axis0, axis1);
        }
        return crsFactory.createGeographicCRS(properties, datum,
                ellipsoidalCS);
    } catch (FactoryException exception) {
        throw element.parseFailed(exception, null);
    }*/
  }
Example #9
0
  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);
  }
Example #10
0
  CoordinateReferenceSystem parseProjCS(Element e) throws ParseException {
    String authCode = parseAuthCode(e);
    if (authCode != null) {
      CoordinateReferenceSystem crs = Proj.crs(authCode);
      if (crs != null) {
        return crs;
      }
    }

    // parse manually
    String name = e.pullString("name");
    CoordinateReferenceSystem geo = parseGeoGCS(e.pullElement("GEOGCS"));

    Projection proj = parseProjection(e);
    String[] params = parseParameters(e);

    // TODO:
    /*
    Unit unit = parseUnit(e, Units.METRES);
    parseAxis(e);
    parseAxis(e);
    */
    return new CoordinateReferenceSystem(name, params, geo.getDatum(), proj);
  }