use of com.revolsys.gis.esri.gdb.file.capi.type.GeometryFieldDefinition 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();
}
}
}
}
}
Aggregations