Search in sources :

Example 1 with FieldType

use of com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType in project com.revolsys.open by revolsys.

the class EsriXmlRecordDefinitionUtil method addField.

private static void addField(final RecordDefinitionImpl recordDefinition, final DETable deTable, final String tableName, final Field field, final String fieldName) {
    final FieldType fieldType = field.getType();
    final int precision = field.getPrecision();
    final DataType dataType;
    if (fieldType == FieldType.esriFieldTypeGeometry && deTable instanceof DEFeatureClass) {
        final DEFeatureClass featureClass = (DEFeatureClass) deTable;
        final GeometryType shapeType = featureClass.getShapeType();
        switch(shapeType) {
            case esriGeometryPoint:
                dataType = DataTypes.POINT;
                break;
            case esriGeometryMultipoint:
                dataType = DataTypes.MULTI_POINT;
                break;
            case esriGeometryPolyline:
                dataType = DataTypes.MULTI_LINE_STRING;
                break;
            case esriGeometryPolygon:
                dataType = DataTypes.POLYGON;
                break;
            default:
                throw new RuntimeException("Unknown geometry type" + shapeType + " for " + tableName + "." + fieldName);
        }
    } else if (precision > 0 && (fieldType.equals(FieldType.esriFieldTypeSingle) || fieldType.equals(FieldType.esriFieldTypeDouble))) {
        dataType = DataTypes.DECIMAL;
    } else {
        dataType = EsriGeodatabaseXmlFieldTypeRegistry.INSTANCE.getDataType(fieldType);
    }
    final int scale = field.getScale();
    int length = field.getLength();
    if (precision != 0) {
        length = precision;
    }
    final Boolean required = !field.isIsNullable() || Booleans.getBoolean(field.getRequired());
    final FieldDefinition attribute = new FieldDefinition(fieldName, dataType, length, scale, required);
    recordDefinition.addField(attribute);
    if (fieldName.equals(tableName + "_ID")) {
        recordDefinition.setIdFieldName(fieldName);
    }
}
Also used : GeometryType(com.revolsys.record.io.format.esri.gdb.xml.model.enums.GeometryType) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) FieldType(com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType) EsriGeodatabaseXmlFieldType(com.revolsys.record.io.format.esri.gdb.xml.type.EsriGeodatabaseXmlFieldType)

Example 2 with FieldType

use of com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType in project com.revolsys.open by revolsys.

the class EsriXmlRecordDefinitionUtil method getRecordDefinition.

public static RecordDefinition getRecordDefinition(final String schemaName, final Domain domain, final boolean appendIdToName) {
    final String tableName;
    if (appendIdToName) {
        tableName = domain.getName() + "_ID";
    } else {
        tableName = domain.getName();
    }
    final PathName typePath = PathName.newPathName(PathUtil.toPath(schemaName, tableName));
    final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(typePath);
    final FieldType fieldType = domain.getFieldType();
    final DataType dataType = EsriGeodatabaseXmlFieldTypeRegistry.INSTANCE.getDataType(fieldType);
    int length = 0;
    for (final CodedValue codedValue : domain.getCodedValues()) {
        length = Math.max(length, codedValue.getCode().toString().length());
    }
    recordDefinition.addField(tableName, dataType, length, true);
    recordDefinition.addField("DESCRIPTION", DataTypes.STRING, 255, true);
    recordDefinition.setIdFieldIndex(0);
    return recordDefinition;
}
Also used : RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName) FieldType(com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType) EsriGeodatabaseXmlFieldType(com.revolsys.record.io.format.esri.gdb.xml.type.EsriGeodatabaseXmlFieldType)

Example 3 with FieldType

use of com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType in project com.revolsys.open by revolsys.

the class FeatureLayer method addField.

