Search in sources :

Example 76 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class EsriGeodatabaseXmlRecordWriter method write.

@Override
public void write(final Record record) {
    if (!this.opened) {
        writeHeader(record.getGeometry());
        writeWorkspaceDataHeader();
    }
    this.out.startTag(RECORD);
    this.out.attribute(XsiConstants.TYPE, RECORD_TYPE);
    this.out.startTag(VALUES);
    this.out.attribute(XsiConstants.TYPE, VALUES_TYPE);
    for (final FieldDefinition field : this.recordDefinition.getFields()) {
        final String fieldName = field.getName();
        final Object value;
        if (isWriteCodeValues()) {
            value = record.getValue(fieldName);
        } else {
            value = record.getCodeValue(fieldName);
        }
        final DataType type = field.getDataType();
        final EsriGeodatabaseXmlFieldType fieldType = this.fieldTypes.getFieldType(type);
        if (fieldType != null) {
            fieldType.writeValue(this.out, value);
        }
    }
    if (this.recordDefinition.getField("OBJECTID") == null) {
        final EsriGeodatabaseXmlFieldType fieldType = this.fieldTypes.getFieldType(DataTypes.INT);
        fieldType.writeValue(this.out, this.objectId++);
    }
    this.out.endTag(VALUES);
    this.out.endTag(RECORD);
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) EsriGeodatabaseXmlFieldType(com.revolsys.record.io.format.esri.gdb.xml.type.EsriGeodatabaseXmlFieldType)

Example 77 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class EsriGeodatabaseXmlRecordWriter method writeField.

private void writeField(final FieldDefinition attribute) {
    final String fieldName = attribute.getName();
    if (fieldName.equals("OBJECTID")) {
        writeOidField();
    } else {
        final DataType dataType = attribute.getDataType();
        final EsriGeodatabaseXmlFieldType fieldType = this.fieldTypes.getFieldType(dataType);
        if (fieldType == null) {
            Logs.error(this, "Data type not supported " + dataType);
        } else {
            this.out.startTag(FIELD);
            this.out.attribute(XsiConstants.TYPE, FIELD_TYPE);
            this.out.element(NAME, fieldName);
            this.out.element(TYPE, fieldType.getEsriFieldType());
            this.out.element(IS_NULLABLE, !attribute.isRequired());
            int length = fieldType.getFixedLength();
            if (length < 0) {
                length = attribute.getLength();
            }
            this.out.element(LENGTH, length);
            final int precision;
            if (fieldType.isUsePrecision()) {
                precision = attribute.getLength();
            } else {
                precision = 0;
            }
            this.out.element(PRECISION, precision);
            this.out.element(SCALE, attribute.getScale());
            final GeometryFactory geometryFactory = attribute.getProperty(FieldProperties.GEOMETRY_FACTORY);
            if (geometryFactory != null) {
                this.out.startTag(GEOMETRY_DEF);
                this.out.attribute(XsiConstants.TYPE, GEOMETRY_DEF_TYPE);
                this.out.element(AVG_NUM_POINTS, 0);
                this.out.element(GEOMETRY_TYPE, this.geometryType);
                this.out.element(HAS_M, false);
                this.out.element(HAS_Z, geometryFactory.hasZ());
                writeSpatialReference(geometryFactory);
                this.out.endTag();
            }
            this.out.endTag(FIELD);
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) DataType(com.revolsys.datatype.DataType) EsriGeodatabaseXmlFieldType(com.revolsys.record.io.format.esri.gdb.xml.type.EsriGeodatabaseXmlFieldType) Point(com.revolsys.geometry.model.Point)

Example 78 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class AbstractRecordReader method newRecordDefinition.

protected RecordDefinition newRecordDefinition(final String baseName, final List<String> fieldNames) throws IOException {
    this.hasPointFields = Property.hasValue(this.pointXFieldName) && Property.hasValue(this.pointYFieldName);
    if (this.hasPointFields) {
        this.geometryType = DataTypes.POINT;
    } else {
        this.pointXFieldName = null;
        this.pointYFieldName = null;
    }
    final List<FieldDefinition> fields = new ArrayList<>();
    FieldDefinition geometryField = null;
    for (final String fieldName : fieldNames) {
        if (fieldName != null) {
            DataType type;
            int length = 0;
            boolean isGeometryField = false;
            if (fieldName.equalsIgnoreCase(this.geometryColumnName)) {
                type = this.geometryType;
                isGeometryField = true;
            } else if ("GEOMETRY".equalsIgnoreCase(fieldName)) {
                type = DataTypes.GEOMETRY;
                isGeometryField = true;
            } else if ("SHAPE".equalsIgnoreCase(fieldName)) {
                type = DataTypes.GEOMETRY;
                isGeometryField = true;
            } else if ("GEOMETRYCOLLECTION".equalsIgnoreCase(fieldName) || "GEOMETRY_COLLECTION".equalsIgnoreCase(fieldName)) {
                type = DataTypes.GEOMETRY_COLLECTION;
                isGeometryField = true;
            } else if ("POINT".equalsIgnoreCase(fieldName)) {
                type = DataTypes.POINT;
                isGeometryField = true;
            } else if ("MULTI_POINT".equalsIgnoreCase(fieldName) || "MULTIPOINT".equalsIgnoreCase(fieldName)) {
                type = DataTypes.MULTI_POINT;
                isGeometryField = true;
            } else if ("LINE_STRING".equalsIgnoreCase(fieldName) || "LINESTRING".equalsIgnoreCase(fieldName) || "LINE".equalsIgnoreCase(fieldName)) {
                type = DataTypes.LINE_STRING;
                isGeometryField = true;
            } else if ("MULTI_LINESTRING".equalsIgnoreCase(fieldName) || "MULTILINESTRING".equalsIgnoreCase(fieldName) || "MULTILINE".equalsIgnoreCase(fieldName) || "MULTI_LINE".equalsIgnoreCase(fieldName)) {
                type = DataTypes.MULTI_LINE_STRING;
                isGeometryField = true;
            } else if ("POLYGON".equalsIgnoreCase(fieldName)) {
                type = DataTypes.POLYGON;
                isGeometryField = true;
            } else if ("MULTI_POLYGON".equalsIgnoreCase(fieldName) || "MULTIPOLYGON".equalsIgnoreCase(fieldName)) {
                type = DataTypes.MULTI_POLYGON;
                isGeometryField = true;
            } else {
                type = DataTypes.STRING;
                length = 4000;
            }
            final FieldDefinition field;
            if (isGeometryField) {
                field = new GeometryFieldDefinition(this.geometryFactory, fieldName, type, false);
                geometryField = field;
            } else {
                field = new FieldDefinition(fieldName, type, length, false);
            }
            fields.add(field);
        }
    }
    if (this.hasPointFields) {
        if (geometryField == null) {
            geometryField = new FieldDefinition(this.geometryColumnName, this.geometryType, true);
            fields.add(geometryField);
        }
    }
    if (geometryField != null) {
        geometryField.setProperty(FieldProperties.GEOMETRY_FACTORY, this.geometryFactory);
    }
    final RecordStoreSchema schema = getProperty("schema");
    String typePath = getProperty("typePath");
    if (!Property.hasValue(typePath)) {
        typePath = "/" + baseName;
        String schemaPath = getProperty("schemaPath");
        if (Property.hasValue(schemaPath)) {
            if (!schemaPath.startsWith("/")) {
                schemaPath = "/" + schemaPath;
            }
            typePath = schemaPath + typePath;
        }
    }
    final PathName pathName = PathName.newPathName(typePath);
    this.recordDefinition = new RecordDefinitionImpl(schema, pathName, getProperties(), fields);
    return this.recordDefinition;
}
Also used : RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) FieldDefinition(com.revolsys.record.schema.FieldDefinition) GeometryFieldDefinition(com.revolsys.record.io.format.csv.GeometryFieldDefinition) ArrayList(java.util.ArrayList) GeometryFieldDefinition(com.revolsys.record.io.format.csv.GeometryFieldDefinition) DataType(com.revolsys.datatype.DataType) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) PathName(com.revolsys.io.PathName)

