Search in sources :

Example 11 with Geodatabase

use of com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method getRecordCount.

@Override
public int getRecordCount(final Query query) {
    if (query == null) {
        return 0;
    } else {
        synchronized (this.apiSync) {
            final Geodatabase geodatabase = getGeodatabase();
            if (geodatabase == null) {
                return 0;
            } else {
                try {
                    String typePath = query.getTypeName();
                    RecordDefinition recordDefinition = query.getRecordDefinition();
                    if (recordDefinition == null) {
                        typePath = query.getTypeName();
                        recordDefinition = getRecordDefinition(typePath);
                        if (recordDefinition == null) {
                            return 0;
                        }
                    } else {
                        typePath = recordDefinition.getPath();
                    }
                    final StringBuilder whereClause = getWhereClause(query);
                    final BoundingBox boundingBox = QueryValue.getBoundingBox(query);
                    if (boundingBox == null) {
                        final StringBuilder sql = new StringBuilder();
                        sql.append("SELECT OBJECTID FROM ");
                        sql.append(JdbcUtils.getTableName(typePath));
                        if (whereClause.length() > 0) {
                            sql.append(" WHERE ");
                            sql.append(whereClause);
                        }
                        try (final FileGdbEnumRowsIterator rows = query(sql.toString(), false)) {
                            int count = 0;
                            for (@SuppressWarnings("unused") final Row row : rows) {
                                count++;
                            }
                            return count;
                        }
                    } else {
                        final GeometryFieldDefinition geometryField = (GeometryFieldDefinition) recordDefinition.getGeometryField();
                        if (geometryField == null || boundingBox.isEmpty()) {
                            return 0;
                        } else {
                            final StringBuilder sql = new StringBuilder();
                            sql.append("SELECT " + geometryField.getName() + " FROM ");
                            sql.append(JdbcUtils.getTableName(typePath));
                            if (whereClause.length() > 0) {
                                sql.append(" WHERE ");
                                sql.append(whereClause);
                            }
                            try (final FileGdbEnumRowsIterator rows = query(sql.toString(), false)) {
                                int count = 0;
                                for (final Row row : rows) {
                                    final Geometry geometry = (Geometry) geometryField.getValue(row);
                                    if (geometry != null) {
                                        final BoundingBox geometryBoundingBox = geometry.getBoundingBox();
                                        if (geometryBoundingBox.intersects(boundingBox)) {
                                            count++;
                                        }
                                    }
                                }
                                return count;
                            }
                        }
                    }
                } finally {
                    releaseGeodatabase();
                }
            }
        }
    }
}
Also used : Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) Geometry(com.revolsys.geometry.model.Geometry) BoundingBox(com.revolsys.geometry.model.BoundingBox) GeometryFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GeometryFieldDefinition) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) Row(com.revolsys.gis.esri.gdb.file.capi.swig.Row) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

Geodatabase (com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase)11 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)8 FileGdbDomainCodeTable (com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable)6 Table (com.revolsys.gis.esri.gdb.file.capi.swig.Table)6 CodeTable (com.revolsys.record.code.CodeTable)6 DETable (com.revolsys.record.io.format.esri.gdb.xml.model.DETable)6 PathName (com.revolsys.io.PathName)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)3 RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)3 ObjectException (com.revolsys.beans.ObjectException)2 ObjectPropertyException (com.revolsys.beans.ObjectPropertyException)2 SpatialReference (com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference)2 BoundingBox (com.revolsys.geometry.model.BoundingBox)1 Geometry (com.revolsys.geometry.model.Geometry)1 Row (com.revolsys.gis.esri.gdb.file.capi.swig.Row)1 GeometryFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.GeometryFieldDefinition)1 DEFeatureClass (com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass)1 DEFeatureDataset (com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureDataset)1 Field (com.revolsys.record.io.format.esri.gdb.xml.model.Field)1 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)1