Search in sources :

Example 1 with GeometryFieldDefinition

use of com.revolsys.record.io.format.csv.GeometryFieldDefinition 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)

Aggregations

DataType (com.revolsys.datatype.DataType)1 PathName (com.revolsys.io.PathName)1 GeometryFieldDefinition (com.revolsys.record.io.format.csv.GeometryFieldDefinition)1 FieldDefinition (com.revolsys.record.schema.FieldDefinition)1 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)1 RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)1 ArrayList (java.util.ArrayList)1