Search in sources :

Example 21 with Location

use of org.openlca.core.model.Location in project olca-modules by GreenDelta.

the class Processes method findForLabel.

/**
 * Searches the given database for a process with the given label. A label
 * can contain a suffix with a location code which is considered in this
 * function.
 */
public static ProcessDescriptor findForLabel(IDatabase db, String label) {
    if (db == null || label == null)
        return null;
    String name = null;
    Location location = null;
    if (label.contains(" - ")) {
        int splitIdx = label.lastIndexOf(" - ");
        name = label.substring(0, splitIdx).trim();
        String locationCode = label.substring(splitIdx + 3).trim();
        LocationDao dao = new LocationDao(db);
        for (Location loc : dao.getAll()) {
            if (Strings.nullOrEqual(loc.code, locationCode)) {
                location = loc;
                break;
            }
        }
    }
    ProcessDescriptor selected = null;
    ProcessDao pDao = new ProcessDao(db);
    for (ProcessDescriptor d : pDao.getDescriptors()) {
        if (!Strings.nullOrEqual(label, d.name) && !Strings.nullOrEqual(name, d.name))
            continue;
        if (selected == null) {
            selected = d;
            if (matchLocation(selected, location))
                break;
            else
                continue;
        }
        if (matchLocation(d, location) && !matchLocation(selected, location)) {
            selected = d;
            break;
        }
    }
    return selected;
}
Also used : ProcessDao(org.openlca.core.database.ProcessDao) LocationDao(org.openlca.core.database.LocationDao) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) Location(org.openlca.core.model.Location)

Example 22 with Location

use of org.openlca.core.model.Location in project olca-modules by GreenDelta.

the class LocationImport method map.

@Override
Location map(JsonObject json, long id) {
    if (json == null)
        return null;
    Location loc = new Location();
    In.mapAtts(json, loc, id, conf);
    loc.code = Json.getString(json, "code");
    double latitude = Json.getDouble(json, "latitude", 0);
    double longitude = Json.getDouble(json, "longitude", 0);
    loc.latitude = latitude;
    loc.longitude = longitude;
    JsonObject geometry = Json.getObject(json, "geometry");
    if (geometry != null) {
        try {
            FeatureCollection coll = GeoJSON.read(geometry);
            if (coll != null) {
                loc.geodata = GeoJSON.pack(coll);
            }
        } catch (Exception e) {
            Logger log = LoggerFactory.getLogger(getClass());
            log.error("Failed to read geometry data from " + loc, e);
        }
    }
    loc = conf.db.put(loc);
    return loc;
}
Also used : FeatureCollection(org.openlca.geo.geojson.FeatureCollection) JsonObject(com.google.gson.JsonObject) Logger(org.slf4j.Logger) Location(org.openlca.core.model.Location)

Example 23 with Location

use of org.openlca.core.model.Location in project olca-modules by GreenDelta.

the class GeoJsonImport method findMatch.

private Location findMatch(Feature f) {
    if (f == null || f.geometry == null || f.properties == null)
        return null;
    // and finally by name
    for (Map<String, Location> map : Arrays.asList(byUUID, byCode, byName)) {
        for (Object prop : f.properties.values()) {
            if (!(prop instanceof String))
                continue;
            String s = (String) prop;
            Location loc = map.get(s);
            if (loc != null && loc.geodata == null) {
                log.trace("identified location {} via attribute {}", loc, s);
                return loc;
            }
        }
    }
    return null;
}
Also used : Location(org.openlca.core.model.Location)

Example 24 with Location

use of org.openlca.core.model.Location in project olca-modules by GreenDelta.

the class ProcessConverter method mapGeography.

private void mapGeography(ProcessDocumentation doc, DataSet dataSet) {
    IGeography geography = factory.createGeography();
    dataSet.setGeography(geography);
    Location location = process.location;
    if (location != null)
        geography.setLocation(location.code);
    if (doc.geography != null)
        geography.setText(doc.geography);
    if (!config.isCreateDefaults())
        return;
    if (geography.getLocation() == null)
        geography.setLocation("GLO");
}
Also used : IGeography(org.openlca.ecospold.IGeography) Location(org.openlca.core.model.Location)

Example 25 with Location

use of org.openlca.core.model.Location in project olca-modules by GreenDelta.

the class DB method findLocation.

public Location findLocation(String locationCode, String genKey) {
    Location location = get(Location.class, locations, genKey);
    if (location != null)
        return location;
    location = search.findLocation(locationCode);
    if (location != null)
        locations.put(genKey, location);
    return location;
}
Also used : Location(org.openlca.core.model.Location)

Aggregations

Location (org.openlca.core.model.Location)44 LocationDao (org.openlca.core.database.LocationDao)11 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 ProcessDescriptor (org.openlca.core.model.descriptors.ProcessDescriptor)6 Test (org.junit.Test)5 FlowDescriptor (org.openlca.core.model.descriptors.FlowDescriptor)5 FeatureCollection (org.openlca.geo.geojson.FeatureCollection)5 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)4 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)4 EnviFlow (org.openlca.core.matrix.index.EnviFlow)4 Category (org.openlca.core.model.Category)4 Flow (org.openlca.core.model.Flow)4 Process (org.openlca.core.model.Process)4 ImpactDescriptor (org.openlca.core.model.descriptors.ImpactDescriptor)4 List (java.util.List)3 CostResultDescriptor (org.openlca.app.util.CostResultDescriptor)3 Feature (org.openlca.geo.geojson.Feature)3 Pair (org.openlca.util.Pair)3 TLongByteHashMap (gnu.trove.map.hash.TLongByteHashMap)2