Search in sources :

Example 6 with RecordDefinitionImpl

use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.

the class ArcSdeObjectIdJdbcFieldDefinition method replaceAttribute.

public static void replaceAttribute(final String schemaName, final RecordDefinition recordDefinition, final Integer registrationId, final String rowIdColumn) {
    final JdbcFieldDefinition objectIdAttribute = (JdbcFieldDefinition) recordDefinition.getField(rowIdColumn);
    if (objectIdAttribute != null && !(objectIdAttribute instanceof ArcSdeObjectIdJdbcFieldDefinition)) {
        final String name = objectIdAttribute.getName();
        final String description = objectIdAttribute.getDescription();
        final Map<String, Object> properties = objectIdAttribute.getProperties();
        final ArcSdeObjectIdJdbcFieldDefinition newObjectIdAttribute = new ArcSdeObjectIdJdbcFieldDefinition(objectIdAttribute.getDbName(), name, description, properties, schemaName, registrationId);
        newObjectIdAttribute.setRecordDefinition(recordDefinition);
        final RecordDefinitionImpl recordDefinitionImpl = (RecordDefinitionImpl) recordDefinition;
        recordDefinitionImpl.replaceField(objectIdAttribute, newObjectIdAttribute);
        if (recordDefinition.getIdFieldName() == null && recordDefinition.getIdFieldNames().isEmpty()) {
            recordDefinitionImpl.setIdFieldName(name);
        }
    }
}
Also used : JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl)

Example 7 with RecordDefinitionImpl

use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.

the class OgrRecordStore method newLayerRecordDefinition.

