use of org.openlca.core.database.LocationDao in project olca-modules by GreenDelta.
the class Sequence method init.
private void init(IDatabase db) {
index(CATEGORY, new CategoryDao(db));
index(LOCATION, new LocationDao(db));
index(ACTOR, new ActorDao(db));
index(SOURCE, new SourceDao(db));
index(UNIT, new UnitDao(db));
index(UNIT_GROUP, new UnitGroupDao(db));
index(FLOW_PROPERTY, new FlowPropertyDao(db));
index(FLOW, new FlowDao(db));
index(CURRENCY, new CurrencyDao(db));
index(PROCESS, new ProcessDao(db));
index(PRODUCT_SYSTEM, new ProductSystemDao(db));
index(IMPACT_CATEGORY, new ImpactCategoryDao(db));
index(IMPACT_METHOD, new ImpactMethodDao(db));
index(NW_SET, new NwSetDao(db));
index(PROJECT, new ProjectDao(db));
index(DQ_SYSTEM, new DQSystemDao(db));
index(SOCIAL_INDICATOR, new SocialIndicatorDao(db));
}
use of org.openlca.core.database.LocationDao in project olca-modules by GreenDelta.
the class LocationExport method doIt.
@Override
protected void doIt(CSVPrinter printer, IDatabase db) throws IOException {
log.trace("write locations");
LocationDao dao = new LocationDao(db);
List<Location> locations = dao.getAll();
for (Location location : locations) {
Object[] line = createLine(location);
printer.printRecord(line);
}
log.trace("{} locations written", locations.size());
}
use of org.openlca.core.database.LocationDao in project olca-modules by GreenDelta.
the class GeoJsonImport method run.
@Override
public void run() {
try {
// parse GeoJSON
log.trace("parse GeoJSON file {}", file);
FeatureCollection coll = GeoJSON.read(file);
if (coll == null || coll.features.isEmpty())
return;
// index locations
LocationDao dao = new LocationDao(db);
indexLocations(dao);
// match and update the locations
for (Feature f : coll.features) {
if (f.geometry == null || f.properties == null)
continue;
Location loc = findMatch(f);
if (loc == null)
continue;
loc.geodata = GeoJSON.pack(FeatureCollection.of(f.geometry));
dao.update(loc);
}
} catch (Exception e) {
log.error("Failed to import GeoJSON file " + file, e);
}
}
use of org.openlca.core.database.LocationDao in project olca-modules by GreenDelta.
the class LocationResult method getLocation.
private Location getLocation(long id) {
Location loc = cache.get(id);
if (loc != null)
return loc;
loc = new LocationDao(db).getForId(id);
cache.put(id, loc);
return loc;
}
use of org.openlca.core.database.LocationDao in project olca-modules by GreenDelta.
the class Library method syncElementaryFlows.
/**
* Returns the elementary flows of the library in matrix order. If this
* information is not present or something went wrong while synchronizing
* the flow index with the database, an empty option is returned.
*/
public Optional<EnviIndex> syncElementaryFlows(IDatabase db) {
var proto = getElemFlowIndex();
int size = proto.getFlowCount();
if (size == 0)
return Optional.empty();
var info = getInfo();
var index = info.isRegionalized() ? EnviIndex.createRegionalized() : EnviIndex.create();
var flows = descriptors(new FlowDao(db));
var locations = descriptors(new LocationDao(db));
for (int i = 0; i < size; i++) {
var entry = proto.getFlow(i);
var flow = flows.get(entry.getFlow().getId());
var location = locations.get(entry.getLocation().getId());
if (flow == null)
return Optional.empty();
if (entry.getIsInput()) {
index.add(EnviFlow.inputOf(flow, location));
} else {
index.add(EnviFlow.outputOf(flow, location));
}
}
return Optional.of(index);
}
Aggregations