Search in sources :

Example 1 with FileGdbRecordStore

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);
                    }
                }
            }
        }
    }
}
Also used : FileGdbRecordStore(com.revolsys.gis.esri.gdb.file.FileGdbRecordStore) Polygonal(com.revolsys.geometry.model.Polygonal) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) Geometry(com.revolsys.geometry.model.Geometry) Record(com.revolsys.record.Record) PathName(com.revolsys.io.PathName) LinearRing(com.revolsys.geometry.model.LinearRing) File(java.io.File)

Example 2 with FileGdbRecordStore

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();
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) FileGdbRecordStore(com.revolsys.gis.esri.gdb.file.FileGdbRecordStore) ArrayRecord(com.revolsys.record.ArrayRecord) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) PathName(com.revolsys.io.PathName) File(java.io.File)

Aggregations

Geometry (com.revolsys.geometry.model.Geometry)2 FileGdbRecordStore (com.revolsys.gis.esri.gdb.file.FileGdbRecordStore)2 PathName (com.revolsys.io.PathName)2 Record (com.revolsys.record.Record)2 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)2 File (java.io.File)2 DataType (com.revolsys.datatype.DataType)1 LinearRing (com.revolsys.geometry.model.LinearRing)1 Polygonal (com.revolsys.geometry.model.Polygonal)1 ArrayRecord (com.revolsys.record.ArrayRecord)1 FieldDefinition (com.revolsys.record.schema.FieldDefinition)1