Search in sources :

Example 6 with LinearUnit

use of com.revolsys.geometry.cs.unit.LinearUnit in project com.revolsys.open by revolsys.

the class EsriCsWktWriter method write.

public static void write(final Writer out, final ProjectedCoordinateSystem coordinateSystem, final int indentLevel) throws IOException {
    out.write("PROJCS[");
    write(out, coordinateSystem.getCoordinateSystemName(), incrementIndent(indentLevel));
    final GeographicCoordinateSystem geoCs = coordinateSystem.getGeographicCoordinateSystem();
    if (geoCs != null) {
        out.write(",");
        indent(out, incrementIndent(indentLevel));
        write(out, geoCs, incrementIndent(indentLevel));
    }
    final CoordinateOperationMethod coordinateOperationMethod = coordinateSystem.getCoordinateOperationMethod();
    if (coordinateOperationMethod != null) {
        out.write(",");
        indent(out, incrementIndent(indentLevel));
        write(out, coordinateOperationMethod, incrementIndent(indentLevel));
    }
    for (final Entry<ParameterName, ParameterValue> parameter : coordinateSystem.getParameterValues().entrySet()) {
        final ParameterName name = parameter.getKey();
        final ParameterValue value = parameter.getValue();
        write(out, name, value, incrementIndent(indentLevel));
    }
    final LinearUnit unit = coordinateSystem.getLinearUnit();
    if (unit != null) {
        write(out, unit, incrementIndent(indentLevel));
    }
    indent(out, indentLevel);
    out.write(']');
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValue(com.revolsys.geometry.cs.ParameterValue) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) ParameterName(com.revolsys.geometry.cs.ParameterName) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem)

Example 7 with LinearUnit

use of com.revolsys.geometry.cs.unit.LinearUnit in project com.revolsys.open by revolsys.

the class WktCsParser method processProjectedCoordinateSystem.

