Search in sources :

Example 66 with Record

use of com.revolsys.record.Record in project com.revolsys.open by revolsys.

the class XbaseIterator method getNext.

@Override
protected Record getNext() {
    try {
        Record object = null;
        this.deletedCount = this.currentDeletedCount;
        this.currentDeletedCount = 0;
        int deleteFlag = ' ';
        do {
            deleteFlag = this.in.read();
            if (deleteFlag == -1) {
                throw new NoSuchElementException();
            } else if (deleteFlag == ' ') {
                object = loadRecord();
            } else if (deleteFlag != 0x1A) {
                this.currentDeletedCount++;
                this.in.read(this.recordBuffer);
                this.position++;
            }
        } while (deleteFlag == '*');
        if (object == null) {
            throw new NoSuchElementException();
        }
        return object;
    } catch (final IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : Record(com.revolsys.record.Record) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException)

Example 67 with Record

use of com.revolsys.record.Record in project com.revolsys.open by revolsys.

the class XbaseRecordReader method loadRecord.

protected Record loadRecord() throws IOException {
    final Record record = this.recordFactory.newRecord(this.recordDefinition);
    for (int i = 0; i < this.recordDefinition.getFieldCount(); i++) {
        int length = this.recordDefinition.getFieldLength(i);
        final DataType type = this.recordDefinition.getFieldType(i);
        Object value = null;
        if (type == DataTypes.STRING) {
            if (length < 255) {
                value = getString(length);
            } else {
                value = getMemo(length);
                length = 10;
            }
        } else if (type == DataTypes.DECIMAL || type == DataTypes.FLOAT) {
            value = getNumber(length);
        } else if (type == DataTypes.BOOLEAN) {
            value = getBoolean();
        } else if (type == DataTypes.DATE_TIME) {
            value = getDate(length);
        }
        record.setValue(i, value);
    }
    return record;
}
Also used : DataType(com.revolsys.datatype.DataType) Record(com.revolsys.record.Record)

Example 68 with Record

use of com.revolsys.record.Record in project com.revolsys.open by revolsys.

the class XbaseRecordReader method getNext.

@Override
protected Record getNext() {
    try {
        Record record = null;
        this.deletedCount = this.currentDeletedCount;
        this.currentDeletedCount = 0;
        int deleteFlag = ' ';
        do {
            this.recordBuffer.clear();
            final int readCount = Buffers.readAll(this.in, this.recordBuffer);
            if (readCount == -1) {
                throw new NoSuchElementException();
            } else if (readCount == 1) {
                throw new NoSuchElementException();
            } else if (readCount != this.recordSize) {
                throw new IllegalStateException("Unexpected end of mappedFile");
            } else {
                deleteFlag = this.recordBuffer.get();
                if (deleteFlag == -1) {
                    throw new NoSuchElementException();
                } else if (deleteFlag == ' ') {
                    record = loadRecord();
                } else if (deleteFlag != 0x1A) {
                    this.currentDeletedCount++;
                    this.position++;
                }
            }
        } while (deleteFlag == '*');
        if (record == null) {
            throw new NoSuchElementException();
        }
        return record;
    } catch (final IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : Record(com.revolsys.record.Record) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException)

Example 69 with Record

use of com.revolsys.record.Record 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 70 with Record

use of com.revolsys.record.Record 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)

Aggregations

Record (com.revolsys.record.Record)198 ArrayRecord (com.revolsys.record.ArrayRecord)43 RecordReader (com.revolsys.record.io.RecordReader)34 RecordDefinition (com.revolsys.record.schema.RecordDefinition)34 Geometry (com.revolsys.geometry.model.Geometry)29 LineString (com.revolsys.geometry.model.LineString)21 Point (com.revolsys.geometry.model.Point)20 ChannelWriter (com.revolsys.io.channels.ChannelWriter)19 Identifier (com.revolsys.identifier.Identifier)17 ArrayList (java.util.ArrayList)16 FieldDefinition (com.revolsys.record.schema.FieldDefinition)15 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)14 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)13 NoSuchElementException (java.util.NoSuchElementException)13 DataType (com.revolsys.datatype.DataType)10 Query (com.revolsys.record.query.Query)9 HashMap (java.util.HashMap)9 List (java.util.List)8 LinkedHashMap (java.util.LinkedHashMap)7 Edge (com.revolsys.geometry.graph.Edge)6