Search in sources :

Example 46 with RecordDefinition

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);
}
Also used : GmlFieldType(com.revolsys.record.io.format.gml.type.GmlFieldType) QName(javax.xml.namespace.QName) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 47 with RecordDefinition

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);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Point(com.revolsys.geometry.model.Point) RecordDefinition(com.revolsys.record.schema.RecordDefinition) Geometry(com.revolsys.geometry.model.Geometry)

Example 48 with RecordDefinition

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;
}
Also used : Vertex(com.revolsys.geometry.model.vertex.Vertex) LineString(com.revolsys.geometry.model.LineString) Record(com.revolsys.record.Record) LineString(com.revolsys.geometry.model.LineString) LinkedHashMap(java.util.LinkedHashMap) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 49 with RecordDefinition

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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LineString(com.revolsys.geometry.model.LineString) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 50 with RecordDefinition

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;
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

RecordDefinition (com.revolsys.record.schema.RecordDefinition)189 FieldDefinition (com.revolsys.record.schema.FieldDefinition)38 Record (com.revolsys.record.Record)34 Geometry (com.revolsys.geometry.model.Geometry)20 CodeTable (com.revolsys.record.code.CodeTable)19 Query (com.revolsys.record.query.Query)18 LineString (com.revolsys.geometry.model.LineString)17 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)16 PathName (com.revolsys.io.PathName)13 ArrayList (java.util.ArrayList)12 DataType (com.revolsys.datatype.DataType)11 Identifier (com.revolsys.identifier.Identifier)11 RecordReader (com.revolsys.record.io.RecordReader)11 RecordStore (com.revolsys.record.schema.RecordStore)11 HashMap (java.util.HashMap)9 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)8 ArrayRecord (com.revolsys.record.ArrayRecord)8 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)6 Table (com.revolsys.gis.esri.gdb.file.capi.swig.Table)5 RecordWriter (com.revolsys.record.io.RecordWriter)5