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);
}
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);
}
}
}
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;
}
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;
}
}
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);
}
Aggregations