Search in sources :

Example 6 with RecordReader

use of com.revolsys.record.io.RecordReader in project com.revolsys.open by revolsys.

the class TransverseMercatorTest method testMascotThomas.

// @Test
// public void testMascotJhs() {
// testUtmMascot(TransverseMercatorJhs::newUtm);
// }
@Test
public void testMascotThomas() {
    final Map<Integer, CoordinatesProjection> projectionById = new HashMap<>();
    try (RecordReader recordReader = RecordReader.newRecordReader("../../com.revolsys.open-testdata/cs/transverseMercator/mascot.csv")) {
        for (final Record record : recordReader) {
            final String monumentId = record.getValue("monumentId");
            final int longitudeDegrees = record.getInteger("longitudeDegrees");
            final int longitudeMinutes = record.getInteger("longitudeMinutes");
            final double longitudeSeconds = record.getDouble("longitudeSeconds");
            final int latitudeDegrees = record.getInteger("latitudeDegrees");
            final int latitudeMinutes = record.getInteger("latitudeMinutes");
            final double latitudeSeconds = record.getDouble("latitudeSeconds");
            final double lon = record.getDouble("lon");
            final double lat = record.getDouble("lat");
            final double lonCalc = Angle.toDecimalDegrees(longitudeDegrees, longitudeMinutes, longitudeSeconds);
            final double latCalc = Angle.toDecimalDegrees(latitudeDegrees, latitudeMinutes, latitudeSeconds);
            final String lonStringCalc = Angle.toDegreesMinutesSecondsLon(lon, 5);
            final String latStringCalc = Angle.toDegreesMinutesSecondsLat(lat, 5);
            Assert.assertEquals(monumentId + "\tlon", lon, lonCalc, 1e-12);
            Assert.assertEquals(monumentId + "\tlat", lat, latCalc, 1e-12);
            final double x = record.getDouble("x");
            final double y = record.getDouble("y");
            final int utmReferenceMeridian = record.getInteger("utmReferenceMeridian");
            CoordinatesProjection mercator = projectionById.get(utmReferenceMeridian);
            if (mercator == null) {
                final Ellipsoid ellipsoid = new Ellipsoid("NAD83", 6378137, 298.257222101);
                mercator = new TransverseMercatorThomas("", ellipsoid, utmReferenceMeridian, 0, 0.9996, 500000, 0);
                projectionById.put(utmReferenceMeridian, mercator);
            }
            final double[] coordinates = new double[2];
            mercator.project(lon, lat, coordinates, 0);
            final double xActual = coordinates[0];
            final double yActual = coordinates[1];
            Assert.assertEquals(monumentId + "\tproj x", x, xActual, 1e-3);
            Assert.assertEquals(monumentId + "\tproj y", y, yActual, 2e-3);
            mercator.inverse(x, y, coordinates, 0);
            final double lonActual = coordinates[0];
            final double latActual = coordinates[1];
            assertDms(monumentId + "\tlon", longitudeDegrees, longitudeMinutes, longitudeSeconds, lonActual, DP_5);
            assertDms(monumentId + "\tlat", latitudeDegrees, latitudeMinutes, latitudeSeconds, latActual, DP_5);
            final String lonStringActual = Angle.toDegreesMinutesSecondsLon(lonActual, 5);
            final String latStringActual = Angle.toDegreesMinutesSecondsLat(latActual, 5);
            if (!equalDms(lonStringCalc, lonStringActual, 0.00005)) {
                Assert.assertEquals(monumentId + "\tlon dms", lonStringCalc, lonStringActual);
            }
            if (!equalDms(latStringCalc, latStringActual, 0.00005)) {
                Assert.assertEquals(monumentId + "\tlat dms", latStringCalc, latStringActual);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) RecordReader(com.revolsys.record.io.RecordReader) Record(com.revolsys.record.Record) Ellipsoid(com.revolsys.geometry.cs.Ellipsoid) Test(org.junit.Test)

Example 7 with RecordReader

use of com.revolsys.record.io.RecordReader in project com.revolsys.open by revolsys.

the class TransverseMercatorTest method testUtmMascot.

private void testUtmMascot(final BiFunction<Ellipsoid, Double, TransverseMercator> projectionFactory) {
    final Map<Integer, CoordinatesProjection> projectionById = new HashMap<>();
    try (RecordReader recordReader = RecordReader.newRecordReader("../../com.revolsys.open-testdata/cs/transverseMercator/mascot.csv")) {
        for (final Record record : recordReader) {
            final String monumentId = record.getValue("monumentId");
            final int longitudeDegrees = record.getInteger("longitudeDegrees");
            final int longitudeMinutes = record.getInteger("longitudeMinutes");
            final double longitudeSeconds = record.getDouble("longitudeSeconds");
            final int latitudeDegrees = record.getInteger("latitudeDegrees");
            final int latitudeMinutes = record.getInteger("latitudeMinutes");
            final double latitudeSeconds = record.getDouble("latitudeSeconds");
            final double lon = record.getDouble("lon");
            final double lat = record.getDouble("lat");
            final double lonCalc = Angle.toDecimalDegrees(longitudeDegrees, longitudeMinutes, longitudeSeconds);
            final double latCalc = Angle.toDecimalDegrees(latitudeDegrees, latitudeMinutes, latitudeSeconds);
            Assert.assertEquals(monumentId + "\tlon", lon, lonCalc, 1e-12);
            Assert.assertEquals(monumentId + "\tlat", lat, latCalc, 1e-12);
            final double x = record.getDouble("x");
            final double y = record.getDouble("y");
            final int utmReferenceMeridian = record.getInteger("utmReferenceMeridian");
            CoordinatesProjection mercator = projectionById.get(utmReferenceMeridian);
            if (mercator == null) {
                final Ellipsoid ellipsoid = new Ellipsoid("NAD83", 6378137, 298.257222101);
                mercator = projectionFactory.apply(ellipsoid, (double) utmReferenceMeridian);
                projectionById.put(utmReferenceMeridian, mercator);
            }
            final double[] coordinates = new double[2];
            mercator.project(lon, lat, coordinates, 0);
            final double xActual = coordinates[0];
            final double yActual = coordinates[1];
            Assert.assertEquals(monumentId + "\tproj x", x, xActual, 1e-3);
            Assert.assertEquals(monumentId + "\tproj y", y, yActual, 2e-3);
            mercator.inverse(x, y, coordinates, 0);
            final double lonActual = coordinates[0];
            final double latActual = coordinates[1];
            assertDms(monumentId + "\tlon", longitudeDegrees, longitudeMinutes, longitudeSeconds, lonActual, DP_4);
            assertDms(monumentId + "\tlat", latitudeDegrees, latitudeMinutes, latitudeSeconds, latActual, DP_4);
        }
    }
}
Also used : HashMap(java.util.HashMap) RecordReader(com.revolsys.record.io.RecordReader) Record(com.revolsys.record.Record) Ellipsoid(com.revolsys.geometry.cs.Ellipsoid)

Example 8 with RecordReader

use of com.revolsys.record.io.RecordReader in project com.revolsys.open by revolsys.

the class EsriCoordinateSystemsLoader method geographic.

private void geographic() {
    final Map<ByteArray, Map<Integer, GeographicCoordinateSystem>> csBymd5 = new LinkedHashMap<>();
    try (RecordReader reader = RecordReader.newRecordReader(this.mainPath + "data/esri/esriGeographicCs.tsv");
        final ChannelWriter writer = ChannelWriter.newChannelWriter(this.mainPath + "resources/CoordinateSystems/esri/Geographic.cs")) {
        for (final Record record : reader) {
            final int id = record.getInteger("ID");
            final String wkt = record.getString("WKT");
            final GeographicCoordinateSystem coordinateSystem = WktCsParser.read(wkt);
            final byte[] digest = coordinateSystem.md5Digest();
            Maps.addToMap(Maps::newTree, csBymd5, new ByteArray(digest), id, coordinateSystem);
            final GeodeticDatum datum = coordinateSystem.getDatum();
            final Ellipsoid ellipsoid = datum.getEllipsoid();
            final PrimeMeridian primeMeridian = coordinateSystem.getPrimeMeridian();
            final AngularUnit angularUnit = coordinateSystem.getAngularUnit();
            final String csName = coordinateSystem.getCoordinateSystemName();
            this.geographicIdByName.put(csName, id);
            final String datumName = datum.getName();
            final String spheroidName = ellipsoid.getName();
            final double semiMajorAxis = ellipsoid.getSemiMajorAxis();
            final double inverseFlattening = ellipsoid.getInverseFlattening();
            final String primeMeridianName = primeMeridian.getName();
            final double longitude = primeMeridian.getLongitude();
            final String angularUnitName = angularUnit.getName();
            final double conversionFactor = angularUnit.getConversionFactor();
            writer.putInt(id);
            writer.putStringUtf8ByteCount(csName);
            writer.putStringUtf8ByteCount(datumName);
            writer.putStringUtf8ByteCount(spheroidName);
            writer.putDouble(semiMajorAxis);
            writer.putDouble(inverseFlattening);
            writer.putStringUtf8ByteCount(primeMeridianName);
            writer.putDouble(longitude);
            writer.putStringUtf8ByteCount(angularUnitName);
            writer.putDouble(conversionFactor);
        }
    }
    writeDigestFile(csBymd5, "Geographic");
}
Also used : RecordReader(com.revolsys.record.io.RecordReader) GeodeticDatum(com.revolsys.geometry.cs.datum.GeodeticDatum) PrimeMeridian(com.revolsys.geometry.cs.PrimeMeridian) AngularUnit(com.revolsys.geometry.cs.unit.AngularUnit) 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) Ellipsoid(com.revolsys.geometry.cs.Ellipsoid)

Example 9 with RecordReader

use of com.revolsys.record.io.RecordReader 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 10 with RecordReader

use of com.revolsys.record.io.RecordReader in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystemsLoader method loadCoordOperation.

private void loadCoordOperation() {
    try (final RecordReader reader = newReader("/public/epsg_coordoperation", "coord_op_code");
        ChannelWriter writer = newWriter("coordOperation")) {
        for (final Record record : reader) {
            writeInt(writer, record, "coord_op_code");
            writeInt(writer, record, "coord_op_method_code", 0);
            writeString(writer, record, "coord_op_name");
            writeCodeByte(writer, record, "coord_op_type", COORDINATE_OPERATION_TYPES);
            writeInt(writer, record, "source_crs_code", 0);
            writeInt(writer, record, "target_crs_code", 0);
            writeString(writer, record, "coord_tfm_version");
            writeInt(writer, record, "coord_op_variant", 0);
            writeInt(writer, record, "area_of_use", 0);
            writeDouble(writer, record, "coord_op_accuracy");
            writeDeprecated(writer, record);
        }
    }
}
Also used : RecordReader(com.revolsys.record.io.RecordReader) Record(com.revolsys.record.Record) ChannelWriter(com.revolsys.io.channels.ChannelWriter)

Aggregations

RecordReader (com.revolsys.record.io.RecordReader)43 Record (com.revolsys.record.Record)34 ChannelWriter (com.revolsys.io.channels.ChannelWriter)19 RecordDefinition (com.revolsys.record.schema.RecordDefinition)11 Identifier (com.revolsys.identifier.Identifier)5 ArrayRecord (com.revolsys.record.ArrayRecord)5 ListRecordReader (com.revolsys.record.io.ListRecordReader)5 Query (com.revolsys.record.query.Query)5 HashMap (java.util.HashMap)5 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)4 BaseCloseable (com.revolsys.io.BaseCloseable)4 Transaction (com.revolsys.transaction.Transaction)4 ArrayList (java.util.ArrayList)4 Maps (com.revolsys.collection.map.Maps)3 Ellipsoid (com.revolsys.geometry.cs.Ellipsoid)3 Geometry (com.revolsys.geometry.model.Geometry)3 RecordWriter (com.revolsys.record.io.RecordWriter)3 RecordStore (com.revolsys.record.schema.RecordStore)3 Resource (com.revolsys.spring.resource.Resource)3 LinkedHashMap (java.util.LinkedHashMap)3