Search in sources :

Example 31 with Record

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

the class OgrQueryIterator method getNext.

@Override
protected Record getNext() throws NoSuchElementException {
    if (this.layer == null) {
        throw new NoSuchElementException();
    } else {
        while (this.offset > 0 && this.count < this.offset) {
            final Feature feature = this.layer.GetNextFeature();
            if (feature == null) {
                throw new NoSuchElementException();
            } else {
                feature.delete();
            }
            this.count++;
        }
        if (this.count - this.offset >= this.limit) {
            throw new NoSuchElementException();
        }
        final Feature feature = this.layer.GetNextFeature();
        this.count++;
        if (feature == null) {
            throw new NoSuchElementException();
        } else {
            try {
                final Record record = this.recordFactory.newRecord(this.recordDefinition);
                record.setState(RecordState.INITIALIZING);
                if (this.labelCountMap == null) {
                    this.recordStore.addStatistic("query", record);
                } else {
                    this.labelCountMap.addCount(record);
                }
                final int fieldCount = feature.GetFieldCount();
                for (int fieldIndex = 0; fieldIndex < fieldCount; fieldIndex++) {
                    final String fieldName = feature.GetFieldDefnRef(fieldIndex).GetName();
                    if (feature.IsFieldSet(fieldIndex)) {
                        final int fieldType = feature.GetFieldType(fieldIndex);
                        Object value;
                        switch(fieldType) {
                            case 0:
                                value = feature.GetFieldAsInteger(fieldIndex);
                                break;
                            case 1:
                                value = feature.GetFieldAsIntegerList(fieldIndex);
                                break;
                            case 2:
                                value = feature.GetFieldAsDouble(fieldIndex);
                                break;
                            case 3:
                                value = feature.GetFieldAsDoubleList(fieldIndex);
                                break;
                            case 4:
                            case 6:
                                value = feature.GetFieldAsString(fieldIndex);
                                break;
                            case 5:
                            case 7:
                                value = feature.GetFieldAsStringList(fieldIndex);
                                break;
                            case 8:
                                value = null;
                                // binary
                                break;
                            case 9:
                                final Calendar date = getCalendar(feature, fieldIndex);
                                value = new Date(date.getTimeInMillis());
                                break;
                            case 10:
                                value = null;
                                // time
                                break;
                            case 11:
                                final Calendar dateTime = getCalendar(feature, fieldIndex);
                                value = new java.util.Date(dateTime.getTimeInMillis());
                                break;
                            default:
                                value = null;
                                break;
                        }
                        record.setValue(fieldName, value);
                    }
                }
                final int geometryCount = feature.GetGeomFieldCount();
                for (int geometryIndex = 0; geometryIndex < geometryCount; geometryIndex++) {
                    final String fieldName = feature.GetGeomFieldDefnRef(geometryIndex).GetName();
                    final org.gdal.ogr.Geometry ogrGeometry = feature.GetGeomFieldRef(geometryIndex);
                    final Geometry geometry = toGeometry(ogrGeometry);
                    record.setValue(fieldName, geometry);
                }
                record.setState(RecordState.PERSISTED);
                return record;
            } finally {
                feature.delete();
            }
        }
    }
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) LineString(com.revolsys.geometry.model.LineString) Feature(org.gdal.ogr.Feature) Date(java.sql.Date) Geometry(com.revolsys.geometry.model.Geometry) Record(com.revolsys.record.Record) NoSuchElementException(java.util.NoSuchElementException)

Example 32 with Record

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

the class GraphProcessor method postRun.

@Override
protected void postRun(final Channel<Record> in, final Channel<Record> out) {
    if (out != null) {
        processGraph();
        for (final Edge<Record> edge : this.graph.getEdges()) {
            final Record object = edge.getObject();
            out.write(object);
        }
    }
}
Also used : Record(com.revolsys.record.Record)

Example 33 with Record

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

the class EqualTypeAndLineEdgeCleanupVisitor method processEqualEdge.

private void processEqualEdge(final Edge<Record> edge1, final Edge<Record> edge2) {
    final Record record1 = edge1.getObject();
    final Record record2 = edge2.getObject();
    final boolean equalAttributes = record1.equalValuesExclude(record2, this.equalExcludeFieldNames);
    final LineString line1 = edge1.getLineString();
    int compare = 0;
    final Comparator<Edge<Record>> comparator = getComparator();
    if (comparator != null) {
        compare = comparator.compare(edge1, edge2);
    }
    if (compare == 0) {
        if (equalAttributes) {
            boolean equalExcludedAttributes = true;
            for (final String name : this.equalExcludeFieldNames) {
                if (!record1.equalValue(record2, name)) {
                    equalExcludedAttributes = false;
                }
            }
            final LineString line2 = edge2.getLineString();
            final boolean equalZ = fixMissingZValues(line1, line2);
            if (equalExcludedAttributes) {
                if (equalZ) {
                    removeDuplicate(edge2, edge1);
                } else {
                    RecordLog.error(getClass(), "Equal geometry with different coordinates or Z-values", record1);
                }
            } else {
                RecordLog.error(getClass(), "Equal geometry with different attributes: ", record1);
            }
        } else {
            RecordLog.error(getClass(), "Equal geometry with different attributes: ", record1);
        }
    } else {
        removeDuplicate(edge2, edge1);
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Record(com.revolsys.record.Record) LineString(com.revolsys.geometry.model.LineString) Edge(com.revolsys.geometry.graph.Edge)

Example 34 with Record

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

the class NodeRemovalVisitor method accept.

@Override
public void accept(final Node<Record> node) {
    if (node.getDegree() == 2) {
        final List<Edge<Record>> edges = node.getEdges();
        if (edges.size() == 2) {
            final Edge<Record> edge1 = edges.get(0);
            final Edge<Record> edge2 = edges.get(1);
            if (edge1 != edge2) {
                final Record object1 = edge1.getObject();
                final Record object2 = edge2.getObject();
                if (DataType.equal(object1, object2, this.excludedFieldNames)) {
                    final End end1 = edge1.getEnd(node);
                    if (end1 == edge2.getEnd(node)) {
                        // if (!fixReversedEdges(node, reversedEdges, edge1, edge2)) {
                        return;
                    // }
                    }
                    if (end1.isFrom()) {
                        this.graph.merge(node, edge2, edge1);
                    } else {
                        this.graph.merge(node, edge1, edge2);
                    }
                }
            }
        }
    }
}
Also used : Record(com.revolsys.record.Record) End(com.revolsys.geometry.model.End) Edge(com.revolsys.geometry.graph.Edge)

Example 35 with Record

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

the class PointRecordMap method addRecord.

/**
 * Add a {@link Point} {@link Record} to the list of objects at the given
 * coordinate.
 *
 * @param pointObjects The map of point objects.
 * @param record The object to add.
 */
public boolean addRecord(final Record record) {
    final Point key = getKey(record);
    final List<Record> records = getOrCreateRecords(key);
    if (records.add(record)) {
        if (this.comparator != null) {
            Collections.sort(records, this.comparator);
        }
        this.size++;
        return true;
    } else {
        return false;
    }
}
Also used : Record(com.revolsys.record.Record) Point(com.revolsys.geometry.model.Point)

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