Example 79 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class AbstractRecordReader method initDo.

@Override
protected void initDo() {
    this.pointXFieldName = getProperty("pointXFieldName");
    this.pointYFieldName = getProperty("pointYFieldName");
    this.geometryColumnName = getProperty("geometryColumnName", "GEOMETRY");
    this.geometryFactory = GeometryFactory.get(getProperty("geometryFactory"));
    if (this.geometryFactory == null || this.geometryFactory == GeometryFactory.DEFAULT_3D) {
        final Integer geometrySrid = Property.getInteger(this, "geometrySrid");
        if (geometrySrid == null) {
            this.geometryFactory = loadGeometryFactory();
        } else {
            this.geometryFactory = GeometryFactory.floating3d(geometrySrid);
        }
    }
    if (this.geometryFactory == null) {
        this.geometryFactory = GeometryFactory.DEFAULT_3D;
    }
    final DataType geometryType = DataTypes.getDataType((String) getProperty("geometryType"));
    if (Geometry.class.isAssignableFrom(geometryType.getJavaClass())) {
        this.geometryType = geometryType;
    }
}
Also used : DataType(com.revolsys.datatype.DataType)

Example 80 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class EsriGeodatabaseXmlFieldTypeRegistry method addFieldType.

public void addFieldType(final EsriGeodatabaseXmlFieldType fieldType) {
    final DataType dataType = fieldType.getDataType();
    addFieldType(dataType, fieldType);
}
Also used : DataType(com.revolsys.datatype.DataType)

Aggregations

DataType (com.revolsys.datatype.DataType)85 FieldDefinition (com.revolsys.record.schema.FieldDefinition)32 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)23 PathName (com.revolsys.io.PathName)13 RecordDefinition (com.revolsys.record.schema.RecordDefinition)11 Geometry (com.revolsys.geometry.model.Geometry)10 Record (com.revolsys.record.Record)10 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)10 ArrayList (java.util.ArrayList)8 ArrayRecord (com.revolsys.record.ArrayRecord)6 PrintWriter (java.io.PrintWriter)6 EsriGeodatabaseXmlFieldType (com.revolsys.record.io.format.esri.gdb.xml.type.EsriGeodatabaseXmlFieldType)5 MapEx (com.revolsys.collection.map.MapEx)4 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 Point (com.revolsys.geometry.model.Point)4 IOException (java.io.IOException)4 Map (java.util.Map)4 CollectionDataType (com.revolsys.datatype.CollectionDataType)3 EnumerationDataType (com.revolsys.datatype.EnumerationDataType)3 CodeTable (com.revolsys.record.code.CodeTable)3