@SuppressWarnings("unchecked")
private ProjectedCoordinateSystem processProjectedCoordinateSystem(final List<Object> values) {
    int index = 0;
    final String name = (String) values.get(index++);
    final GeographicCoordinateSystem geographicCoordinateSystem = (GeographicCoordinateSystem) values.get(index++);
    final Map<ParameterName, ParameterValue> parameters = new LinkedHashMap<>();
    LinearUnit linearUnit = null;
    final List<Axis> axis = new ArrayList<>();
    Authority authority = null;
    String methodName = null;
    while (index < values.size()) {
        final Object value = values.get(index++);
        if (value instanceof String) {
            methodName = (String) value;
        } else if (value instanceof Map) {
            final Map<String, List<Object>> map = (Map<String, List<Object>>) value;
            final String key = map.keySet().iterator().next();
            if (key.equals("PARAMETER")) {
                final List<Object> paramValues = map.get(key);
                final String paramName = (String) paramValues.get(0);
                final ParameterName parameterName = new SingleParameterName(paramName);
                final ParameterValueBigDecimal paramValue = new ParameterValueBigDecimal((BigDecimal) paramValues.get(1));
                parameters.put(parameterName, paramValue);
            }
        } else if (value instanceof LinearUnit) {
            linearUnit = (LinearUnit) value;
        } else if (value instanceof Axis) {
            axis.add((Axis) value);
        } else if (value instanceof Authority) {
            authority = (Authority) value;
        }
    }
    final int coordinateSystemId = getCoordinateSystemId(authority);
    final CoordinateOperationMethod coordinateOperationMethod = new CoordinateOperationMethod(methodName);
    return new ProjectedCoordinateSystem(coordinateSystemId, name, geographicCoordinateSystem, coordinateOperationMethod, parameters, linearUnit, axis, authority);
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 8 with LinearUnit

use of com.revolsys.geometry.cs.unit.LinearUnit in project com.revolsys.open by revolsys.

the class EsriCoordinateSystemsLoader method vertical.

private void vertical() {
    final Map<ByteArray, Map<Integer, VerticalCoordinateSystem>> csBymd5 = new LinkedHashMap<>();
    try (RecordReader reader = RecordReader.newRecordReader(this.mainPath + "data/esri/esriVerticalCs.tsv");
        final ChannelWriter writer = ChannelWriter.newChannelWriter(this.mainPath + "resources/CoordinateSystems/esri/Vertical.cs")) {
        for (final Record record : reader) {
            final int id = record.getInteger("ID");
            final String wkt = record.getString("WKT");
            final VerticalCoordinateSystem coordinateSystem = WktCsParser.read(wkt);
            final byte[] digest = coordinateSystem.md5Digest();
            Maps.addToMap(Maps::newTree, csBymd5, new ByteArray(digest), id, coordinateSystem);
            final VerticalDatum datum = coordinateSystem.getDatum();
            if (datum != null) {
                final Map<ParameterName, ParameterValue> parameterValues = coordinateSystem.getParameterValues();
                final LinearUnit linearUnit = coordinateSystem.getLinearUnit();
                final String csName = coordinateSystem.getCoordinateSystemName();
                this.geographicIdByName.put(csName, id);
                final String datumName = datum.getName();
                final String linearUnitName = linearUnit.getName();
                final double conversionFactor = linearUnit.getConversionFactor();
                writer.putInt(id);
                writer.putStringUtf8ByteCount(csName);
                writer.putStringUtf8ByteCount(datumName);
                writeParameters(writer, parameterValues);
                writer.putStringUtf8ByteCount(linearUnitName);
                writer.putDouble(conversionFactor);
            }
        }
    }
    writeDigestFile(csBymd5, "Vertical");
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValue(com.revolsys.geometry.cs.ParameterValue) RecordReader(com.revolsys.record.io.RecordReader) VerticalDatum(com.revolsys.geometry.cs.datum.VerticalDatum) ParameterName(com.revolsys.geometry.cs.ParameterName) LinkedHashMap(java.util.LinkedHashMap) ChannelWriter(com.revolsys.io.channels.ChannelWriter) Maps(com.revolsys.collection.map.Maps) VerticalCoordinateSystem(com.revolsys.geometry.cs.VerticalCoordinateSystem) Record(com.revolsys.record.Record) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 9 with LinearUnit

use of com.revolsys.geometry.cs.unit.LinearUnit in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystems method getCoordinateSystem.

public static synchronized CoordinateSystem getCoordinateSystem(final CoordinateSystem coordinateSystem) {
    initialize();
    if (coordinateSystem == null) {
        return null;
    } else {
        int srid = coordinateSystem.getCoordinateSystemId();
        CoordinateSystem matchedCoordinateSystem = coordinateSystemsById.get(srid);
        if (matchedCoordinateSystem == null) {
            matchedCoordinateSystem = coordinateSystemsByName.get(coordinateSystem.getCoordinateSystemName());
            if (matchedCoordinateSystem == null) {
                final int hashCode = coordinateSystem.hashCode();
                int matchCoordinateSystemId = 0;
                final List<CoordinateSystem> coordinateSystems = coordinateSystemsByCoordinateSystem.get(hashCode);
                if (coordinateSystems != null) {
                    for (final CoordinateSystem coordinateSystem3 : coordinateSystems) {
                        if (coordinateSystem3.equals(coordinateSystem)) {
                            final int srid3 = coordinateSystem3.getCoordinateSystemId();
                            if (matchedCoordinateSystem == null) {
                                matchedCoordinateSystem = coordinateSystem3;
                                matchCoordinateSystemId = srid3;
                            } else if (srid3 < matchCoordinateSystemId) {
                                if (!coordinateSystem3.isDeprecated() || matchedCoordinateSystem.isDeprecated()) {
                                    matchedCoordinateSystem = coordinateSystem3;
                                    matchCoordinateSystemId = srid3;
                                }
                            }
                        }
                    }
                }
                if (matchedCoordinateSystem == null) {
                    if (srid <= 0) {
                        srid = nextSrid++;
                    }
                    final String name = coordinateSystem.getCoordinateSystemName();
                    final List<Axis> axis = coordinateSystem.getAxis();
                    final Area area = coordinateSystem.getArea();
                    final Authority authority = coordinateSystem.getAuthority();
                    final boolean deprecated = coordinateSystem.isDeprecated();
                    if (coordinateSystem instanceof GeographicCoordinateSystem) {
                        final GeographicCoordinateSystem geographicCs = (GeographicCoordinateSystem) coordinateSystem;
                        final GeodeticDatum geodeticDatum = geographicCs.getDatum();
                        final PrimeMeridian primeMeridian = geographicCs.getPrimeMeridian();
                        final CoordinateSystem sourceCoordinateSystem = geographicCs.getSourceCoordinateSystem();
                        final CoordinateOperation coordinateOperation = geographicCs.getCoordinateOperation();
                        final GeographicCoordinateSystem newCs = new GeographicCoordinateSystem(srid, name, geodeticDatum, primeMeridian, axis, area, sourceCoordinateSystem, coordinateOperation, deprecated);
                        addCoordinateSystem(newCs);
                        return newCs;
                    } else if (coordinateSystem instanceof ProjectedCoordinateSystem) {
                        final ProjectedCoordinateSystem projectedCs = (ProjectedCoordinateSystem) coordinateSystem;
                        GeographicCoordinateSystem geographicCs = projectedCs.getGeographicCoordinateSystem();
                        geographicCs = (GeographicCoordinateSystem) getCoordinateSystem(geographicCs);
                        final CoordinateOperationMethod coordinateOperationMethod = projectedCs.getCoordinateOperationMethod();
                        final Map<ParameterName, ParameterValue> parameters = projectedCs.getParameterValues();
                        final LinearUnit linearUnit = projectedCs.getLinearUnit();
                        final ProjectedCoordinateSystem newCs = new ProjectedCoordinateSystem(srid, name, geographicCs, area, coordinateOperationMethod, parameters, linearUnit, axis, authority, deprecated);
                        addCoordinateSystem(newCs);
                        return newCs;
                    }
                    return coordinateSystem;
                }
            }
        }
        return matchedCoordinateSystem;
    }
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) Authority(com.revolsys.geometry.cs.Authority) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) GeocentricCoordinateSystem(com.revolsys.geometry.cs.GeocentricCoordinateSystem) CompoundCoordinateSystem(com.revolsys.geometry.cs.CompoundCoordinateSystem) VerticalCoordinateSystem(com.revolsys.geometry.cs.VerticalCoordinateSystem) EngineeringCoordinateSystem(com.revolsys.geometry.cs.EngineeringCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeodeticDatum(com.revolsys.geometry.cs.datum.GeodeticDatum) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) PrimeMeridian(com.revolsys.geometry.cs.PrimeMeridian) Area(com.revolsys.geometry.cs.Area) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) Map(java.util.Map) IntHashMap(com.revolsys.collection.map.IntHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Axis(com.revolsys.geometry.cs.Axis)

Example 10 with LinearUnit

use of com.revolsys.geometry.cs.unit.LinearUnit in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystems method loadEllipsoid.

private static IntHashMap<Ellipsoid> loadEllipsoid() {
    final IntHashMap<Ellipsoid> ellipsoids = new IntHashMap<>();
    try (ChannelReader reader = newChannelReader("ellipsoid")) {
        while (true) {
            final int id = reader.getInt();
            final String name = reader.getStringUtf8ByteCount();
            final int unitId = reader.getInt();
            final LinearUnit unit = (LinearUnit) UNIT_BY_ID.get(unitId);
            final double semiMinorAxis = unit.toBase(reader.getDouble());
            final double semiMajorAxis = unit.toBase(reader.getDouble());
            final double inverseFlattening = unit.toBase(reader.getDouble());
            final int ellipsoidShape = reader.getByte();
            final boolean deprecated = readBoolean(reader);
            final EpsgAuthority authority = new EpsgAuthority(id);
            final Ellipsoid ellipsoid = new Ellipsoid(name, semiMajorAxis, semiMinorAxis, inverseFlattening, authority, deprecated);
            ellipsoids.put(id, ellipsoid);
        }
    } catch (final NoSuchResourceException e) {
    } catch (final WrappedException e) {
        if (Exceptions.isException(e, EOFException.class)) {
        } else {
            throw e;
        }
    }
    return ellipsoids;
}
Also used : WrappedException(com.revolsys.util.WrappedException) LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) IntHashMap(com.revolsys.collection.map.IntHashMap) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException) Ellipsoid(com.revolsys.geometry.cs.Ellipsoid)

Aggregations

LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)17 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)9 ParameterName (com.revolsys.geometry.cs.ParameterName)8 Map (java.util.Map)8 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)7 ParameterValue (com.revolsys.geometry.cs.ParameterValue)7 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)7 LinkedHashMap (java.util.LinkedHashMap)7 Authority (com.revolsys.geometry.cs.Authority)4 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 VerticalDatum (com.revolsys.geometry.cs.datum.VerticalDatum)4 ChannelReader (com.revolsys.io.channels.ChannelReader)4 WrappedException (com.revolsys.util.WrappedException)4 EOFException (java.io.EOFException)4 IntHashMap (com.revolsys.collection.map.IntHashMap)3 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)3 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)3 NoSuchResourceException (com.revolsys.spring.resource.NoSuchResourceException)3 HashMap (java.util.HashMap)3 Maps (com.revolsys.collection.map.Maps)2