Search in sources :

Example 1 with RecordStoreSchema

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

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

the class FileGdbRecordStore method newSchema.

private RecordStoreSchema newSchema(final PathName schemaPath, final SpatialReference spatialReference) {
    synchronized (this.apiSync) {
        synchronized (API_SYNC) {
            final Geodatabase geodatabase = getGeodatabase();
            if (geodatabase == null) {
                return null;
            } else {
                try {
                    String parentCatalogPath = "\\";
                    RecordStoreSchema schema = getRootSchema();
                    for (final PathName childSchemaPath : schemaPath.getPaths()) {
                        if (childSchemaPath.length() > 1) {
                            RecordStoreSchema childSchema = schema.getSchema(childSchemaPath);
                            final String childCatalogPath = toCatalogPath(childSchemaPath);
                            if (!hasChildDataset(getGeodatabase(), parentCatalogPath, "Feature Dataset", childCatalogPath)) {
                                if (spatialReference != null) {
                                    final DEFeatureDataset dataset = EsriXmlRecordDefinitionUtil.newDEFeatureDataset(childCatalogPath, spatialReference);
                                    final String datasetDefinition = EsriGdbXmlSerializer.toString(dataset);
                                    try {
                                        geodatabase.createFeatureDataset(datasetDefinition);
                                    } catch (final Throwable t) {
                                        Logs.debug(this, datasetDefinition);
                                        throw new RuntimeException("Unable to create feature dataset " + childCatalogPath, t);
                                    }
                                }
                            }
                            if (childSchema == null) {
                                childSchema = newFeatureDatasetSchema(schema, childSchemaPath);
                                schema.addElement(childSchema);
                            }
                            schema = childSchema;
                            parentCatalogPath = childCatalogPath;
                        }
                    }
                    return schema;
                } finally {
                    releaseGeodatabase();
                }
            }
        }
    }
}
Also used : Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) DEFeatureDataset(com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureDataset) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) PathName(com.revolsys.io.PathName)

Example 3 with RecordStoreSchema

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

the class FileGdbRecordStore method newFeatureDatasetSchema.

private RecordStoreSchema newFeatureDatasetSchema(final RecordStoreSchema parentSchema, final PathName schemaPath) {
    final PathName childSchemaPath = schemaPath;
    final RecordStoreSchema schema = new RecordStoreSchema(parentSchema, childSchemaPath);
    this.catalogPathByPath.put(childSchemaPath, toCatalogPath(schemaPath));
    return schema;
}
Also used : RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) PathName(com.revolsys.io.PathName)

Example 4 with RecordStoreSchema

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

the class FileGdbRecordStore method newTableRecordDefinition.

private RecordDefinitionImpl newTableRecordDefinition(final DETable deTable) {
    synchronized (this.apiSync) {
        synchronized (API_SYNC) {
            final Geodatabase geodatabase = getGeodatabase();
            if (geodatabase == null) {
                return null;
            } else {
                try {
                    String schemaCatalogPath = deTable.getParentCatalogPath();
                    SpatialReference spatialReference;
                    if (deTable instanceof DEFeatureClass) {
                        final DEFeatureClass featureClass = (DEFeatureClass) deTable;
                        spatialReference = featureClass.getSpatialReference();
                    } else {
                        spatialReference = null;
                    }
                    PathName schemaPath = toPath(schemaCatalogPath);
                    final RecordStoreSchema schema = newSchema(schemaPath, spatialReference);
                    if (schemaPath.equals(this.defaultSchemaPath)) {
                        if (!(deTable instanceof DEFeatureClass)) {
                            schemaCatalogPath = "\\";
                            deTable.setCatalogPath("\\" + deTable.getName());
                        }
                    } else if (schemaPath.equals("")) {
                        schemaPath = this.defaultSchemaPath;
                    }
                    for (final Field field : deTable.getFields()) {
                        final String fieldName = field.getName();
                        final CodeTable codeTable = getCodeTableByFieldName(fieldName);
                        if (codeTable instanceof FileGdbDomainCodeTable) {
                            final FileGdbDomainCodeTable domainCodeTable = (FileGdbDomainCodeTable) codeTable;
                            field.setDomain(domainCodeTable.getDomain());
                        }
                    }
                    final String tableDefinition = EsriGdbXmlSerializer.toString(deTable);
                    try {
                        final Table table = geodatabase.createTable(tableDefinition, schemaCatalogPath);
                        geodatabase.closeTable(table);
                        table.delete();
                        final RecordDefinitionImpl recordDefinition = getRecordDefinition(PathName.newPathName(schemaPath), schemaCatalogPath, tableDefinition);
                        initRecordDefinition(recordDefinition);
                        schema.addElement(recordDefinition);
                        return recordDefinition;
                    } catch (final Throwable t) {
                        throw new RuntimeException("Unable to create table " + deTable.getCatalogPath(), t);
                    }
                } finally {
                    releaseGeodatabase();
                }
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) CodeTable(com.revolsys.record.code.CodeTable) DETable(com.revolsys.record.io.format.esri.gdb.xml.model.DETable) Table(com.revolsys.gis.esri.gdb.file.capi.swig.Table) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) DEFeatureClass(com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) Field(com.revolsys.record.io.format.esri.gdb.xml.model.Field) SpatialReference(com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference) PathName(com.revolsys.io.PathName)

Example 5 with RecordStoreSchema

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

the class PathRecordStoreTreeNode method loadChildrenDo.

@Override
protected List<BaseTreeNode> loadChildrenDo() {
    final RecordStore recordStore = getRecordStore();
    if (recordStore != null) {
        final RecordStoreSchema schema = recordStore.getRootSchema();
        if (schema != null) {
            schema.refresh();
            final List<BaseTreeNode> children = new ArrayList<>();
            for (final RecordStoreSchemaElement element : schema.getElements()) {
                final BaseTreeNode node = BaseTreeNode.newTreeNode(element);
                children.add(node);
            }
            return children;
        }
    }
    return Collections.emptyList();
}
Also used : RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) RecordStore(com.revolsys.record.schema.RecordStore) ArrayList(java.util.ArrayList) BaseTreeNode(com.revolsys.swing.tree.BaseTreeNode) RecordStoreSchemaElement(com.revolsys.record.schema.RecordStoreSchemaElement)

Aggregations

RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)12 PathName (com.revolsys.io.PathName)11 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)4 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)4 RecordStoreSchemaElement (com.revolsys.record.schema.RecordStoreSchemaElement)4 Geodatabase (com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase)3 FieldDefinition (com.revolsys.record.schema.FieldDefinition)3 TreeMap (java.util.TreeMap)3 DataType (com.revolsys.datatype.DataType)2 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)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 DETable (com.revolsys.record.io.format.esri.gdb.xml.model.DETable)2 Field (com.revolsys.record.io.format.esri.gdb.xml.model.Field)2 SpatialReference (com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference)2 RecordDefinition (com.revolsys.record.schema.RecordDefinition)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Table (com.revolsys.gis.esri.gdb.file.capi.swig.Table)1