private void addField(final RecordDefinitionImpl recordDefinition, final String geometryType, final MapEx field) {
    final String fieldName = field.getString("name");
    final String fieldTitle = field.getString("string");
    final String fieldType = field.getString("type");
    final FieldType esriFieldType = FieldType.valueOf(fieldType);
    final DataType dataType;
    if (esriFieldType == FieldType.esriFieldTypeGeometry) {
        final DataType geometryDataType = getGeometryDataType(geometryType);
        if (geometryDataType == null) {
            throw new IllegalArgumentException("No geometryType specified for " + getServiceUrl());
        }
        dataType = geometryDataType;
    } else {
        dataType = esriFieldType.getDataType();
    }
    if (dataType == null) {
        throw new IllegalArgumentException("Unsupported field=" + fieldName + " type=" + dataType + " for " + getServiceUrl());
    }
    final int length = field.getInteger("length", 0);
    final FieldDefinition fieldDefinition = recordDefinition.addField(fieldName, dataType, length, false);
    fieldDefinition.setTitle(fieldTitle);
    setCodeTable(fieldDefinition, field);
    if (esriFieldType == FieldType.esriFieldTypeOID) {
        recordDefinition.setIdFieldName(fieldName);
        fieldDefinition.setRequired(true);
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) FieldType(com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType)

Example 4 with FieldType

use of com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method getRecordDefinition.

public RecordDefinitionImpl getRecordDefinition(final PathName schemaName, final String path, final String tableDefinition) {
    synchronized (this.apiSync) {
        synchronized (API_SYNC) {
            try {
                final XmlProcessor parser = new EsriGdbXmlParser();
                final DETable deTable = parser.process(tableDefinition);
                final String tableName = deTable.getName();
                final PathName typePath = PathName.newPathName(schemaName.newChild(tableName));
                final RecordStoreSchema schema = getSchema(schemaName);
                final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(schema, typePath);
                recordDefinition.setPolygonRingDirection(ClockDirection.CLOCKWISE);
                String lengthFieldName = null;
                String areaFieldName = null;
                if (deTable instanceof DEFeatureClass) {
                    final DEFeatureClass featureClass = (DEFeatureClass) deTable;
                    lengthFieldName = featureClass.getLengthFieldName();
                    final LengthFieldName lengthFieldNameProperty = new LengthFieldName(lengthFieldName);
                    lengthFieldNameProperty.setRecordDefinition(recordDefinition);
                    areaFieldName = featureClass.getAreaFieldName();
                    final LengthFieldName areaFieldNameProperty = new LengthFieldName(areaFieldName);
                    areaFieldNameProperty.setRecordDefinition(recordDefinition);
                }
                for (final Field field : deTable.getFields()) {
                    final String fieldName = field.getName();
                    AbstractFileGdbFieldDefinition fieldDefinition = null;
                    if (fieldName.equals(lengthFieldName)) {
                        fieldDefinition = new LengthFieldDefinition(field);
                    } else if (fieldName.equals(areaFieldName)) {
                        fieldDefinition = new AreaFieldDefinition(field);
                    } else {
                        final FieldType type = field.getType();
                        final Constructor<? extends AbstractFileGdbFieldDefinition> fieldConstructor = ESRI_FIELD_TYPE_FIELD_DEFINITION_MAP.get(type);
                        if (fieldConstructor != null) {
                            try {
                                fieldDefinition = JavaBeanUtil.invokeConstructor(fieldConstructor, field);
                            } catch (final Throwable e) {
                                Logs.error(this, tableDefinition);
                                throw new RuntimeException("Error creating field for " + typePath + "." + field.getName() + " : " + field.getType(), e);
                            }
                        } else {
                            Logs.error(this, "Unsupported field type " + fieldName + ":" + type);
                        }
                    }
                    if (fieldDefinition != null) {
                        final Domain domain = field.getDomain();
                        if (domain != null) {
                            CodeTable codeTable = getCodeTable(domain.getDomainName() + "_ID");
                            if (codeTable == null) {
                                codeTable = new FileGdbDomainCodeTable(this, domain);
                                addCodeTable(codeTable);
                            }
                            fieldDefinition.setCodeTable(codeTable);
                        }
                        fieldDefinition.setRecordStore(this);
                        recordDefinition.addField(fieldDefinition);
                        if (fieldDefinition instanceof GlobalIdFieldDefinition) {
                            recordDefinition.setIdFieldName(fieldName);
                        }
                    }
                }
                final String oidFieldName = deTable.getOIDFieldName();
                recordDefinition.setProperty(EsriGeodatabaseXmlConstants.ESRI_OBJECT_ID_FIELD_NAME, oidFieldName);
                if (deTable instanceof DEFeatureClass) {
                    final DEFeatureClass featureClass = (DEFeatureClass) deTable;
                    final String shapeFieldName = featureClass.getShapeFieldName();
                    recordDefinition.setGeometryFieldName(shapeFieldName);
                }
                for (final Index index : deTable.getIndexes()) {
                    if (index.getName().endsWith("_PK")) {
                        for (final Field field : index.getFields()) {
                            final String fieldName = field.getName();
                            recordDefinition.setIdFieldName(fieldName);
                        }
                    }
                }
                addRecordDefinitionProperties(recordDefinition);
                if (recordDefinition.getIdFieldIndex() == -1) {
                    recordDefinition.setIdFieldName(deTable.getOIDFieldName());
                }
                this.catalogPathByPath.put(typePath, deTable.getCatalogPath());
                return recordDefinition;
            } catch (final RuntimeException e) {
                Logs.debug(this, tableDefinition);
                throw e;
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) EsriGdbXmlParser(com.revolsys.record.io.format.esri.gdb.xml.model.EsriGdbXmlParser) XmlProcessor(com.revolsys.record.io.format.xml.XmlProcessor) LengthFieldName(com.revolsys.record.property.LengthFieldName) Constructor(java.lang.reflect.Constructor) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) DEFeatureClass(com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) Index(com.revolsys.record.io.format.esri.gdb.xml.model.Index) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) GlobalIdFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GlobalIdFieldDefinition) AreaFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AreaFieldDefinition) FieldType(com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType) Field(com.revolsys.record.io.format.esri.gdb.xml.model.Field) AbstractFileGdbFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition) LengthFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.LengthFieldDefinition) PathName(com.revolsys.io.PathName) Domain(com.revolsys.record.io.format.esri.gdb.xml.model.Domain) DETable(com.revolsys.record.io.format.esri.gdb.xml.model.DETable)

