use of eu.esdihumboldt.hale.io.geopackage.internal.GeopackageFeatureCollection in project hale by halestudio.
the class GeopackageInstanceReader method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
progress.begin("Inspecting GeoPackage", ProgressIndicator.UNKNOWN);
try {
Map<String, String> queryFilters = new HashMap<>();
String queryFiltersParam = getParameter(PARAM_QUERY_FILTER).as(String.class, null);
if (StringUtils.hasText(queryFiltersParam)) {
Set<String> queryFiltersByTable = new HashSet<>(Arrays.asList(StringUtils.delimitedListToStringArray(queryFiltersParam, "||")));
for (String queryFilterRaw : queryFiltersByTable) {
String[] rawSplit = StringUtils.split(queryFilterRaw, "|");
if (rawSplit.length == 2) {
queryFilters.put(rawSplit[0].toUpperCase(), rawSplit[1]);
}
}
}
URI loc = getSource().getLocation();
File file;
try {
file = new File(loc);
} catch (Exception e) {
throw new IllegalArgumentException("Only files are supported as data source", e);
}
GeoPackage gpkg = GeoPackageManager.open(file, true);
Map<TypeDefinition, InstanceCollection> collections = new HashMap<>();
// try to load each feature table
for (String table : gpkg.getFeatureTables()) {
TypeDefinition type = findType(table);
if (type == null) {
reporter.warn("For feature table {0} no matching schema type could be identified", table);
} else {
FeatureDao features = gpkg.getFeatureDao(table);
String where = null;
if (queryFilters.containsKey(table.toUpperCase())) {
where = queryFilters.get(table.toUpperCase());
}
collections.put(type, new GeopackageFeatureCollection(features, type, where));
}
}
// try to load each attribute table
for (String table : gpkg.getAttributesTables()) {
TypeDefinition type = findType(table);
if (type == null) {
reporter.warn("For attribute table {0} no matching schema type could be identified", table);
} else {
AttributesDao attributes = gpkg.getAttributesDao(table);
collections.put(type, new GeopackageFeatureCollection(attributes, type));
}
}
collection = new PerTypeInstanceCollection(collections);
reporter.setSuccess(true);
} catch (Exception e) {
reporter.error(new IOMessageImpl("Error configuring database connection", e));
reporter.setSuccess(false);
} finally {
progress.end();
}
return reporter;
}
Aggregations