use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class OgrRecordStore method newLayerRecordDefinition.
private RecordDefinition newLayerRecordDefinition(final DataSource dataSource, final RecordDefinition sourceRecordDefinition) {
final PathName typePath = sourceRecordDefinition.getPathName();
final String name = typePath.getName();
final PathName parentPath = typePath.getParent();
final RecordStoreSchema schema = getSchema(parentPath);
Layer layer;
if (sourceRecordDefinition.hasGeometryField()) {
final GeometryFactory geometryFactory = sourceRecordDefinition.getGeometryFactory();
final FieldDefinition geometryField = sourceRecordDefinition.getGeometryField();
final int geometryFieldType = getGeometryFieldType(geometryFactory, geometryField);
final SpatialReference spatialReference = Gdal.getSpatialReference(geometryFactory);
layer = dataSource.CreateLayer(typePath.getPath(), spatialReference, geometryFieldType);
} else {
layer = dataSource.CreateLayer(name);
}
if (dataSource.TestCapability(ogrConstants.ODsCCreateLayer) == false) {
System.err.println("CreateLayer not supported by driver.");
}
return newLayerRecordDefinition(schema, layer);
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class OgrRecordWriter method setGeometries.
private void setGeometries(final FeatureDefn featureDefinition, final Record record, final Feature feature) {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final int geometryFieldCount = featureDefinition.GetGeomFieldCount();
for (int fieldIndex = 0; fieldIndex < geometryFieldCount; fieldIndex++) {
final GeomFieldDefn fieldDefinition = featureDefinition.GetGeomFieldDefn(fieldIndex);
final String name = fieldDefinition.GetName();
Geometry geometry = record.getValue(name);
if (geometry != null) {
final FieldDefinition attribute = recordDefinition.getField(name);
final GeometryFactory geometryFactory = attribute.getProperty(FieldProperties.GEOMETRY_FACTORY);
geometry = geometry.convertGeometry(geometryFactory);
final int geometryType = fieldDefinition.GetFieldType();
final int axisCount = geometryFactory.getAxisCount();
final org.gdal.ogr.Geometry ogrGeometry = toOgrGeometry(geometry, geometryType, axisCount);
feature.SetGeomField(fieldIndex, ogrGeometry);
}
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class GeometryTest method writeTestFile.
public static void writeTestFile(final GeometryFactory geometryFactory, final String wkt) {
final Geometry geometry = geometryFactory.geometry(wkt);
final DataType geometryDataType = DataTypes.getDataType(geometry);
String name = "/" + geometryDataType.getName();
if (geometryFactory.hasZ()) {
name += "Z";
}
final File file = new File("target/test-data/" + name + ".gdb");
FileUtil.deleteDirectory(file);
final PathName pathName = PathName.newPathName(name);
RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(pathName);
recordDefinition.addField("ID", DataTypes.INT, true);
final FieldDefinition geometryField = recordDefinition.addField("Geometry", geometryDataType, true);
geometryField.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
recordDefinition.setIdFieldName("ID");
final FileGdbRecordStore recordStore = FileGdbRecordStoreFactory.newRecordStore(file);
recordStore.initialize();
recordDefinition = (RecordDefinitionImpl) recordStore.getRecordDefinition(recordDefinition);
final Record object = new ArrayRecord(recordDefinition);
object.setIdentifier(Identifier.newIdentifier(1));
object.setGeometryValue(geometry);
recordStore.insertRecord(object);
final Record object2 = recordStore.getRecord(pathName, Identifier.newIdentifier(1));
if (!DataType.equal(object, object2)) {
System.out.println("Not Equal");
System.out.println(object);
System.out.println(object2);
}
recordStore.close();
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class Record method setValuesClone.
default void setValuesClone(final Record record) {
final List<FieldDefinition> fields = getFieldDefinitions();
for (final FieldDefinition fieldDefintion : fields) {
final String name = fieldDefintion.getName();
final Object value = record.getValue(name);
fieldDefintion.setValueClone(this, value);
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class Record method equalValue.
default boolean equalValue(final CharSequence fieldName, Object value) {
final FieldDefinition fieldDefinition = getFieldDefinition(fieldName);
if (fieldDefinition == null) {
return false;
} else {
final int fieldIndex = fieldDefinition.getIndex();
final Object fieldValue = getValue(fieldIndex);
final CodeTable codeTable = fieldDefinition.getCodeTable();
if (codeTable != null) {
value = codeTable.getIdentifier(value);
}
return fieldDefinition.equals(fieldValue, value);
}
}
Aggregations