use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class GmlRecordWriter method write.
@Override
public void write(final Record record) {
if (!this.opened) {
writeHeader();
}
this.out.startTag(Gml.FEATURE_MEMBER);
final RecordDefinition recordDefinition = record.getRecordDefinition();
QName qualifiedName = recordDefinition.getProperty(RecordProperties.QUALIFIED_NAME);
if (qualifiedName == null) {
final String typeName = recordDefinition.getPath();
final String path = PathUtil.getPath(typeName);
final String name = PathUtil.getName(typeName);
qualifiedName = new QName(path, name);
recordDefinition.setProperty(RecordProperties.QUALIFIED_NAME, qualifiedName);
}
this.out.startTag(qualifiedName);
for (final FieldDefinition fieldDefinition : recordDefinition.getFields()) {
final String fieldName = fieldDefinition.getName();
final Object value;
if (isWriteCodeValues()) {
value = record.getCodeValue(fieldName);
} else {
value = record.getValue(fieldName);
}
if (isValueWritable(value)) {
this.out.startTag(this.namespaceUri, fieldName);
final DataType dataType = fieldDefinition.getDataType();
final GmlFieldType fieldType = this.fieldTypes.getFieldType(dataType);
if (fieldType != null) {
fieldType.writeValue(this.out, value);
}
this.out.endTag();
}
}
this.out.endTag(qualifiedName);
this.out.endTag(Gml.FEATURE_MEMBER);
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class KmlRecordWriter method write.
@Override
public void write(final Record record) {
try {
open();
this.writer.write("<Placemark>\n");
final RecordDefinition recordDefinition = record.getRecordDefinition();
final int geometryIndex = recordDefinition.getGeometryFieldIndex();
final int idIndex = recordDefinition.getIdFieldIndex();
final String nameAttribute = getProperty(PLACEMARK_NAME_ATTRIBUTE_PROPERTY);
String name = null;
if (nameAttribute != null) {
name = record.getValue(nameAttribute);
}
if (name == null && idIndex != -1) {
final Object id = record.getValue(idIndex);
final String typeName = recordDefinition.getName();
name = typeName + " " + id;
}
if (name != null) {
this.writer.write("<name>");
XmlWriter.writeElementContent(this.writer, name);
this.writer.write("</name>\n");
}
final String snippet = getProperty(SNIPPET_PROPERTY);
if (snippet != null) {
this.writer.write("<Snippet>");
XmlWriter.writeElementContent(this.writer, snippet);
this.writer.write("</Snippet>\n");
}
String description = getProperty(PLACEMARK_DESCRIPTION_PROPERTY);
if (description == null) {
description = getProperty(IoConstants.DESCRIPTION_PROPERTY);
}
if (Property.hasValue(description)) {
this.writer.write("<description>");
this.writer.write("<![CDATA[");
this.writer.write(description);
this.writer.write("]]>");
this.writer.write("<description>");
}
Geometry geometry = null;
GeometryFactory kmlGeometryFactory = GEOMETRY_FACTORY_2D;
final List<Integer> geometryFieldIndexes = recordDefinition.getGeometryFieldIndexes();
if (!geometryFieldIndexes.isEmpty()) {
if (geometryFieldIndexes.size() == 1) {
geometry = record.getValue(geometryFieldIndexes.get(0));
final int axisCount = geometry.getAxisCount();
if (axisCount > 2) {
kmlGeometryFactory = GEOMETRY_FACTORY_2D.convertAxisCount(axisCount);
}
geometry = geometry.convertGeometry(kmlGeometryFactory);
} else {
final List<Geometry> geometries = new ArrayList<>();
for (final Integer geometryFieldIndex : geometryFieldIndexes) {
Geometry part = record.getValue(geometryFieldIndex);
if (part != null) {
final int axisCount = part.getAxisCount();
if (axisCount > 2) {
kmlGeometryFactory = GEOMETRY_FACTORY_2D.convertAxisCount(axisCount);
}
part = part.convertGeometry(kmlGeometryFactory);
if (!part.isEmpty()) {
geometries.add(part);
}
}
}
if (!geometries.isEmpty()) {
geometry = kmlGeometryFactory.geometry(geometries);
}
}
}
writeLookAt(record.getGeometry());
if (Property.hasValue(this.styleUrl)) {
this.writer.write("<styleUrl>");
XmlWriter.writeElementContent(this.writer, this.styleUrl);
this.writer.write("</styleUrl>\n");
} else if (Property.hasValue(this.defaultStyleUrl)) {
this.writer.write("<styleUrl>");
XmlWriter.writeElementContent(this.writer, this.defaultStyleUrl);
this.writer.write("</styleUrl>\n");
}
boolean hasValues = false;
for (final FieldDefinition field : recordDefinition.getFields()) {
final int fieldIndex = field.getIndex();
if (fieldIndex != geometryIndex) {
final String fieldName = field.getName();
final Object value;
if (isWriteCodeValues()) {
value = record.getCodeValue(fieldIndex);
} else {
value = record.getValue(fieldIndex);
}
if (isValueWritable(value)) {
if (!hasValues) {
hasValues = true;
this.writer.write("<ExtendedData>\n");
}
this.writer.write("<Data name=\"");
XmlWriter.writeAttributeContent(this.writer, fieldName);
this.writer.write("\">\n");
this.writer.write("<value>");
if (Property.hasValue(value)) {
XmlWriter.writeElementContent(this.writer, value.toString());
}
this.writer.write("</value>\n");
this.writer.write("</Data>\n");
}
}
}
if (hasValues) {
this.writer.write("</ExtendedData>\n");
}
if (geometry != null) {
GeometryFactory geometryFactory = getProperty(IoConstants.GEOMETRY_FACTORY);
if (geometryFactory == null) {
geometryFactory = geometry.getGeometryFactory();
}
final int axisCount = geometryFactory.getAxisCount();
KmlWriterUtil.writeGeometry(this.writer, geometry, axisCount);
}
this.writer.write("</Placemark>\n");
} catch (final IOException e) {
throw Exceptions.wrap(e);
}
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class DirectionalFields method getMergedMap.
public Map<String, Object> getMergedMap(final Point point, final Record record1, Record record2) {
final LineString line1 = record1.getGeometry();
LineString line2 = record2.getGeometry();
Record fromRecord;
Record toRecord;
LineString newLine;
final Vertex line1From = line1.getVertex(0);
final Vertex line2From = line2.getVertex(0);
if (line1From.equals(2, line2From) && line1From.equals(2, point)) {
record2 = getReverse(record2);
line2 = record2.getGeometry();
fromRecord = record2;
toRecord = record1;
newLine = line1.merge(point, line2);
} else {
final Vertex line1To = line1.getToVertex(0);
final Vertex line2To = line2.getToVertex(0);
if (line1To.equals(2, line2To) && line1To.equals(2, point)) {
record2 = getReverse(record2);
line2 = record2.getGeometry();
fromRecord = record1;
toRecord = record2;
newLine = line1.merge(point, line2);
} else if (line1To.equals(2, line2From) && line1To.equals(2, point)) {
fromRecord = record1;
toRecord = record2;
newLine = line1.merge(point, line2);
} else if (line1From.equals(2, line2To) && line1From.equals(2, point)) {
fromRecord = record2;
toRecord = record1;
newLine = line2.merge(point, line1);
} else {
throw new IllegalArgumentException("Lines for records don't touch");
}
}
final Map<String, Object> newValues = new LinkedHashMap<>(record1);
setFromFieldValues(fromRecord, toRecord, newValues);
setToFieldValues(toRecord, fromRecord, newValues);
final RecordDefinition recordDefinition = record1.getRecordDefinition();
final String geometryFieldName = recordDefinition.getGeometryFieldName();
newValues.put(geometryFieldName, newLine);
return newValues;
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class DirectionalFields method getCantMergeFieldNames.
public Set<String> getCantMergeFieldNames(final Point point, final Record record1, final Record record2, final Collection<String> equalExcludeFieldNames) {
final RecordDefinition recordDefinition = getRecordDefinition();
final boolean[] forwardsIndicators = getForwardsIndicators(point, record1, record2);
if (forwardsIndicators != null) {
final Set<String> fieldNames = new LinkedHashSet<>();
final EqualIgnoreFieldNames equalIgnore = EqualIgnoreFieldNames.getProperty(recordDefinition);
for (final String fieldName : recordDefinition.getFieldNames()) {
if (!equalExcludeFieldNames.contains(fieldName) && !equalIgnore.isFieldIgnored(fieldName)) {
if (!canMerge(fieldName, point, record1, record2, equalExcludeFieldNames, forwardsIndicators)) {
fieldNames.add(fieldName);
}
}
}
return fieldNames;
} else {
final String geometryFieldName = recordDefinition.getGeometryFieldName();
return Collections.singleton(geometryFieldName);
}
}
use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.
the class DirectionalFields method canMerge.
public boolean canMerge(final Point point, final Record record1, final Record record2, final Collection<String> equalExcludeFieldNames) {
final boolean[] forwardsIndicators = getForwardsIndicators(point, record1, record2);
if (forwardsIndicators != null) {
final RecordDefinition recordDefinition = getRecordDefinition();
final EqualIgnoreFieldNames equalIgnore = EqualIgnoreFieldNames.getProperty(recordDefinition);
for (final String fieldName : recordDefinition.getFieldNames()) {
if (!record1.isFieldExcluded(equalExcludeFieldNames, fieldName) && !equalIgnore.isFieldIgnored(fieldName)) {
if (!canMerge(fieldName, point, record1, record2, equalExcludeFieldNames, forwardsIndicators)) {
return false;
}
}
}
return true;
} else {
return false;
}
}
Aggregations