/** * Transform the PrjElement in parameter into a set of parameters. * * @param el the PrjElement to transform */ static Map<String, String> match(PrjElement el) { PrjMatcher m = new PrjMatcher(); return m.doMatch(el); }
List<PrjElement> ll = matchNode(el, PrjKeyParameters.COMPDCS, false); if (ll == null) { ll = matchNode(el, PrjKeyParameters.PROJCS, false); if (ll == null) { ll = matchNode(el, PrjKeyParameters.GEOGCS, false); if (ll == null) { ll = matchNode(el, PrjKeyParameters.GEOCCS, false); if (ll == null) { ll = matchNode(el, PrjKeyParameters.VERTCS); parseVertcs(ll, true); } else { parseGeoccs(ll); parseGeogcs(ll, true); parseProjcs(ll, true); parseCompdcs(ll); cleanUnits(); return params;
/** * Read the informations contains in the VERT_DATUM node and put it into the * set of parameters. * * @param ll the children of the VERT_DATUM node */ private void parseVertDatum(List<PrjElement> ll) { String datum = getString(ll.get(0)); String datm = PrjValueParameters.DATUMNAMES.get(datum.toLowerCase().replaceAll("[^a-zA-Z0-9]", "")); datum = datm != null ? datm : datum; params.put(PrjKeyParameters.VERTDATUM, datum); parseNumber(ll.get(1), PrjKeyParameters.VERTDATUMTYPE); if (ll.size() > 2) { String auth = getAuthority(matchNode(ll.get(2), PrjKeyParameters.AUTHORITY)); params.put(PrjKeyParameters.VERTDATUMREFNAME, auth); } }
/** * Read the informations contains in a PARAMETER node and put it into the * set of parameters. * * @param ll the children of the PARAMETER node */ private void parseParameter(List<PrjElement> ll) { String param = getString(ll.get(0)); String parm = PrjValueParameters.PARAMNAMES.get(param.toLowerCase().replaceAll("[^a-zA-Z0-9]", "")); if (parm != null) { parseNumber(ll.get(1), parm); } }
/** * Return the informations contains in an UNIT node in a list of String. * * @param ll the children of the UNIT node */ private List<String> getUnit(List<PrjElement> ll) { List<String> result = new ArrayList<String>(); String unit = getString(ll.get(0)); String unt = PrjValueParameters.UNITNAMES.get(unit.replaceAll("[^a-zA-Z0-9]", "").toLowerCase()); if (unt != null) { result.add(unt); } else { result.add(unit); } result.add(String.valueOf(getNumber(ll.get(1)))); if (ll.size() > 2) { result.add(getAuthority(matchNode(ll.get(2), PrjKeyParameters.AUTHORITY))); } return result; }
parseString(ll.get(0), PrjKeyParameters.VERTCS); } else { parseString(ll.get(0), PrjKeyParameters.NAME); matchAnyNode(ll.get(i), matchers);
/** * Return the authority code contains in the AUTHORITY node in parameter. * * @param ll the children of the AUTHORITY node */ private String getAuthority(List<PrjElement> ll) { String auth = getString(ll.get(0)); PrjElement authorityCode = ll.get(1); String code ; if(authorityCode instanceof PrjNumberElement){ code = String.valueOf(Math.round(getNumber(authorityCode))); } else{ code = getString(authorityCode); } return auth + ':' + code; }
String datum = getString(ll.get(0)); String datm = PrjValueParameters.DATUMNAMES.get(datum.toLowerCase() .replaceAll("^d_","") matchAnyNode(ll.get(i), matchers);
/** * Read the informations contains in the PROJECTION node and put it into the * set of parameters. * * @param ll the children of the PROJECTION node */ private void parseProjection(List<PrjElement> ll) { String proj = getString(ll.get(0)); String prj = PrjValueParameters.PROJNAMES.get(proj.replaceAll("[^a-zA-Z0-9]", "").toLowerCase()); proj = prj != null ? prj : proj; params.put(ProjKeyParameters.proj, proj); }
/** * Read the informations contains in the PrjElement in parameter using one * of the PrjNodeMatcher in parameter and put it into the set of parameters. * * @param e the PrjElement to parse * @param nn the PrjNodeMatcher to use to parse the given PrjElement */ private void matchAnyNode(PrjElement e, PrjNodeMatcher[] nn) { matchAnyNode(e, nn, false); }
/** * Return the children of the PrjElement in parameter if it is an instance * of PrjNodeElement and if its name is the same as the name given in * parameter,else it throws a PrjParserException. * * @param e the PrjElement to match * @param name the name of the desired PrjElement */ private List<PrjElement> matchNode(PrjElement e, String name) { return matchNode(e, name, true); }
/** * Read the informations contains in the TOWGS84 node and put it into the * set of parameters. * * @param ll the children of the TOWGS84 node */ private void parseToWGS84(List<PrjElement> ll) { StringBuilder b = new StringBuilder(); b.append(getNumber(ll.get(0))); for (int i = 1; i < ll.size(); i++) { b.append(',').append(getNumber(ll.get(i))); } params.put(ProjKeyParameters.towgs84, b.toString()); }
/** * Parses a WKT PRJ String into a set of parameters. * * This is the main entry point of the parser. * * @param prjString a WKT string * @return a list of parameters * @throws PrjParserException if the PRJ cannot be parsed into a CRS for any * reason */ public Map<String, String> getParameters(String prjString) { CharBuffer s = CharBuffer.wrap(prjString); PrjElement e; try { e = parseNode(s); } catch (BufferUnderflowException ex) { throw new PrjParserException("Failed to read PRJ.", ex); } Map<String, String> prjParameters = PrjMatcher.match(e); return prjParameters; }
parseString(ll.get(0), PrjKeyParameters.PROJCS); } else { parseString(ll.get(0), PrjKeyParameters.NAME); matchAnyNode(ll.get(i), matchers);
/** * Return the informations contains in an AXIS node in a list of String. * * @param ll the children of the UNIT node */ private List<String> getAxis(List<PrjElement> ll) { List<String> result = new ArrayList<String>(); String axisName = getString(ll.get(0)); String axis = PrjValueParameters.AXISNAMES.get(axisName.replaceAll("[^a-zA-Z0-9]", "").toLowerCase()); if (axis != null) { result.add(axis); } else { result.add(axisName); } result.add(getString(ll.get(1))); return result; }
/** * Read the informations contains in the SPHEROID node and put it into the * set of parameters. * * @param ll the children of the SPHEROID node */ private void parseSpheroid(List<PrjElement> ll) { String ellps = getString(ll.get(0)); String elps = PrjValueParameters.ELLIPSOIDNAMES.get(ellps.toLowerCase().replaceAll("[^a-zA-Z0-9]", "")); ellps = elps != null ? elps : ellps; params.put(ProjKeyParameters.ellps, ellps); parseNumber(ll.get(1), ProjKeyParameters.a); parseNumber(ll.get(2), ProjKeyParameters.rf); if (ll.size() > 3) { String auth = getAuthority(matchNode(ll.get(3), PrjKeyParameters.AUTHORITY)); params.put(PrjKeyParameters.SPHEROIDREFNAME, auth); } }
parseString(ll.get(0), PrjKeyParameters.NAME); params.put(ProjKeyParameters.proj, ProjValueParameters.GEOCENT); indexAxis = 0; matchAnyNode(ll.get(i), matchers);
/** * Read the informations contains in the PRIMEM node and put it into the set * of parameters. * * @param ll the children of the PRIMEM node */ private void parsePrimeM(List<PrjElement> ll) { String pm = getString(ll.get(0)); String prm = PrjValueParameters.PRIMEMERIDIANNAMES.get(pm.replaceAll("[^a-zA-Z0-9]", "").toLowerCase()); if (prm != null) { params.put(ProjKeyParameters.pm, prm); } else { params.put(ProjKeyParameters.pm, pm); parseNumber(ll.get(1), PrjKeyParameters.PMVALUE); if (ll.size() > 2) { String auth = getAuthority(matchNode(ll.get(2), PrjKeyParameters.AUTHORITY)); params.put(PrjKeyParameters.PRIMEMREFNAME, auth); } } }
parseString(ll.get(0), PrjKeyParameters.GEOGCS); } else { parseString(ll.get(0), PrjKeyParameters.NAME); parseString(ll.get(0), PrjKeyParameters.GEOGCS); matchers[3] = new PrjNodeMatcher() { @Override matchAnyNode(ll.get(i), matchers);
parseString(ll.get(0), PrjKeyParameters.NAME); PrjNodeMatcher[] matchers; matchers = new PrjNodeMatcher[4]; matchAnyNode(ll.get(i), matchers);