private <P extends Position> CompoundCoordinateReferenceSystem<P> decodeCompoundCrs() { String crsName = decodeName(); matchesElementSeparator(); SingleCoordinateReferenceSystem<?> head = (SingleCoordinateReferenceSystem<?>)decode(); matchesElementSeparator(); SingleCoordinateReferenceSystem<?> tail = (SingleCoordinateReferenceSystem<?>)decode(); CrsId cr = decodeOptionalAuthority(srid); return new CompoundCoordinateReferenceSystem<P>(cr, crsName, head, tail); }
private VerticalCoordinateReferenceSystem decodeVertCS() { String crsName = decodeName(); matchesElementSeparator(); VerticalDatum vdatum = decodeVertDatum(); matchesElementSeparator(); LinearUnit unit =(LinearUnit) decodeUnit(true); matchesElementSeparator(); VerticalStraightLineAxis axis = (VerticalStraightLineAxis)decodeAxis(unit, VerticalCoordinateReferenceSystem.class); CrsId id = decodeOptionalAuthority(); return new VerticalCoordinateReferenceSystem(id, crsName, vdatum, axis); }
/** * Determines the WKT variant and calls the according method to decode the WKT. * * @return The decoded WKT as a <code>CoordinateReferenceSystem</code> object. */ private CoordinateReferenceSystem<? extends Position> decode() { if (currentToken == CrsWktVariant.PROJCS) { return decodeProjectedCrs(); } else if (currentToken == CrsWktVariant.GEOGCS) { return decodeGeographicCrs(); } else if (currentToken == CrsWktVariant.GEOCCS) { return decodeGeocentricCrs(); } else if (currentToken == CrsWktVariant.COMPD_CS) { return decodeCompoundCrs(); } else if (currentToken == CrsWktVariant.VERT_CS) { return decodeVertCS(); } throw new WktDecodeException("Expected Wkt Token PROJCS, GEOGCS, GEOCCS or COMPD_CS. Received " + currentToken); }
private <T extends CoordinateReferenceSystem> CoordinateSystemAxis[] decodeOptionalAxes(int num, Unit unit, Class<T> crsClass) { matchesElementSeparator(); if (currentToken != CrsWktVariant.AXIS) { return defaultCRS(unit, crsClass); } CoordinateSystemAxis[] axes = new CoordinateSystemAxis[num]; for (int i = 0; i < num; i++) { if (i > 0) matchesElementSeparator(); axes[i] = decodeAxis(unit, crsClass); } return axes; }
private double[] decodeOptionalToWGS84() { matchesElementSeparator(); if (currentToken != CrsWktVariant.TOWGS84) { return new double[0]; } nextToken(); double[] toWGS = new double[7]; matchesOpenList(); for (int i = 0; i < 7; i++) { //TODO -- what with 3-parameter variants? toWGS[i] = decodeNumber(); matchesElementSeparator(); } matchesCloseList(); return toWGS; }
/** * Implementation to decode a Projected CRS. * * @return The <code>ProjectedCoordinateReferenceSystem</code> that is decoded from the WKT. */ private ProjectedCoordinateReferenceSystem decodeProjectedCrs() { String crsName = decodeName(); matchesElementSeparator(); Geographic2DCoordinateReferenceSystem geogcs = decodeGeographicCrs(); matchesElementSeparator(); Unit unit; Projection projection; List<CrsParameter> parameters; // spatial_reference.sql contains both variants of ProjCRS Wkt if (currentToken == CrsWktVariant.UNIT) { unit = decodeUnit(true); projection = decodeProjection(); parameters = decodeOptionalParameters(); } else { projection = decodeProjection(); parameters = decodeOptionalParameters(); unit = decodeUnit(true); } CoordinateSystemAxis[] twinAxes = decodeOptionalAxes(2, unit, ProjectedCoordinateReferenceSystem.class); Extension extension = decodeOptionalExtension(); CrsId crsId = decodeOptionalAuthority(srid); matchesCloseList(); return new ProjectedCoordinateReferenceSystem(crsId, crsName, geogcs, projection, parameters, new CartesianCoordinateSystem2D((StraightLineAxis)twinAxes[0], (StraightLineAxis)twinAxes[1]), extension); }
/** e * Currently not used in Postgis and also not implemented here! * * @throws UnsupportedConversionException Geocentric CRS is currently not implemented */ private GeocentricCartesianCoordinateReferenceSystem decodeGeocentricCrs() { String crsName = decodeName(); matchesElementSeparator(); Datum datum = decodeDatum(); matchesElementSeparator(); PrimeMeridian primem = decodePrimem(); matchesElementSeparator(); Unit unit = decodeUnit(true); CoordinateSystemAxis[] axes = decodeOptionalAxes(3, unit, GeocentricCartesianCoordinateReferenceSystem.class); CrsId cr = decodeOptionalAuthority(srid); matchesCloseList(); GeocentricCartesianCoordinateReferenceSystem system = new GeocentricCartesianCoordinateReferenceSystem(cr, crsName, datum, primem, new CartesianCoordinateSystem3D((StraightLineAxis)axes[0], (StraightLineAxis)axes[1], (VerticalStraightLineAxis) axes[2]) ); return system; }
private PrimeMeridian decodePrimem() { if (currentToken != CrsWktVariant.PRIMEM) { throw new WktDecodeException("Expected PRIMEM keyword, received " + currentToken.toString()); } String name = decodeName(); matchesElementSeparator(); double longitude = decodeNumber(); CrsId crsId = decodeOptionalAuthority(CrsId.UNDEFINED.getCode()); matchesCloseList(); return new PrimeMeridian(crsId, name, longitude); }
private VerticalDatum decodeVertDatum() { if (currentToken != CrsWktVariant.VERT_DATUM) { throw new WktDecodeException("Expected VERT_DATUM keyword, found " + currentToken.toString()); } String name = decodeName(); matchesElementSeparator(); int type = decodeInt(); Extension extension = decodeOptionalExtension(); CrsId authority = decodeOptionalAuthority(srid); matchesCloseList(); return new VerticalDatum(authority, name, type, extension); }
private CrsId decodeOptionalAuthority(int srid) { matchesElementSeparator(); if (currentToken != CrsWktVariant.AUTHORITY) { return new CrsId("EPSG", srid); } nextToken(); matchesOpenList(); String authority = decodeText(); matchesElementSeparator(); int value = decodeInt(); matchesCloseList(); return new CrsId(authority, value); }
private Datum decodeDatum() { if (currentToken != CrsWktVariant.DATUM) { throw new WktDecodeException("Expected DATUM token."); } String datumName = decodeName(); matchesElementSeparator(); Ellipsoid ellipsoid = decodeSpheroid(); double[] toWGS84 = decodeOptionalToWGS84(); CrsId crsId = decodeOptionalAuthority(CrsId.UNDEFINED.getCode()); matchesCloseList(); return new Datum(crsId, ellipsoid, datumName, toWGS84); }
private CrsParameter decodeOptionalParameter() { matchesElementSeparator(); if (currentToken != CrsWktVariant.PARAMETER) { return null; } nextToken(); String name = decodeName(); matchesElementSeparator(); double value = decodeNumber(); matchesCloseList(); return new CrsParameter(name, value); }
/** * Decodes a WKT representation of a <code>CoordinateReferenceSystem</code>. * * @param wkt the WKT string to decode * @return The <code>CoordinateReferenceSystem</code> that is encoded in the input WKT. */ public CoordinateReferenceSystem<? extends Position> decode(String wkt, int srid) { this.srid = srid; setTokenizer(new CrsWktTokenizer(wkt, getWktVariant())); nextToken(); return decode(); }
private static void addDefinition(String line, CrsWktDecoder decoder) { String[] tokens = line.split(DELIM); if (!"EPSG".equals(tokens[0])) { LOGGER.debug(String.format("Non-EPSG CRS ignored: %s", tokens[2])); return; } Integer srid = Integer.valueOf(tokens[1]); try { CoordinateReferenceSystem crs = decoder.decode(tokens[2], srid); crsMap.put(CrsId.valueOf(srid), crs); } catch (WktDecodeException e) { LOGGER.warn(String.format("Can't parse srid %d (%s). \n%s", srid, tokens[2], e.getMessage())); } catch (RuntimeException e) { LOGGER.warn(String.format("Can't parse srid %d (%s) -- inconsistent coordinate system. \n%s", srid, tokens[2], e.getMessage())); } }
private static void loadCRS() throws IOException { BufferedReader reader = createReader(); try { String line = reader.readLine(); CrsWktDecoder decoder = new CrsWktDecoder(); while (line != null) { addDefinition(line, decoder); line = reader.readLine(); } } finally { reader.close(); } }
/** * Implementation to decode a Geographic CRS. * * @return The <code>GeographicCoordinateReferenceSystem</code> that is decoded from the WKT. */ private Geographic2DCoordinateReferenceSystem decodeGeographicCrs() { String crsName = decodeName(); matchesElementSeparator(); Datum datum = decodeDatum(); matchesElementSeparator(); PrimeMeridian primem = decodePrimem(); matchesElementSeparator(); Unit unit = decodeUnit(false); CoordinateSystemAxis[] twinAxes = decodeOptionalAxes(2, unit, Geographic2DCoordinateReferenceSystem.class); CrsId cr = decodeOptionalAuthority(srid); matchesCloseList(); Geographic2DCoordinateReferenceSystem system = new Geographic2DCoordinateReferenceSystem(cr, crsName, new EllipsoidalCoordinateSystem2D((EllipsoidalAxis) twinAxes[0], (EllipsoidalAxis) twinAxes[1])); system.setDatum(datum); system.setPrimeMeridian(primem); return system; }
private Ellipsoid decodeSpheroid() { if (currentToken != CrsWktVariant.SPHEROID) { throw new WktDecodeException("Expected SPHEROID keyword, but received " + currentToken.toString()); } String ellipsoidName = decodeName(); matchesElementSeparator(); double semiMajorAxis = decodeNumber(); matchesElementSeparator(); double inverseFlattening = decodeNumber(); CrsId crsId = decodeOptionalAuthority(CrsId.UNDEFINED.getCode()); matchesCloseList(); return new Ellipsoid(crsId, ellipsoidName, semiMajorAxis, inverseFlattening); }
throw new WktDecodeException("Expected AXIS keyword, found " + currentToken.toString()); String name = decodeName(); matchesElementSeparator(); CoordinateSystemAxisDirection direction = CoordinateSystemAxisDirection.valueOf(currentToken.toString()); nextToken(); matchesCloseList();
private Unit decodeUnit(boolean isLinear) { if (currentToken != CrsWktVariant.UNIT) { throw new WktDecodeException("Expected UNIT keyword, found " + currentToken.toString()); } String name = decodeName(); matchesElementSeparator(); double cf = decodeNumber(); matchesElementSeparator(); CrsId crsId = decodeOptionalAuthority(CrsId.UNDEFINED.getCode()); matchesCloseList(); return isLinear ? new LinearUnit(crsId, name, cf) : new AngularUnit(crsId, name, cf); }
private Projection decodeProjection() { matchesElementSeparator(); if (currentToken != CrsWktVariant.PROJECTION) { throw new WktDecodeException("Expected PROJECTION keyword, found " + currentToken.toString()); } String name = decodeName(); CrsId crsId = decodeOptionalAuthority(CrsId.UNDEFINED.getCode()); matchesCloseList(); return new Projection(crsId, name); }