protected RecordDefinitionImpl newLayerRecordDefinition(final RecordStoreSchema schema, final Layer layer) {
    final String layerName = layer.GetName();
    final PathName typePath = PathName.newPathName(layerName);
    /**
     * This primes the layer so that the fidColumn is loaded correctly.
     */
    layer.GetNextFeature();
    final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(schema, typePath);
    String idFieldName = layer.GetFIDColumn();
    if (!Property.hasValue(idFieldName)) {
        idFieldName = "rowid";
    }
    this.idFieldNames.put(typePath.getUpperPath(), idFieldName);
    final FeatureDefn layerDefinition = layer.GetLayerDefn();
    if (SQLITE.equals(this.driverName) || GEO_PAKCAGE.equals(this.driverName)) {
        recordDefinition.addField(idFieldName, DataTypes.LONG, true);
        recordDefinition.setIdFieldName(idFieldName);
    }
    for (int fieldIndex = 0; fieldIndex < layerDefinition.GetFieldCount(); fieldIndex++) {
        final FieldDefn fieldDefinition = layerDefinition.GetFieldDefn(fieldIndex);
        final String fieldName = fieldDefinition.GetName();
        final int fieldType = fieldDefinition.GetFieldType();
        final int fieldWidth = fieldDefinition.GetWidth();
        final int fieldPrecision = fieldDefinition.GetPrecision();
        DataType fieldDataType;
        switch(fieldType) {
            case 0:
                fieldDataType = DataTypes.INT;
                break;
            case 2:
                fieldDataType = DataTypes.DOUBLE;
                break;
            case 4:
            case 6:
                fieldDataType = DataTypes.STRING;
                break;
            case 9:
                fieldDataType = DataTypes.DATE;
                break;
            case 11:
                fieldDataType = DataTypes.DATE_TIME;
                break;
            default:
                fieldDataType = DataTypes.STRING;
                final String fieldTypeName = fieldDefinition.GetFieldTypeName(fieldType);
                Logs.error(this, "Unsupported field type " + this.file + " " + fieldName + ": " + fieldTypeName);
                break;
        }
        final FieldDefinition field = new FieldDefinition(fieldName, fieldDataType, fieldWidth, fieldPrecision, false);
        recordDefinition.addField(field);
    }
    for (int fieldIndex = 0; fieldIndex < layerDefinition.GetGeomFieldCount(); fieldIndex++) {
        final GeomFieldDefn fieldDefinition = layerDefinition.GetGeomFieldDefn(fieldIndex);
        final String fieldName = fieldDefinition.GetName();
        final int geometryFieldType = fieldDefinition.GetFieldType();
        DataType geometryFieldDataType;
        int axisCount = 2;
        switch(geometryFieldType) {
            case 1:
                geometryFieldDataType = DataTypes.POINT;
                break;
            case 2:
                geometryFieldDataType = DataTypes.LINE_STRING;
                break;
            case 3:
                geometryFieldDataType = DataTypes.POLYGON;
                break;
            case 4:
                geometryFieldDataType = DataTypes.MULTI_POINT;
                break;
            case 5:
                geometryFieldDataType = DataTypes.MULTI_LINE_STRING;
                break;
            case 6:
                geometryFieldDataType = DataTypes.MULTI_POLYGON;
                break;
            case 7:
                geometryFieldDataType = DataTypes.GEOMETRY_COLLECTION;
                break;
            case 101:
                geometryFieldDataType = DataTypes.LINEAR_RING;
                break;
            case 0x80000000 + 1:
                geometryFieldDataType = DataTypes.POINT;
                axisCount = 3;
                break;
            case 0x80000000 + 2:
                geometryFieldDataType = DataTypes.LINE_STRING;
                axisCount = 3;
                break;
            case 0x80000000 + 3:
                geometryFieldDataType = DataTypes.POLYGON;
                axisCount = 3;
                break;
            case 0x80000000 + 4:
                geometryFieldDataType = DataTypes.MULTI_POINT;
                axisCount = 3;
                break;
            case 0x80000000 + 5:
                geometryFieldDataType = DataTypes.MULTI_LINE_STRING;
                axisCount = 3;
                break;
            case 0x80000000 + 6:
                geometryFieldDataType = DataTypes.MULTI_POLYGON;
                axisCount = 3;
                break;
            case 0x80000000 + 7:
                geometryFieldDataType = DataTypes.GEOMETRY_COLLECTION;
                axisCount = 3;
                break;
            default:
                geometryFieldDataType = DataTypes.GEOMETRY;
                break;
        }
        final SpatialReference spatialReference = fieldDefinition.GetSpatialRef();
        final GeometryFactory geometryFactory = Gdal.getGeometryFactory(spatialReference, axisCount);
        final FieldDefinition field = new FieldDefinition(fieldName, geometryFieldDataType, false);
        field.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
        recordDefinition.addField(field);
    }
    return recordDefinition;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FeatureDefn(org.gdal.ogr.FeatureDefn) GeomFieldDefn(org.gdal.ogr.GeomFieldDefn) FieldDefn(org.gdal.ogr.FieldDefn) FieldDefinition(com.revolsys.record.schema.FieldDefinition) GeomFieldDefn(org.gdal.ogr.GeomFieldDefn) SpatialReference(org.gdal.osr.SpatialReference) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

Example 8 with RecordDefinitionImpl

use of com.revolsys.record.schema.RecordDefinitionImpl 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 9 with RecordDefinitionImpl

use of com.revolsys.record.schema.RecordDefinitionImpl 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 10 with RecordDefinitionImpl

use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.

the class FeatureSource method newLayer.

private FeatureLayer newLayer(final String name, final MapEx element, final MapEx complexType) {
    if (!"true".equals(getString(complexType, "@abstract"))) {
        final PathName pathName = getPathName();
        final PathName layerPathName = pathName.newChild(name);
        final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(layerPathName);
        GeometryFactory geometryFactory = GeometryFactory.DEFAULT_3D;
        final MapEx complexContent = getValue(complexType, "xs:complexContent");
        final MapEx extension = getValue(complexContent, "xs:extension");
        if ("gml:AbstractFeatureType".equals(getString(extension, "@base"))) {
            final MapEx sequence = getValue(extension, "xs:sequence");
            final List<MapEx> elements = sequence.getValue("xs:element");
            for (final MapEx fieldElement : elements) {
                final String fieldName = getString(fieldElement, "@name");
                final boolean required = !"0".equals(getString(fieldElement, "@minOccurs"));
                DataType dataType = DataTypes.STRING;
                final MapEx simpleFieldType = getValue(fieldElement, "xs:simpleType");
                if (simpleFieldType == null) {
                    final String fieldType = getString(fieldElement, "@type");
                    if ("gml:AbstractGeometryType".equals(fieldType)) {
                        final String geometryTypes = getString(fieldElement, "@fdo:geometryTypes");
                        for (final String geometryType : geometryTypes.split(" ")) {
                            final DataType geometryDataType = DataTypes.getDataType(geometryType);
                            if (geometryDataType != DataTypes.OBJECT) {
                                if (dataType == DataTypes.STRING) {
                                    dataType = geometryDataType;
                                } else if (dataType == DataTypes.GEOMETRY) {
                                } else if (geometryDataType == DataTypes.GEOMETRY) {
                                    dataType = DataTypes.GEOMETRY;
                                } else if (geometryDataType == DataTypes.GEOMETRY_COLLECTION) {
                                    dataType = DataTypes.GEOMETRY;
                                } else if (dataType.equals(DataTypes.POINT)) {
                                    if (geometryDataType.equals(DataTypes.POINT)) {
                                    } else if (geometryDataType.equals(DataTypes.MULTI_POINT)) {
                                        dataType = DataTypes.MULTI_POINT;
                                    } else {
                                        dataType = DataTypes.GEOMETRY;
                                    }
                                } else if (dataType.equals(DataTypes.MULTI_POINT)) {
                                    if (geometryDataType.equals(DataTypes.POINT)) {
                                    } else if (geometryDataType.equals(DataTypes.MULTI_POINT)) {
                                    } else {
                                        dataType = DataTypes.GEOMETRY;
                                    }
                                } else if (dataType.equals(DataTypes.LINE_STRING)) {
                                    if (geometryDataType.equals(DataTypes.LINE_STRING)) {
                                    } else if (geometryDataType.equals(DataTypes.MULTI_LINE_STRING)) {
                                        dataType = DataTypes.MULTI_LINE_STRING;
                                    } else {
                                        dataType = DataTypes.GEOMETRY;
                                    }
                                } else if (dataType.equals(DataTypes.MULTI_LINE_STRING)) {
                                    if (geometryDataType.equals(DataTypes.LINE_STRING)) {
                                    } else if (geometryDataType.equals(DataTypes.MULTI_LINE_STRING)) {
                                    } else {
                                        dataType = DataTypes.GEOMETRY;
                                    }
                                } else if (dataType.equals(DataTypes.POLYGON)) {
                                    if (geometryDataType.equals(DataTypes.POLYGON)) {
                                    } else if (geometryDataType.equals(DataTypes.MULTI_POLYGON)) {
                                        dataType = DataTypes.MULTI_POLYGON;
                                    } else {
                                        dataType = DataTypes.GEOMETRY;
                                    }
                                } else if (dataType.equals(DataTypes.MULTI_POLYGON)) {
                                    if (geometryDataType.equals(DataTypes.POLYGON)) {
                                    } else if (geometryDataType.equals(DataTypes.MULTI_POLYGON)) {
                                    } else {
                                        dataType = DataTypes.GEOMETRY;
                                    }
                                }
                            }
                        }
                        if (dataType == DataTypes.STRING) {
                            dataType = DataTypes.GEOMETRY;
                        }
                        int axisCount = 2;
                        if ("true".equals(getString(fieldElement, "@fdo:hasMeasure"))) {
                            axisCount = 4;
                        } else if ("true".equals(getString(fieldElement, "@fdo:hasElevation"))) {
                            axisCount = 3;
                        }
                        final String srsName = getString(fieldElement, "@fdo:srsName");
                        if (Property.hasValue(srsName)) {
                            final Integer coordinateSystemId = Maps.getInteger(this.coordinateSystemIdBySrsName, srsName);
                            if (coordinateSystemId == null) {
                                try {
                                    final Map<String, Object> csParameters = Collections.singletonMap("CSCODE", srsName);
                                    final MapGuideWebService webService = getWebService();
                                    final Resource wktResource = webService.getResource("CS.CONVERTCOORDINATESYSTEMCODETOWKT", null, csParameters);
                                    final String wkt = wktResource.contentsAsString();
                                    geometryFactory = GeometryFactory.floating(wkt, axisCount);
                                } catch (final Throwable e) {
                                }
                            } else {
                                geometryFactory = GeometryFactory.floating(coordinateSystemId, axisCount);
                            }
                        }
                    }
                } else {
                    final MapEx restriction = getValue(simpleFieldType, "xs:restriction");
                    if (restriction != null) {
                        final String fieldBase = getString(restriction, "@base");
                        dataType = DataTypes.getDataType(fieldBase.replace("xs:", ""));
                    }
                }
                if (dataType != null) {
                    recordDefinition.addField(fieldName, dataType, required);
                }
            }
            recordDefinition.setGeometryFactory(geometryFactory);
            final FeatureLayer layer = new FeatureLayer(this, recordDefinition);
            return layer;
        }
    }
    return null;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LinkedHashMapEx(com.revolsys.collection.map.LinkedHashMapEx) MapEx(com.revolsys.collection.map.MapEx) WebServiceResource(com.revolsys.webservice.WebServiceResource) Resource(com.revolsys.spring.resource.Resource) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

Aggregations

RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)30 PathName (com.revolsys.io.PathName)14 DataType (com.revolsys.datatype.DataType)10 FieldDefinition (com.revolsys.record.schema.FieldDefinition)7 RecordDefinition (com.revolsys.record.schema.RecordDefinition)6 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)4 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Geometry (com.revolsys.geometry.model.Geometry)3 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)3 ArrayRecord (com.revolsys.record.ArrayRecord)3 Record (com.revolsys.record.Record)3 DETable (com.revolsys.record.io.format.esri.gdb.xml.model.DETable)3 MapEx (com.revolsys.collection.map.MapEx)2 FileGdbRecordStore (com.revolsys.gis.esri.gdb.file.FileGdbRecordStore)2 FileGdbDomainCodeTable (com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable)2 CodeTable (com.revolsys.record.code.CodeTable)2 DEFeatureClass (com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass)2 Field (com.revolsys.record.io.format.esri.gdb.xml.model.Field)2