Search in sources :

Example 31 with FieldDefinition

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);
}
Also used : RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) SpatialReference(org.gdal.osr.SpatialReference) PathName(com.revolsys.io.PathName) Layer(org.gdal.ogr.Layer)

Example 32 with FieldDefinition

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);
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) GeomFieldDefn(org.gdal.ogr.GeomFieldDefn) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 33 with FieldDefinition

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

Example 34 with FieldDefinition

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);
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition)

Example 35 with FieldDefinition

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);
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) FieldDefinition(com.revolsys.record.schema.FieldDefinition)

Aggregations

FieldDefinition (com.revolsys.record.schema.FieldDefinition)133 RecordDefinition (com.revolsys.record.schema.RecordDefinition)38 DataType (com.revolsys.datatype.DataType)32 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)23 JdbcFieldDefinition (com.revolsys.jdbc.field.JdbcFieldDefinition)19 PathName (com.revolsys.io.PathName)15 Record (com.revolsys.record.Record)15 ArrayList (java.util.ArrayList)15 Geometry (com.revolsys.geometry.model.Geometry)13 CodeTable (com.revolsys.record.code.CodeTable)9 Query (com.revolsys.record.query.Query)8 LineString (com.revolsys.geometry.model.LineString)7 ArrayRecord (com.revolsys.record.ArrayRecord)7 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)7 SQLException (java.sql.SQLException)7 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 IOException (java.io.IOException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 BadLocationException (javax.swing.text.BadLocationException)4