Search in sources :

Example 1 with FieldProfile

use of org.activityinfo.geoadmin.merge2.view.profile.FieldProfile in project activityinfo by bedatadriven.

the class FormMappingBuilder method build.

public Observable<List<FieldMapping>> build() {
    // the source to the target field
    for (FieldProfile targetField : target.getFields()) {
        if (targetField.getNode().isRoot())
            if (SimpleFieldMapping.isSimple(targetField)) {
                buildSimpleMapping(targetField);
            }
    }
    // Add mappings for ReferenceFields, for which we have to perform look ups
    for (FormTree.Node targetNode : target.getFormTree().getRootFields()) {
        if (targetNode.isReference()) {
            buildReferenceMapping(targetNode.getField());
        }
    }
    // Add mapping for geography, IIF source and target have exactly one GeoArea
    Set<FormField> targetGeoFields = findGeoFields(target.getFormTree());
    Set<FormField> sourceGeoFields = findGeoFields(source.getFormTree());
    if (targetGeoFields.size() == 1 && sourceGeoFields.size() == 1) {
        FormField sourceField = Iterables.getOnlyElement(sourceGeoFields);
        FormField targetField = Iterables.getOnlyElement(targetGeoFields);
        mappings.add(Observable.<FieldMapping>just(new GeoAreaFieldMapping(source.getField(sourceField.getId()), targetField)));
    }
    return Observable.flatten(SynchronousScheduler.INSTANCE, mappings);
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) FieldProfile(org.activityinfo.geoadmin.merge2.view.profile.FieldProfile) FormField(org.activityinfo.model.form.FormField)

Example 2 with FieldProfile

use of org.activityinfo.geoadmin.merge2.view.profile.FieldProfile in project activityinfo by bedatadriven.

the class FieldScoreMatrix method calculateScore.

private double calculateScore(int i, int j) {
    FieldProfile x = sourceColumns.get(i);
    FieldProfile y = targetColumns.get(j);
    if (x.isText() && y.isText()) {
        return scoreTextColumnMatch(x, y);
    } else if (x.isGeoArea() && y.isGeoArea()) {
        return scoreGeoAreaMatch(x, y);
    } else {
        return 0;
    }
}
Also used : FieldProfile(org.activityinfo.geoadmin.merge2.view.profile.FieldProfile)

Example 3 with FieldProfile

use of org.activityinfo.geoadmin.merge2.view.profile.FieldProfile in project activityinfo by bedatadriven.

the class LookupDialogTableModel method getValueAt.

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    if (columnIndex == SCORE_COLUMN) {
        return scoreFormat.format(scores[rowIndex]);
    } else {
        int targetRow = targetCandidateRows.get(rowIndex);
        FieldProfile targetField = targetKeyFields.get(columnIndex - 1);
        return targetField.getView().getString(targetRow);
    }
}
Also used : FieldProfile(org.activityinfo.geoadmin.merge2.view.profile.FieldProfile)

Example 4 with FieldProfile

use of org.activityinfo.geoadmin.merge2.view.profile.FieldProfile in project activityinfo by bedatadriven.

the class LookupDialog method buildReferenceMatch.

/**
 * Build a ReferenceMatch that can be stored as part of the model.
 * since this will form part of the model "state" it cannot depend
 * on computed values in any way, so we need to map our row indices and SourceKeys
 * back to the original ids.
 *
 * @param candidateIndex the index within the list of candidate target matches (from LookupGraph)
 */
private ReferenceMatch buildReferenceMatch(int candidateIndex) {
    ResourceId targetId = tableModel.getTargetInstanceId(candidateIndex);
    Map<FieldPath, String> keyMap = new HashMap<>();
    java.util.List<FieldProfile> keyFields = lookupTable.getSourceKeyFields();
    for (int i = 0; i < keyFields.size(); i++) {
        keyMap.put(keyFields.get(i).getPath(), sourceKey.get(i));
    }
    return new ReferenceMatch(keyMap, targetId);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) HashMap(java.util.HashMap) FieldPath(org.activityinfo.model.formTree.FieldPath) FieldProfile(org.activityinfo.geoadmin.merge2.view.profile.FieldProfile) ReferenceMatch(org.activityinfo.geoadmin.merge2.model.ReferenceMatch)

Example 5 with FieldProfile

use of org.activityinfo.geoadmin.merge2.view.profile.FieldProfile in project activityinfo by bedatadriven.

the class ImportView method updateGeometry.

private void updateGeometry(GeoAdminClient client, Map<ResourceId, ResourceId> idMap) throws IOException {
    FeatureSourceStorageProvider catalog = new FeatureSourceStorageProvider();
    FeatureSourceStorage formStorage = (FeatureSourceStorage) catalog.getForm(getModel().getSourceFormId().get()).get();
    ResourceId targetFormId = getModel().getTargetFormId().get();
    FieldProfile targetField = getTargetProfile().get().getGeometryField();
    if (targetField == null) {
        System.err.println("No geometry field to update.");
        return;
    }
    int sourceIndex = formStorage.getGeometryAttributeIndex();
    if (sourceIndex == -1) {
        System.err.println("No source geometry field.");
        return;
    }
    SimpleFeatureSource featureSource = formStorage.getFeatureSource();
    GeometryType geometryType = (GeometryType) featureSource.getSchema().getDescriptor(sourceIndex).getType();
    GeometryConverter converter = new GeometryConverter(geometryType);
    SimpleFeatureIterator it = featureSource.getFeatures().features();
    while (it.hasNext()) {
        SimpleFeature feature = it.next();
        ResourceId sourceId = ResourceId.valueOf(feature.getID());
        ResourceId targetId = idMap.get(sourceId);
        if (targetId != null) {
            Geometry geometry = converter.toWgs84(feature.getAttribute(sourceIndex));
            System.out.print("Updating geometry for " + targetId + " [" + geometry.getGeometryType() + "] ... ");
            try {
                client.updateGeometry(targetFormId, targetId, targetField.getId(), geometry);
                System.out.println("OK");
            } catch (Exception e) {
                System.out.println("ERROR: " + e.getMessage());
            }
        }
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FeatureSourceStorage(org.activityinfo.geoadmin.source.FeatureSourceStorage) GeometryType(org.opengis.feature.type.GeometryType) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) ResourceId(org.activityinfo.model.resource.ResourceId) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) FieldProfile(org.activityinfo.geoadmin.merge2.view.profile.FieldProfile) GeometryConverter(org.activityinfo.geoadmin.source.GeometryConverter) FeatureSourceStorageProvider(org.activityinfo.geoadmin.source.FeatureSourceStorageProvider) SimpleFeature(org.opengis.feature.simple.SimpleFeature) IOException(java.io.IOException)

Aggregations

FieldProfile (org.activityinfo.geoadmin.merge2.view.profile.FieldProfile)7 FieldPath (org.activityinfo.model.formTree.FieldPath)2 ResourceId (org.activityinfo.model.resource.ResourceId)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ScoreMatrix (org.activityinfo.geoadmin.match.ScoreMatrix)1 ReferenceMatch (org.activityinfo.geoadmin.merge2.model.ReferenceMatch)1 FeatureSourceStorage (org.activityinfo.geoadmin.source.FeatureSourceStorage)1 FeatureSourceStorageProvider (org.activityinfo.geoadmin.source.FeatureSourceStorageProvider)1 GeometryConverter (org.activityinfo.geoadmin.source.GeometryConverter)1 FormField (org.activityinfo.model.form.FormField)1 FormTree (org.activityinfo.model.formTree.FormTree)1 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)1 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 GeometryType (org.opengis.feature.type.GeometryType)1