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