use of eu.esdihumboldt.hale.common.instance.model.InstanceReference in project hale by halestudio.
the class StyledMapUtil method zoomToSelection.
/**
* Zoom to the selected instances. Does nothing if the selection is empty or
* contains no {@link Instance}s or {@link InstanceReference}s.
*
* @param mapKit the map kit
* @param selection the selection
*/
public static void zoomToSelection(BasicMapKit mapKit, IStructuredSelection selection) {
BoundingBox bb = null;
// determine bounding box for each reference and accumulate it
for (AbstractInstancePainter painter : mapKit.getTilePainters(AbstractInstancePainter.class)) {
for (Object element : selection.toList()) {
InstanceReference ref = getReference(element);
if (ref != null) {
InstanceWaypoint wp = painter.findWaypoint(ref);
if (wp != null) {
BoundingBox wpBB = wp.getBoundingBox();
if (wpBB.checkIntegrity() && !wpBB.isEmpty()) {
if (bb == null) {
bb = new BoundingBox(wpBB);
} else {
bb.add(wpBB);
}
}
}
}
}
}
if (bb != null) {
Set<GeoPosition> positions = new HashSet<GeoPosition>();
positions.add(new GeoPosition(bb.getMinX(), bb.getMinY(), SelectableWaypoint.COMMON_EPSG));
positions.add(new GeoPosition(bb.getMaxX(), bb.getMaxY(), SelectableWaypoint.COMMON_EPSG));
mapKit.zoomToPositions(positions);
}
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceReference in project hale by halestudio.
the class SpatialJoinHandler method partitionInstances.
/**
* @see eu.esdihumboldt.hale.common.align.transformation.function.InstanceHandler#partitionInstances(eu.esdihumboldt.hale.common.instance.model.InstanceCollection,
* java.lang.String,
* eu.esdihumboldt.hale.common.align.transformation.engine.TransformationEngine,
* com.google.common.collect.ListMultimap, java.util.Map,
* eu.esdihumboldt.hale.common.align.transformation.report.TransformationLog)
*/
@Override
public ResourceIterator<FamilyInstance> partitionInstances(InstanceCollection instances, String transformationIdentifier, TransformationEngine engine, ListMultimap<String, ParameterValue> transformationParameters, Map<String, String> executionParameters, TransformationLog log) throws TransformationException {
if (transformationParameters == null || !transformationParameters.containsKey(PARAMETER_SPATIAL_JOIN) || transformationParameters.get(PARAMETER_SPATIAL_JOIN).isEmpty()) {
throw new TransformationException("No join parameter defined");
}
if (services == null) {
throw new IllegalStateException("ServiceProvider must be set before calling partitionInstances");
}
SpatialJoinParameter joinParameter = transformationParameters.get(PARAMETER_SPATIAL_JOIN).get(0).as(SpatialJoinParameter.class);
String validation = joinParameter.validate();
if (validation != null) {
throw new TransformationException("Spatial Join parameter invalid: " + validation);
}
List<TypeEntityDefinition> types = joinParameter.types;
// ChildType -> DirectParentType
int[] directParent = new int[joinParameter.types.size()];
// ChildType -> (ParentType -> Collection<JoinCondition>)
Map<Integer, Multimap<Integer, SpatialJoinCondition>> joinTable = new HashMap<>();
for (SpatialJoinCondition condition : joinParameter.conditions) {
int baseTypeIndex = types.indexOf(AlignmentUtil.getTypeEntity(condition.baseProperty));
int joinTypeIndex = types.indexOf(AlignmentUtil.getTypeEntity(condition.joinProperty));
Multimap<Integer, SpatialJoinCondition> typeTable = joinTable.get(joinTypeIndex);
if (typeTable == null) {
typeTable = ArrayListMultimap.create(2, 2);
joinTable.put(joinTypeIndex, typeTable);
}
typeTable.put(baseTypeIndex, condition);
// update highest type if necessary
if (directParent[joinTypeIndex] < baseTypeIndex) {
directParent[joinTypeIndex] = baseTypeIndex;
}
}
// remember instances of first type to start join afterwards
Collection<InstanceReference> startInstances = new LinkedList<InstanceReference>();
// iterate once over all instances
ResourceIterator<Instance> iterator = instances.iterator();
try {
while (iterator.hasNext()) {
Instance next = iterator.next();
// remember instances of first type
if (next.getDefinition().equals(types.get(0).getDefinition())) {
startInstances.add(instances.getReference(next));
}
}
} finally {
iterator.close();
}
return new SpatialJoinIterator(instances, startInstances, directParent, services, joinTable);
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceReference in project hale by halestudio.
the class StyledInstanceMarker method getStyle.
/**
* Get the style for a given way-point.
*
* @param context the way-point
* @return the style
*/
private Style getStyle(InstanceWaypoint context) {
StyleService ss = PlatformUI.getWorkbench().getService(StyleService.class);
InstanceReference ref = context.getValue();
return ss.getStyle(context.getInstanceType(), ref.getDataSet());
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceReference in project hale by halestudio.
the class TypeStyleHandler method collectTypesFromSelection.
/**
* Collect all type definitions and data sets from the current selection of
* {@link TypeDefinition}s, {@link EntityDefinition}s, {@link Instance}s and
* {@link InstanceReference}s.
*
* @param event the handler execution event
* @return the collected type definitions
*/
public static SetMultimap<DataSet, TypeDefinition> collectTypesFromSelection(ExecutionEvent event) {
SetMultimap<DataSet, TypeDefinition> types = HashMultimap.create();
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
for (Object object : ((IStructuredSelection) selection).toArray()) {
if (object instanceof TypeDefinition) {
TypeDefinition type = (TypeDefinition) object;
if (!types.containsValue(type)) {
DataSet dataSet = findDataSet(type);
types.put(dataSet, type);
}
}
if (object instanceof EntityDefinition) {
EntityDefinition entityDef = (EntityDefinition) object;
if (entityDef.getPropertyPath().isEmpty()) {
DataSet dataSet = (entityDef.getSchemaSpace() == SchemaSpaceID.SOURCE) ? (DataSet.SOURCE) : (DataSet.TRANSFORMED);
types.put(dataSet, entityDef.getType());
}
}
if (object instanceof InstanceReference) {
InstanceService is = HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench().getService(InstanceService.class);
object = is.getInstance((InstanceReference) object);
}
if (object instanceof Instance) {
Instance instance = (Instance) object;
types.put(instance.getDataSet(), instance.getDefinition());
}
}
}
return types;
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceReference in project hale by halestudio.
the class JoinIterator method join.
// Joins all direct children of the given type to currentInstances.
private void join(FamilyInstance[] currentInstances, int currentType) {
// Join all types that are direct children of the last type.
for (int i = currentType + 1; i < parent.length; i++) {
if (parent[i] == currentType) {
// Get join condition for the direct child type.
Multimap<Integer, JoinCondition> joinConditions = joinTable.get(i);
// Collect intersection of conditions. null marks beginning
// in contrast to an empty set.
Set<InstanceReference> possibleInstances = null;
// ParentType -> JoinConditions
for (Map.Entry<Integer, JoinCondition> joinCondition : joinConditions.entries()) {
Collection<Object> currentValues = AlignmentUtil.getValues(currentInstances[joinCondition.getKey()], joinCondition.getValue().baseProperty, true);
if (currentValues == null) {
possibleInstances = Collections.emptySet();
break;
}
// Allow targets with any of the property values.
HashSet<InstanceReference> matches = new HashSet<InstanceReference>();
for (Object currentValue : currentValues) {
Object keyValue = currentValue;
if (valueProcessor != null) {
keyValue = valueProcessor.processValue(currentValue, joinCondition.getValue().baseProperty);
}
matches.addAll(index.get(joinCondition.getValue().joinProperty).get(keyValue));
}
if (possibleInstances == null)
possibleInstances = matches;
else {
// Intersect!
Iterator<InstanceReference> iter = possibleInstances.iterator();
while (iter.hasNext()) {
InstanceReference ref = iter.next();
if (!matches.contains(ref))
iter.remove();
}
}
// Break if set is empty.
if (possibleInstances.isEmpty())
break;
}
if (possibleInstances != null && !possibleInstances.isEmpty()) {
FamilyInstance parent = currentInstances[currentType];
for (InstanceReference ref : possibleInstances) {
FamilyInstance child;
if (ref instanceof ResolvableInstanceReference) {
child = new FamilyInstanceImpl(((ResolvableInstanceReference) ref).resolve());
} else {
child = new FamilyInstanceImpl(instances.getInstance(ref));
}
parent.addChild(child);
currentInstances[i] = child;
join(currentInstances, i);
}
currentInstances[i] = null;
}
}
}
}
Aggregations