Aggregations

FieldType (com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType)4 DataType (com.revolsys.datatype.DataType)3 PathName (com.revolsys.io.PathName)2 EsriGeodatabaseXmlFieldType (com.revolsys.record.io.format.esri.gdb.xml.type.EsriGeodatabaseXmlFieldType)2 FieldDefinition (com.revolsys.record.schema.FieldDefinition)2 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)2 FileGdbDomainCodeTable (com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable)1 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)1 AbstractFileGdbFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition)1 AreaFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.AreaFieldDefinition)1 GlobalIdFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.GlobalIdFieldDefinition)1 LengthFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.LengthFieldDefinition)1 CodeTable (com.revolsys.record.code.CodeTable)1 DEFeatureClass (com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass)1 DETable (com.revolsys.record.io.format.esri.gdb.xml.model.DETable)1 Domain (com.revolsys.record.io.format.esri.gdb.xml.model.Domain)1 EsriGdbXmlParser (com.revolsys.record.io.format.esri.gdb.xml.model.EsriGdbXmlParser)1 Field (com.revolsys.record.io.format.esri.gdb.xml.model.Field)1 Index (com.revolsys.record.io.format.esri.gdb.xml.model.Index)1 GeometryType (com.revolsys.record.io.format.esri.gdb.xml.model.enums.GeometryType)1