Search in sources :

Example 71 with Record

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

the class Property method get.

@SuppressWarnings("unchecked")
static <T> T get(final Object object, final String key) {
    if (object == null) {
        return null;
    } else {
        if (object instanceof Record) {
            final Record record = (Record) object;
            return record.getValueByPath(key);
        } else if (object instanceof Map) {
            final Map<String, ?> map = (Map<String, ?>) object;
            return (T) map.get(key);
        } else if (object instanceof Annotation) {
            final Annotation annotation = (Annotation) object;
            return (T) AnnotationUtils.getValue(annotation, key);
        } else {
            final String firstName = Property.getFirstName(key);
            final String subName = Property.getSubName(key);
            final Object value = Property.getSimple(object, firstName);
            if (value == null || !Property.hasValue(subName)) {
                return (T) value;
            } else {
                return (T) get(value, subName);
            }
        }
    }
}
Also used : Record(com.revolsys.record.Record) Map(java.util.Map) Annotation(java.lang.annotation.Annotation)

Example 72 with Record

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

the class Property method set.

static void set(final Object object, final String propertyName, final Object value) {
    if (object != null) {
        if (object instanceof Record) {
            final Record record = (Record) object;
            record.setValueByPath(propertyName, value);
        } else if (object instanceof Map) {
            @SuppressWarnings("unchecked") final Map<String, Object> map = (Map<String, Object>) object;
            map.put(propertyName, value);
        } else {
            setSimple(object, propertyName, value);
        }
    }
}
Also used : Record(com.revolsys.record.Record) Map(java.util.Map)

Example 73 with Record

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

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

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

the class RecordWriterPerformanceTest method newRecord.

private static Record newRecord(final RecordDefinition recordDefinition, final int index) {
    final Record record = new ArrayRecord(recordDefinition);
    record.setValue("boolean", index % 2 == 0);
    record.setValue("byte", index % 256 + Byte.MIN_VALUE);
    record.setValue("short", index % 65536 + Short.MIN_VALUE);
    record.setValue("int", index);
    record.setValue("long", index);
    record.setValue("float", index + index % 1000 / 1000.0);
    record.setValue("double", index + index % 1000 / 1000.0);
    record.setValue("string", "String with some special characters " + index + "\\/\"'\t\n\r");
    final Calendar calendar = new GregorianCalendar();
    calendar.set(2016, 11, index % 28 + 1, 0, 0);
    final Date date = new Date(calendar.getTimeInMillis());
    record.setValue("date", date);
    calendar.set(Calendar.MINUTE, index % 60);
    final java.util.Date dateTime = new java.util.Date(calendar.getTimeInMillis());
    record.setValue("dateTime", dateTime);
    calendar.set(Calendar.MILLISECOND, index % 1000);
    final Timestamp timestamp = new Timestamp(calendar.getTimeInMillis());
    record.setValue("timestamp", timestamp);
    record.setValue("geometry", new PointDoubleXY(index, index * 2));
    return record;
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Timestamp(java.sql.Timestamp) Date(java.sql.Date)

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