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;
}
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;
}
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;
}
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");
}
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;
}
Aggregations