Search in sources :

Example 51 with DataType

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

the class RecordRowTableModel method getPrototypeValue.

@Override
public Object getPrototypeValue(final int columnIndex) {
    FieldDefinition fieldDefinition = getColumnFieldDefinition(columnIndex);
    if (fieldDefinition == null) {
        return null;
    } else {
        final CodeTable codeTable = fieldDefinition.getCodeTable();
        if (codeTable != null) {
            final FieldDefinition valueFieldDefinition = codeTable.getValueFieldDefinition();
            if (valueFieldDefinition != null) {
                fieldDefinition = valueFieldDefinition;
            } else {
                Object maxValue = "";
                int maxLength = 0;
                for (final Object value : codeTable.getValues()) {
                    if (value != null) {
                        final int length = DataTypes.toString(value).length();
                        if (length > maxLength) {
                            maxValue = value;
                            maxLength = length;
                        }
                    }
                }
                return maxValue;
            }
        }
        final DataType fieldType = fieldDefinition.getDataType();
        final Class<?> fieldClass = fieldDefinition.getTypeClass();
        final int fieldLength = fieldDefinition.getLength();
        if (DataTypes.BOOLEAN.equals(fieldType)) {
            return Byte.MIN_VALUE;
        } else if (DataTypes.BYTE.equals(fieldType)) {
            return Byte.MIN_VALUE;
        } else if (DataTypes.SHORT.equals(fieldType)) {
            return Short.MAX_VALUE;
        } else if (DataTypes.INT.equals(fieldType)) {
            return Integer.MAX_VALUE;
        } else if (DataTypes.LONG.equals(fieldType)) {
            return Long.MAX_VALUE;
        } else if (DataTypes.SQL_DATE.equals(fieldType)) {
            return Dates.getSqlDate("9999-12-31");
        } else if (DataTypes.DATE.equals(fieldType)) {
            return Dates.getDate("9999-12-29 23:59:59.999");
        } else if (DataTypes.DATE_TIME.equals(fieldType)) {
            return Dates.getTimestamp("9999-12-29 23:59:59.999");
        } else if (DataTypes.TIMESTAMP.equals(fieldType)) {
            return Dates.getTimestamp("9999-12-29 23:59:59.999");
        } else if (Geometry.class.isAssignableFrom(fieldClass)) {
            return fieldType.getName();
        } else {
            if (fieldLength < 1 || fieldLength > 30) {
                return "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
            } else {
                final StringBuilder string = new StringBuilder();
                for (int i = 0; i < fieldLength; i++) {
                    string.append("X");
                }
                return string.toString();
            }
        }
    // if (Number.class.isAssignableFrom(fieldClass)) {
    // final StringBuilder numberString = new StringBuilder();
    // final Object maxValue = fieldDefinition.getMaxValue();
    // final Object minValue = fieldDefinition.getMinValue();
    // if (maxValue == null) {
    // for (int i = 0; i <= maxLength; i++) {
    // numberString.append("9");
    // }
    // return fieldType.toObject(numberString.toString());
    // } else {
    // if (minValue instanceof Number) {
    // numberString.append(((Number)minValue).longValue());
    // }
    // }
    // if (Float.class.isAssignableFrom(fieldClass) ||
    // Double.class.isAssignableFrom(fieldClass)
    // || BigDecimal.class.isAssignableFrom(fieldClass)) {
    // numberString.append('.');
    // final int fieldScale = fieldDefinition.getScale();
    // for (int i = 0; i <= fieldScale; i++) {
    // numberString.append("9");
    // }
    // final BigDecimal scaleValue = new BigDecimal(numberString.toString());
    // }
    // }
    // return super.getPrototypeValue(columnIndex);
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) Geometry(com.revolsys.geometry.model.Geometry) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType)

Example 52 with DataType

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

the class GeometryFactory method geometryCollection.

/**
 * Does not flattern nested geometry collections.
 *
 * @param geometries
 * @return
 */
@SuppressWarnings("unchecked")
public <G extends Geometry> G geometryCollection(final Iterable<? extends Geometry> geometries) {
    if (geometries == null) {
        return (G) geometryCollection();
    } else {
        DataType dataType = null;
        boolean heterogeneous = false;
        final List<Geometry> geometryList = new ArrayList<>();
        if (geometries != null) {
            for (final Geometry geometry : geometries) {
                if (geometry != null) {
                    if (heterogeneous) {
                    } else {
                        final DataType geometryDataType = geometry.getDataType();
                        if (dataType == null) {
                            dataType = geometryDataType;
                        } else if (dataType != geometryDataType) {
                            heterogeneous = true;
                            dataType = null;
                        }
                    }
                    final Geometry copy = geometry.newGeometry(this);
                    geometryList.add(copy);
                }
            }
        }
        if (geometryList.size() == 0) {
            return (G) geometryCollection();
        } else if (geometryList.size() == 1) {
            return (G) geometryList.get(0);
        } else if (dataType == DataTypes.POINT) {
            return (G) punctual(geometryList);
        } else if (dataType == DataTypes.LINE_STRING) {
            return (G) lineal(geometryList);
        } else if (dataType == DataTypes.POLYGON) {
            return (G) polygonal(geometryList);
        } else {
            final Geometry[] geometryArray = new Geometry[geometryList.size()];
            geometryList.toArray(geometryArray);
            return (G) new GeometryCollectionImpl(this, geometryArray);
        }
    }
}
Also used : GeometryCollectionImpl(com.revolsys.geometry.model.impl.GeometryCollectionImpl) ArrayList(java.util.ArrayList) DataType(com.revolsys.datatype.DataType)

