Search in sources :

Example 26 with DataType

use of com.revolsys.datatype.DataType 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 27 with DataType

use of com.revolsys.datatype.DataType 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 28 with DataType

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

the class FeatureSource method newLayer.

private FeatureLayer newLayer(final String name, final MapEx element, final MapEx complexType) {
    if (!"true".equals(getString(complexType, "@abstract"))) {
        final PathName pathName = getPathName();
        final PathName layerPathName = pathName.newChild(name);
        final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(layerPathName);
        GeometryFactory geometryFactory = GeometryFactory.DEFAULT_3D;
        final MapEx complexContent = getValue(complexType, "xs:complexContent");
        final MapEx extension = getValue(complexContent, "xs:extension");
        if ("gml:AbstractFeatureType".equals(getString(extension, "@base"))) {
            final MapEx sequence = getValue(extension, "xs:sequence");
            final List<MapEx> elements = sequence.getValue("xs:element");
            for (final MapEx fieldElement : elements) {
                final String fieldName = getString(fieldElement, "@name");
                final boolean required = !"0".equals(getString(fieldElement, "@minOccurs"));
                DataType dataType = DataTypes.STRING;
                final MapEx simpleFieldType = getValue(fieldElement, "xs:simpleType");
                if (simpleFieldType == null) {
                    final String fieldType = getString(fieldElement, "@type");
                    if ("gml:AbstractGeometryType".equals(fieldType)) {
                        final String geometryTypes = getString(fieldElement, "@fdo:geometryTypes");
                        for (final String geometryType : geometryTypes.split(" ")) {
                            final DataType geometryDataType = DataTypes.getDataType(geometryType);
                            if (geometryDataType != DataTypes.OBJECT) {
                                if (dataType == DataTypes.STRING) {
                                    dataType = geometryDataType;
                                } else if (dataType == DataTypes.GEOMETRY) {
                                } else if (geometryDataType == DataTypes.GEOMETRY) {
                                    dataType = DataTypes.GEOMETRY;
                                } else if (geometryDataType == DataTypes.GEOMETRY_COLLECTION) {
                                    dataType = DataTypes.GEOMETRY;
                                } else if (dataType.equals(DataTypes.POINT)) {
                                    if (geometryDataType.equals(DataTypes.POINT)) {
                                    } else if (geometryDataType.equals(DataTypes.MULTI_POINT)) {
                                        dataType = DataTypes.MULTI_POINT;
                                    } else {
                                        dataType = DataTypes.GEOMETRY;
                                    }
                                } else if (dataType.equals(DataTypes.MULTI_POINT)) {
                                    if (geometryDataType.equals(DataTypes.POINT)) {
                                    } else if (geometryDataType.equals(DataTypes.MULTI_POINT)) {
                                    } else {
                                        dataType = DataTypes.GEOMETRY;
                                    }
                                } else if (dataType.equals(DataTypes.LINE_STRING)) {
                                    if (geometryDataType.equals(DataTypes.LINE_STRING)) {
                                    } else if (geometryDataType.equals(DataTypes.MULTI_LINE_STRING)) {
                                        dataType = DataTypes.MULTI_LINE_STRING;
                                    } else {
                                        dataType = DataTypes.GEOMETRY;
                                    }
                                } else if (dataType.equals(DataTypes.MULTI_LINE_STRING)) {
                                    if (geometryDataType.equals(DataTypes.LINE_STRING)) {
                                    } else if (geometryDataType.equals(DataTypes.MULTI_LINE_STRING)) {
                                    } else {
                                        dataType = DataTypes.GEOMETRY;
                                    }
                                } else if (dataType.equals(DataTypes.POLYGON)) {
                                    if (geometryDataType.equals(DataTypes.POLYGON)) {
                                    } else if (geometryDataType.equals(DataTypes.MULTI_POLYGON)) {
                                        dataType = DataTypes.MULTI_POLYGON;
                                    } else {
                                        dataType = DataTypes.GEOMETRY;
                                    }
                                } else if (dataType.equals(DataTypes.MULTI_POLYGON)) {
                                    if (geometryDataType.equals(DataTypes.POLYGON)) {
                                    } else if (geometryDataType.equals(DataTypes.MULTI_POLYGON)) {
                                    } else {
                                        dataType = DataTypes.GEOMETRY;
                                    }
                                }
                            }
                        }
                        if (dataType == DataTypes.STRING) {
                            dataType = DataTypes.GEOMETRY;
                        }
                        int axisCount = 2;
                        if ("true".equals(getString(fieldElement, "@fdo:hasMeasure"))) {
                            axisCount = 4;
                        } else if ("true".equals(getString(fieldElement, "@fdo:hasElevation"))) {
                            axisCount = 3;
                        }
                        final String srsName = getString(fieldElement, "@fdo:srsName");
                        if (Property.hasValue(srsName)) {
                            final Integer coordinateSystemId = Maps.getInteger(this.coordinateSystemIdBySrsName, srsName);
                            if (coordinateSystemId == null) {
                                try {
                                    final Map<String, Object> csParameters = Collections.singletonMap("CSCODE", srsName);
                                    final MapGuideWebService webService = getWebService();
                                    final Resource wktResource = webService.getResource("CS.CONVERTCOORDINATESYSTEMCODETOWKT", null, csParameters);
                                    final String wkt = wktResource.contentsAsString();
                                    geometryFactory = GeometryFactory.floating(wkt, axisCount);
                                } catch (final Throwable e) {
                                }
                            } else {
                                geometryFactory = GeometryFactory.floating(coordinateSystemId, axisCount);
                            }
                        }
                    }
                } else {
                    final MapEx restriction = getValue(simpleFieldType, "xs:restriction");
                    if (restriction != null) {
                        final String fieldBase = getString(restriction, "@base");
                        dataType = DataTypes.getDataType(fieldBase.replace("xs:", ""));
                    }
                }
                if (dataType != null) {
                    recordDefinition.addField(fieldName, dataType, required);
                }
            }
            recordDefinition.setGeometryFactory(geometryFactory);
            final FeatureLayer layer = new FeatureLayer(this, recordDefinition);
            return layer;
        }
    }
    return null;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LinkedHashMapEx(com.revolsys.collection.map.LinkedHashMapEx) MapEx(com.revolsys.collection.map.MapEx) WebServiceResource(com.revolsys.webservice.WebServiceResource) Resource(com.revolsys.spring.resource.Resource) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

Example 29 with DataType

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

the class XbaseIterator method loadRecord.

protected Record loadRecord() throws IOException {
    if (this.in.read(this.recordBuffer) != this.recordBuffer.length) {
        throw new IllegalStateException("Unexpected end of mappedFile");
    }
    final Record object = this.recordFactory.newRecord(this.recordDefinition);
    int startIndex = 0;
    for (int i = 0; i < this.recordDefinition.getFieldCount(); i++) {
        int len = this.recordDefinition.getFieldLength(i);
        final DataType type = this.recordDefinition.getFieldType(i);
        Object value = null;
        if (type == DataTypes.STRING) {
            if (len < 255) {
                value = getString(startIndex, len);
            } else {
                value = getMemo(startIndex, len);
                len = 10;
            }
        } else if (type == DataTypes.DECIMAL || type == DataTypes.FLOAT) {
            value = getNumber(startIndex, len);
        } else if (type == DataTypes.BOOLEAN) {
            value = getBoolean(startIndex);
        } else if (type == DataTypes.DATE_TIME) {
            value = getDate(startIndex, len);
        }
        startIndex += len;
        object.setValue(i, value);
    }
    return object;
}
Also used : DataType(com.revolsys.datatype.DataType) Record(com.revolsys.record.Record)

Example 30 with DataType

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

the class XbaseIterator method readRecordDefinition.

private void readRecordDefinition() throws IOException {
    this.recordDefinition = new RecordDefinitionImpl(this.typeName);
    int b = this.in.read();
    while (b != 0x0D) {
        final StringBuilder fieldName = new StringBuilder();
        boolean endOfName = false;
        for (int i = 0; i < 11; i++) {
            if (!endOfName && b != 0) {
                fieldName.append((char) b);
            } else {
                endOfName = true;
            }
            if (i != 10) {
                b = this.in.read();
            }
        }
        final char fieldType = (char) this.in.read();
        this.in.skipBytes(4);
        int length = this.in.read();
        final int decimalCount = this.in.read();
        this.in.skipBytes(14);
        b = this.in.read();
        final DataType dataType = DATA_TYPES.get(fieldType);
        if (fieldType == MEMO_TYPE) {
            length = Integer.MAX_VALUE;
        }
        this.recordDefinition.addField(fieldName.toString(), dataType, length, decimalCount, false);
    }
    if (this.mappedFile) {
        final EndianMappedByteBuffer file = (EndianMappedByteBuffer) this.in;
        this.firstIndex = file.getFilePointer();
    }
}
Also used : EndianMappedByteBuffer(com.revolsys.io.endian.EndianMappedByteBuffer) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) 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