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();
}
}
}
}
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);
}
}
}
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);
}
}
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);
}
}
}
}
}
}
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;
}
}
Aggregations