Example 53 with DataType

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

the class MeasureOverlay method setMeasureDataType.

public void setMeasureDataType(final DataType measureDataType) {
    final DataType oldValue = this.measureDataType;
    if (oldValue != measureDataType) {
        this.measureDataType = measureDataType;
        setMeasureGeometry(EMPTY_GEOMETRY);
        this.dragged = false;
        this.measureDataType = measureDataType;
        firePropertyChange("measureDataType", oldValue, measureDataType);
    }
}
Also used : DataType(com.revolsys.datatype.DataType)

Example 54 with DataType

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

the class MeasureOverlay method modeMeasureClear.

private void modeMeasureClear() {
    clearOverlayAction(MEASURE);
    setMeasureGeometry(EMPTY_GEOMETRY);
    this.dragged = false;
    final DataType oldValue = this.measureDataType;
    this.measureDataType = null;
    firePropertyChange("measureDataType", oldValue, null);
}
Also used : DataType(com.revolsys.datatype.DataType)

Example 55 with DataType

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

the class FileGdbRecordStore method newIterator.

@Override
public AbstractIterator<Record> newIterator(final Query query, final Map<String, Object> properties) {
    PathName typePath = query.getTypePath();
    RecordDefinition recordDefinition = query.getRecordDefinition();
    if (recordDefinition == null) {
        recordDefinition = getRecordDefinition(typePath);
        if (recordDefinition == null) {
            throw new IllegalArgumentException("Type name does not exist " + typePath);
        }
    } else {
        typePath = recordDefinition.getPathName();
    }
    final String catalogPath = getCatalogPath(typePath);
    final BoundingBox boundingBox = QueryValue.getBoundingBox(query);
    final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
    final StringBuilder whereClause = getWhereClause(query);
    StringBuilder sql = new StringBuilder();
    if (orderBy.isEmpty() || boundingBox != null) {
        if (!orderBy.isEmpty()) {
            Logs.error(this, "Unable to sort on " + catalogPath + " " + orderBy.keySet() + " as the ESRI library can't sort with a bounding box query");
        }
        sql = whereClause;
    } else {
        sql.append("SELECT ");
        final List<String> fieldNames = query.getFieldNames();
        if (fieldNames.isEmpty()) {
            StringBuilders.append(sql, recordDefinition.getFieldNames());
        } else {
            StringBuilders.append(sql, fieldNames);
        }
        sql.append(" FROM ");
        sql.append(JdbcUtils.getTableName(catalogPath));
        if (whereClause.length() > 0) {
            sql.append(" WHERE ");
            sql.append(whereClause);
        }
        boolean first = true;
        for (final Entry<? extends CharSequence, Boolean> entry : orderBy.entrySet()) {
            final CharSequence fieldName = entry.getKey();
            final DataType dataType = recordDefinition.getFieldType(fieldName);
            if (dataType != null && !Geometry.class.isAssignableFrom(dataType.getJavaClass())) {
                if (first) {
                    sql.append(" ORDER BY ");
                    first = false;
                } else {
                    sql.append(", ");
                }
                if (fieldName instanceof FieldDefinition) {
                    final FieldDefinition field = (FieldDefinition) fieldName;
                    field.appendColumnName(sql);
                } else {
                    sql.append(fieldName);
                }
                final Boolean ascending = entry.getValue();
                if (!ascending) {
                    sql.append(" DESC");
                }
            } else {
                Logs.error(this, "Unable to sort on " + recordDefinition.getPath() + "." + fieldName + " as the ESRI library can't sort on " + dataType + " columns");
            }
        }
    }
    final FileGdbQueryIterator iterator = new FileGdbQueryIterator(this, catalogPath, sql.toString(), boundingBox, query, query.getOffset(), query.getLimit());
    iterator.setStatistics(query.getStatistics());
    return iterator;
}
Also used : OidFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.OidFieldDefinition) DoubleFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.DoubleFieldDefinition) FloatFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.FloatFieldDefinition) AreaFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AreaFieldDefinition) StringFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.StringFieldDefinition) AbstractFileGdbFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition) FieldDefinition(com.revolsys.record.schema.FieldDefinition) GlobalIdFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GlobalIdFieldDefinition) IntegerFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.IntegerFieldDefinition) GuidFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GuidFieldDefinition) XmlFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.XmlFieldDefinition) ShortFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.ShortFieldDefinition) LengthFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.LengthFieldDefinition) BinaryFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.BinaryFieldDefinition) DateFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.DateFieldDefinition) GeometryFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GeometryFieldDefinition) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) RecordDefinition(com.revolsys.record.schema.RecordDefinition) BoundingBox(com.revolsys.geometry.model.BoundingBox) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

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