Search in sources :

Example 11 with AdminEntity

use of org.activityinfo.geoadmin.model.AdminEntity in project activityinfo by bedatadriven.

the class LocationImportWindow method doImportSql.

private void doImportSql() throws IOException {
    int nameIndex = importForm.getNameAttributeIndex();
    int codeIndex = importForm.getCodeAttributeIndex();
    File locationsFile = File.createTempFile("location", ".sql");
    try (FileWriter writer = new FileWriter(locationsFile)) {
        writer.append("BEGIN;\n");
        writer.append("INSERT INTO location (LocationID, LocationTypeID, Name, Axe, X, Y, timeEdited) VALUES");
        boolean needsComma = false;
        for (LocationFeature location : locations) {
            Point point = location.getPoint();
            writer.append(needsComma ? ",\n" : "\n");
            writer.append(String.format("(%d, %d, %s, %s, %f, %f, %d)", location.getId(), locationTypeId, Sql.quote(truncate(location.getFeature().getAttributeStringValue(nameIndex))), Sql.quote(truncate(location.getFeature().getAttributeStringValue(codeIndex))), point.getX(), point.getY(), new Date().getTime()));
            needsComma = true;
        }
        writer.append(";\n");
        writer.append("INSERT INTO locationadminlink (LocationID, AdminEntityID) VALUES");
        needsComma = false;
        for (LocationFeature location : locations) {
            for (AdminEntity entity : location.getEntities().values()) {
                writer.append(needsComma ? "\n," : "\n");
                writer.append(String.format("(%d, %d)", location.getId(), entity.getId()));
                needsComma = true;
            }
        }
        writer.append(";");
        writer.append("COMMIT;\n");
    }
    System.out.println("Wrote to " + locationsFile.getAbsolutePath());
}
Also used : AdminEntity(org.activityinfo.geoadmin.model.AdminEntity) FileWriter(java.io.FileWriter) Point(com.vividsolutions.jts.geom.Point) File(java.io.File) Point(com.vividsolutions.jts.geom.Point) Date(java.util.Date)

Example 12 with AdminEntity

use of org.activityinfo.geoadmin.model.AdminEntity in project activityinfo by bedatadriven.

the class ParentGuesser method findBestParent.

public static AdminEntity findBestParent(ImportFeature feature, Collection<AdminEntity> spatialMatches) {
    double bestScore = MIN_SCORE;
    AdminEntity bestParent = null;
    for (AdminEntity parent : spatialMatches) {
        double score = scoreParent(feature, parent);
        if (score > bestScore) {
            bestScore = score;
            bestParent = parent;
        }
    }
    return bestParent;
}
Also used : AdminEntity(org.activityinfo.geoadmin.model.AdminEntity)

Example 13 with AdminEntity

use of org.activityinfo.geoadmin.model.AdminEntity in project activityinfo by bedatadriven.

the class LocationAdminMatcher method findBestParent.

public AdminEntity findBestParent(ImportFeature feature, Collection<AdminEntity> spatialMatches) {
    double bestScore = 0;
    AdminEntity bestParent = null;
    for (AdminEntity parent : spatialMatches) {
        double score = scoreParent(feature, parent);
        if (score > bestScore) {
            bestScore = score;
            bestParent = parent;
        }
    }
    return bestParent;
}
Also used : AdminEntity(org.activityinfo.geoadmin.model.AdminEntity)

Example 14 with AdminEntity

use of org.activityinfo.geoadmin.model.AdminEntity in project activityinfo by bedatadriven.

the class LocationImportForm method guessLevelColumns.

public void guessLevelColumns(GeoAdminClient client) {
    for (AdminLevel level : levelCombos.keySet()) {
        List<AdminEntity> entities = client.getAdminEntities(level);
        setLevelAttribute(level, new ColumnGuesser().forEntities(entities).findBest(source));
    }
}
Also used : AdminEntity(org.activityinfo.geoadmin.model.AdminEntity) AdminLevel(org.activityinfo.geoadmin.model.AdminLevel) ColumnGuesser(org.activityinfo.geoadmin.ColumnGuesser)

Aggregations

AdminEntity (org.activityinfo.geoadmin.model.AdminEntity)14 AdminLevel (org.activityinfo.geoadmin.model.AdminLevel)5 Point (com.vividsolutions.jts.geom.Point)3 Predicate (com.google.common.base.Predicate)1 Envelope (com.vividsolutions.jts.geom.Envelope)1 Component (java.awt.Component)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 Date (java.util.Date)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 ColumnGuesser (org.activityinfo.geoadmin.ColumnGuesser)1 AdminLevelNode (org.activityinfo.geoadmin.model.AdminLevelNode)1 NewLocation (org.activityinfo.geoadmin.model.NewLocation)1 Extents (org.activityinfo.model.type.geo.Extents)1