Search in sources :

Example 1 with SpatialJoinCondition

use of eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter.SpatialJoinCondition in project hale by halestudio.

the class SpatialJoinParameterPage method getConfiguration.

/**
 * @see eu.esdihumboldt.hale.ui.function.generic.pages.ParameterPage#getConfiguration()
 */
@Override
public ListMultimap<String, ParameterValue> getConfiguration() {
    ListMultimap<String, ParameterValue> result = ArrayListMultimap.create(1, 1);
    Set<SpatialJoinCondition> conditions = new HashSet<>();
    for (ConditionPage page : pages) {
        conditions.addAll(page.conditions);
    }
    SpatialJoinParameter param = new SpatialJoinParameter(types, conditions);
    result.put(PARAMETER_SPATIAL_JOIN, new ParameterValue(new ComplexValue(param)));
    return result;
}
Also used : ComplexValue(eu.esdihumboldt.hale.common.core.io.impl.ComplexValue) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) SpatialJoinCondition(eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter.SpatialJoinCondition) SpatialJoinParameter(eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter) HashSet(java.util.HashSet)

Example 2 with SpatialJoinCondition

use of eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter.SpatialJoinCondition 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);
}
Also used : TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) HashMap(java.util.HashMap) SpatialJoinCondition(eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter.SpatialJoinCondition) FamilyInstance(eu.esdihumboldt.hale.common.instance.model.FamilyInstance) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) LinkedList(java.util.LinkedList) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ListMultimap(com.google.common.collect.ListMultimap) Multimap(com.google.common.collect.Multimap) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) ResolvableInstanceReference(eu.esdihumboldt.hale.common.instance.model.ResolvableInstanceReference) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference)

Example 3 with SpatialJoinCondition

use of eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter.SpatialJoinCondition in project hale by halestudio.

the class SpatialJoinParameterPage method onShowPage.

/**
 * @see eu.esdihumboldt.hale.ui.HaleWizardPage#onShowPage(boolean)
 */
@Override
protected void onShowPage(boolean firstShow) {
    super.onShowPage(firstShow);
    Cell cell = getWizard().getUnfinishedCell();
    List<? extends Entity> sourceEntities = cell.getSource().get(JOIN_TYPES);
    List<TypeEntityDefinition> types = new ArrayList<TypeEntityDefinition>();
    Iterator<? extends Entity> iter = sourceEntities.iterator();
    while (iter.hasNext()) types.add(AlignmentUtil.getTypeEntity(iter.next().getDefinition()));
    if (sameTypes(this.types, types))
        return;
    if (containsDuplicateType(types)) {
        setPageComplete(false);
        setErrorMessage("The selected source types contain duplicates.");
        this.types.clear();
        table.setInput(null);
        return;
    } else {
        setErrorMessage(null);
    }
    SpatialJoinParameter initialValue = null;
    if (firstShow && !getInitialValues().isEmpty()) {
        initialValue = getInitialValues().get(PARAMETER_SPATIAL_JOIN).get(0).as(SpatialJoinParameter.class);
        if (initialValue != null && (initialValue.validate() != null || !sameTypes(types, initialValue.types)))
            initialValue = null;
    }
    for (ConditionPage page : pages) page.dispose();
    pages.clear();
    if (initialValue != null) {
        // use ordering of the initial value (needs to be modifiable)
        types = new ArrayList<>(initialValue.types);
    }
    this.types = types;
    if (table != null)
        table.setInput(types);
    for (int i = 1; i < types.size(); i++) {
        ConditionPage conditionPage = new ConditionPage(i);
        conditionPage.setWizard(getWizard());
        pages.add(conditionPage);
    }
    if (initialValue != null) {
        // add initial conditions
        for (SpatialJoinCondition condition : initialValue.conditions) {
            TypeEntityDefinition joinType = AlignmentUtil.getTypeEntity(condition.joinProperty);
            int typeIndex = types.indexOf(joinType);
            int pageIndex = typeIndex - 1;
            pages.get(pageIndex).conditions.add(condition);
            pages.get(pageIndex).updateCompletionStatus();
        }
    }
    // order is always valid, will trigger updateButtons
    setPageComplete(true);
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) SpatialJoinParameter(eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter) SpatialJoinCondition(eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter.SpatialJoinCondition) ArrayList(java.util.ArrayList) ViewerCell(org.eclipse.jface.viewers.ViewerCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Point(org.eclipse.swt.graphics.Point)

Example 4 with SpatialJoinCondition

use of eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter.SpatialJoinCondition in project hale by halestudio.

the class SpatialJoinParameterPage method createJoinParameter.

/**
 * Creates a join parameter for the types up to <code>upToIndex</code>.
 *
 * @param upToIndex the type index up to which the parameter should be
 *            created for
 * @return the current join parameter up to the specified index
 */
private SpatialJoinParameter createJoinParameter(int upToIndex) {
    Set<SpatialJoinCondition> conditions = new HashSet<>();
    for (int i = 0; i < upToIndex; i++) conditions.addAll(pages.get(i).conditions);
    SpatialJoinParameter param = new SpatialJoinParameter(types.subList(0, upToIndex + 1), conditions);
    return param;
}
Also used : SpatialJoinCondition(eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter.SpatialJoinCondition) SpatialJoinParameter(eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter) Point(org.eclipse.swt.graphics.Point) HashSet(java.util.HashSet)

Aggregations

SpatialJoinCondition (eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter.SpatialJoinCondition)4 SpatialJoinParameter (eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter)3 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)2 HashSet (java.util.HashSet)2 Point (org.eclipse.swt.graphics.Point)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ListMultimap (com.google.common.collect.ListMultimap)1 Multimap (com.google.common.collect.Multimap)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)1 TransformationException (eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)1 ComplexValue (eu.esdihumboldt.hale.common.core.io.impl.ComplexValue)1 FamilyInstance (eu.esdihumboldt.hale.common.instance.model.FamilyInstance)1 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)1 InstanceReference (eu.esdihumboldt.hale.common.instance.model.InstanceReference)1 ResolvableInstanceReference (eu.esdihumboldt.hale.common.instance.model.ResolvableInstanceReference)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 ViewerCell (org.eclipse.jface.viewers.ViewerCell)1