Search in sources :

Example 26 with ChannelWriter

use of com.revolsys.io.channels.ChannelWriter in project com.revolsys.open by revolsys.

the class EsriCoordinateSystemsLoader method writeDigestFile.

private <C extends CoordinateSystem> void writeDigestFile(final Map<ByteArray, Map<Integer, C>> csBymd5, final String csType) {
    try (final ChannelWriter writer = ChannelWriter.newChannelWriter(this.mainPath + "resources/CoordinateSystems/esri/" + csType + ".digest")) {
        for (final Entry<ByteArray, Map<Integer, C>> entry : csBymd5.entrySet()) {
            final ByteArray digest = entry.getKey();
            writer.putBytes(digest.getData());
            final Map<Integer, C> coordinateSystemById = entry.getValue();
            writer.putShort((short) coordinateSystemById.size());
            for (final Integer id : coordinateSystemById.keySet()) {
                writer.putInt(id);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ChannelWriter(com.revolsys.io.channels.ChannelWriter)

Example 27 with ChannelWriter

use of com.revolsys.io.channels.ChannelWriter in project com.revolsys.open by revolsys.

the class EsriCoordinateSystemsLoader method projected.

private void projected() {
    final Map<ByteArray, Map<Integer, ProjectedCoordinateSystem>> csBymd5 = new LinkedHashMap<>();
    try (RecordReader reader = RecordReader.newRecordReader(this.mainPath + "data/esri/esriProjectedCs.tsv");
        final ChannelWriter writer = ChannelWriter.newChannelWriter(this.mainPath + "resources/CoordinateSystems/esri/Projected.cs")) {
        for (final Record record : reader) {
            final int id = record.getInteger("ID");
            final String wkt = record.getString("WKT");
            final ProjectedCoordinateSystem coordinateSystem = WktCsParser.read(wkt);
            final byte[] digest = coordinateSystem.md5Digest();
            Maps.addToMap(Maps::newTree, csBymd5, new ByteArray(digest), id, coordinateSystem);
            final String csName = coordinateSystem.getCoordinateSystemName();
            final GeographicCoordinateSystem geographicCoordinateSystem = coordinateSystem.getGeographicCoordinateSystem();
            final String geographicCoordinateSystemName = geographicCoordinateSystem.getCoordinateSystemName();
            final int geographicCoordinateSystemId = this.geographicIdByName.getOrDefault(geographicCoordinateSystemName, 0);
            if (geographicCoordinateSystemId == 0) {
                System.out.println(wkt);
            }
            final String projectionName = coordinateSystem.getCoordinateOperationMethod().getName();
            final Map<ParameterName, ParameterValue> parameterValues = coordinateSystem.getParameterValues();
            final LinearUnit linearUnit = coordinateSystem.getLinearUnit();
            final String unitName = linearUnit.getName();
            final double conversionFactor = linearUnit.getConversionFactor();
            writer.putInt(id);
            writer.putStringUtf8ByteCount(csName);
            writer.putInt(geographicCoordinateSystemId);
            writer.putStringUtf8ByteCount(projectionName);
            writeParameters(writer, parameterValues);
            writer.putStringUtf8ByteCount(unitName);
            writer.putDouble(conversionFactor);
        }
    }
    writeDigestFile(csBymd5, "Projected");
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValue(com.revolsys.geometry.cs.ParameterValue) RecordReader(com.revolsys.record.io.RecordReader) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ParameterName(com.revolsys.geometry.cs.ParameterName) LinkedHashMap(java.util.LinkedHashMap) ChannelWriter(com.revolsys.io.channels.ChannelWriter) Maps(com.revolsys.collection.map.Maps) Record(com.revolsys.record.Record) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ChannelWriter (com.revolsys.io.channels.ChannelWriter)27 Record (com.revolsys.record.Record)19 RecordReader (com.revolsys.record.io.RecordReader)19 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 Maps (com.revolsys.collection.map.Maps)3 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)2 ParameterName (com.revolsys.geometry.cs.ParameterName)2 ParameterValue (com.revolsys.geometry.cs.ParameterValue)2 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)2 BoundingBox (com.revolsys.geometry.model.BoundingBox)2 IOException (java.io.IOException)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 Ellipsoid (com.revolsys.geometry.cs.Ellipsoid)1 PrimeMeridian (com.revolsys.geometry.cs.PrimeMeridian)1 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)1 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)1