Search in sources :

Example 1 with SpatialReference

use of com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method getSpatialReference.

public static SpatialReference getSpatialReference(final GeometryFactory geometryFactory) {
    if (geometryFactory == null || geometryFactory.getCoordinateSystemId() == 0) {
        return null;
    } else {
        final String wkt = getSingleThreadResult(() -> {
            return EsriFileGdb.getSpatialReferenceWkt(geometryFactory.getCoordinateSystemId());
        });
        final SpatialReference spatialReference = SpatialReference.get(geometryFactory, wkt);
        return spatialReference;
    }
}
Also used : SpatialReference(com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)

Example 2 with SpatialReference

use of com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference 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 3 with SpatialReference

use of com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method refreshSchemaElements.

@Override
protected Map<PathName, ? extends RecordStoreSchemaElement> refreshSchemaElements(final RecordStoreSchema schema) {
    synchronized (this.apiSync) {
        synchronized (API_SYNC) {
            final Map<PathName, RecordStoreSchemaElement> elementsByPath = new TreeMap<>();
            final Geodatabase geodatabase = getGeodatabase();
            if (geodatabase != null) {
                try {
                    final PathName schemaPath = schema.getPathName();
                    final String schemaCatalogPath = getCatalogPath(schema);
                    final VectorOfWString childDatasets = getChildDatasets(geodatabase, schemaCatalogPath, "Feature Dataset");
                    if (childDatasets != null) {
                        for (int i = 0; i < childDatasets.size(); i++) {
                            final String childCatalogPath = childDatasets.get(i);
                            final PathName childPath = toPath(childCatalogPath);
                            RecordStoreSchema childSchema = schema.getSchema(childPath);
                            if (childSchema == null) {
                                childSchema = newFeatureDatasetSchema(schema, childPath);
                            } else {
                                if (childSchema.isInitialized()) {
                                    childSchema.refresh();
                                }
                            }
                            elementsByPath.put(childPath, childSchema);
                        }
                    }
                    if (schemaPath.isParentOf(this.defaultSchemaPath) && !elementsByPath.containsKey(this.defaultSchemaPath)) {
                        final SpatialReference spatialReference = getSpatialReference(getGeometryFactory());
                        final RecordStoreSchema childSchema = newSchema(this.defaultSchemaPath, spatialReference);
                        elementsByPath.put(this.defaultSchemaPath, childSchema);
                    }
                    if (schema.equalPath(this.defaultSchemaPath)) {
                        refreshSchemaRecordDefinitions(elementsByPath, schemaPath, "\\", "Feature Class");
                        refreshSchemaRecordDefinitions(elementsByPath, schemaPath, "\\", "Table");
                    }
                    refreshSchemaRecordDefinitions(elementsByPath, schemaPath, schemaCatalogPath, "Feature Class");
                    refreshSchemaRecordDefinitions(elementsByPath, schemaPath, schemaCatalogPath, "Table");
                } finally {
                    releaseGeodatabase();
                }
            }
            return elementsByPath;
        }
    }
}
Also used : Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) SpatialReference(com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference) PathName(com.revolsys.io.PathName) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) TreeMap(java.util.TreeMap) RecordStoreSchemaElement(com.revolsys.record.schema.RecordStoreSchemaElement)

Example 4 with SpatialReference

use of com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method newTableRecordDefinition.

private RecordDefinition newTableRecordDefinition(final RecordDefinition recordDefinition) {
    synchronized (this.apiSync) {
        synchronized (API_SYNC) {
            final GeometryFactory geometryFactory = recordDefinition.getGeometryFactory();
            final SpatialReference spatialReference = getSpatialReference(geometryFactory);
            final DETable deTable = EsriXmlRecordDefinitionUtil.getDETable(recordDefinition, spatialReference, this.createLengthField, this.createAreaField);
            final RecordDefinitionImpl tableRecordDefinition = newTableRecordDefinition(deTable);
            final String idFieldName = recordDefinition.getIdFieldName();
            if (idFieldName != null) {
                tableRecordDefinition.setIdFieldName(idFieldName);
            }
            return tableRecordDefinition;
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) SpatialReference(com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) DETable(com.revolsys.record.io.format.esri.gdb.xml.model.DETable)

Aggregations

VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)4 SpatialReference (com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference)4 Geodatabase (com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase)2 PathName (com.revolsys.io.PathName)2 DETable (com.revolsys.record.io.format.esri.gdb.xml.model.DETable)2 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)2 RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)2 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 FileGdbDomainCodeTable (com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable)1 Table (com.revolsys.gis.esri.gdb.file.capi.swig.Table)1 CodeTable (com.revolsys.record.code.CodeTable)1 DEFeatureClass (com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass)1 Field (com.revolsys.record.io.format.esri.gdb.xml.model.Field)1 RecordStoreSchemaElement (com.revolsys.record.schema.RecordStoreSchemaElement)1 TreeMap (java.util.TreeMap)1