use of com.revolsys.gis.esri.gdb.file.FileGdbRecordStore in project com.revolsys.open by revolsys.
the class FileGdbIoTest method doWriteReadTest.
public static void doWriteReadTest(GeometryFactory geometryFactory, final DataType dataType, Geometry geometry) {
final int axisCount = geometryFactory.getAxisCount();
if (geometry.isEmpty() || axisCount == 4) {
return;
}
geometryFactory = GeometryFactory.fixed(geometryFactory.getCoordinateSystemId(), axisCount, GeometryFactory.newScalesFixed(axisCount, 10000000.0));
geometry = geometry.convertGeometry(geometryFactory);
final String geometryTypeString = dataType.toString();
String name = "/tmp/revolsystest/io/gdb/" + geometryTypeString + "_" + axisCount;
if (geometry.isGeometryCollection()) {
name += "_" + geometry.getGeometryCount();
}
if (geometry instanceof Polygonal) {
name += "_" + geometry.getGeometryComponents(LinearRing.class).size();
}
final File file = new File(name + "_" + geometry.getVertexCount() + ".gdb");
FileUtil.deleteDirectory(file);
file.getParentFile().mkdirs();
try (final FileGdbRecordStore recordStore = FileGdbRecordStoreFactory.newRecordStore(file)) {
recordStore.setCreateMissingTables(true);
recordStore.setCreateMissingRecordStore(true);
recordStore.initialize();
final PathName typePath = PathName.newPathName("/" + geometryTypeString);
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(typePath);
recordDefinition.addField("ID", DataTypes.INT, true);
recordDefinition.addField("NAME", DataTypes.STRING, 50, false);
recordDefinition.addField("GEOMETRY", dataType, true);
recordDefinition.setGeometryFactory(geometryFactory);
recordStore.getRecordDefinition(recordDefinition);
try (Writer<Record> writer = recordStore.newRecordWriter()) {
writer.setProperty(IoConstants.GEOMETRY_FACTORY, geometryFactory);
writer.setProperty(IoConstants.GEOMETRY_TYPE, dataType);
final Record record = recordStore.newRecord(typePath);
record.setValue("ID", 1);
record.setGeometryValue(geometry);
writer.write(record);
}
try (Reader<Record> reader = recordStore.getRecords(typePath)) {
final List<Record> objects = reader.toList();
Assert.assertEquals("Geometry Count", 1, objects.size());
final Geometry actual = objects.get(0).getGeometry();
Assert.assertEquals("Empty", geometry.isEmpty(), actual.isEmpty());
if (!geometry.isEmpty()) {
final int geometryAxisCount = geometry.getAxisCount();
Assert.assertEquals("Axis Count", geometryAxisCount, actual.getAxisCount());
if (!actual.equals(geometryAxisCount, geometry)) {
// Allow for conversion of multi part to single part
if (geometry.getGeometryCount() != 1 || !actual.equals(geometryAxisCount, geometry.getGeometry(0))) {
TestUtil.failNotEquals("Geometry Equal Exact", geometry, actual);
}
}
}
}
}
}
use of com.revolsys.gis.esri.gdb.file.FileGdbRecordStore 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();
}
Aggregations