use of org.activityinfo.model.type.geo.Extents in project activityinfo by bedatadriven.
the class LeafletReportOverlays method addMarkers.
public Extents addMarkers(List<MapMarker> markers, EventHandler<Event> markerEventHandler) {
Extents extents = Extents.emptyExtents();
for (MapMarker marker : markers) {
markerLayer.addLayer(LeafletMarkerFactory.create(marker, markerEventHandler));
extents.grow(marker.getLat(), marker.getLng());
}
return extents;
}
use of org.activityinfo.model.type.geo.Extents in project activityinfo by bedatadriven.
the class AdminFieldSetPresenter method updateBounds.
private void updateBounds() {
Extents oldBounds = bounds;
bounds = AdminBoundsHelper.calculate(countryBounds, levels, new HasAdminEntityValues() {
@Override
public AdminEntityDTO getAdminEntity(int levelId) {
return level(levelId).getSelection();
}
});
if (!bounds.equals(oldBounds)) {
boundsName = AdminBoundsHelper.name(bounds, levels, this);
fireEvent(new BoundsChangedEvent(bounds, boundsName));
}
}
use of org.activityinfo.model.type.geo.Extents in project activityinfo by bedatadriven.
the class ImportWindow method buildUpdate.
private AdminLevel buildUpdate() {
int nameAttribute = importForm.getNameAttributeIndex();
int codeAttribute = importForm.getCodeAttributeIndex();
List<AdminEntity> entities = Lists.newArrayList();
Map<ImportKey, AdminEntity> entityMap = Maps.newHashMap();
for (int i = 0; i != tableModel.getRowCount(); ++i) {
if (tableModel.getActionAt(i) == ImportAction.IMPORT) {
ImportFeature feature = tableModel.getFeatureAt(i);
String featureName = feature.getAttributeStringValue(nameAttribute);
AdminEntity parent = tableModel.getParent(i);
if (!validateFeature(feature, featureName, parent)) {
continue;
}
if (Strings.isNullOrEmpty(featureName)) {
throw new RuntimeException("Feature " + i + " has an empty name");
}
// we can't have two entities with the same name within a
// given parent. This happens often because secondary exterior rings
// are stored as separate features.
ImportKey key = new ImportKey(parent, featureName);
if (!entityMap.containsKey(key)) {
AdminEntity entity = new AdminEntity();
String truncatedName = featureName;
if (truncatedName.length() > MAX_NAME_LENGTH) {
truncatedName = truncatedName.substring(0, MAX_NAME_LENGTH);
}
entity.setName(truncatedName);
if (codeAttribute != -1) {
entity.setCode(feature.getAttributeStringValue(codeAttribute));
}
Extents bounds = GeoUtils.toBounds(feature.getEnvelope());
entity.setBounds(bounds);
if (importForm.isGeometryImported()) {
entity.setGeometry(feature.getGeometry());
}
if (parentLevel != null) {
entity.setParentId(parent.getId());
}
entities.add(entity);
entityMap.put(key, entity);
} else {
// add this geometry to the existing entity
LOGGER.info("Merging geometry for entity named '" + featureName + "'");
AdminEntity entity = entityMap.get(key);
Envelope bounds = GeoUtils.toEnvelope(entity.getBounds());
bounds.expandToInclude(feature.getEnvelope());
entity.setBounds(GeoUtils.toBounds(bounds));
if (importForm.isGeometryImported()) {
entity.setGeometry(entity.getGeometry().union(feature.getGeometry()));
}
}
}
}
AdminLevel newLevel = new AdminLevel();
newLevel.setName(importForm.getLevelName());
if (parentLevel != null) {
newLevel.setParentId(parentLevel.getId());
}
newLevel.setEntities(entities);
return newLevel;
}
use of org.activityinfo.model.type.geo.Extents in project activityinfo by bedatadriven.
the class FieldScoreMatrix method scoreGeoAreaMatch.
private double scoreGeoAreaMatch(FieldProfile x, FieldProfile y) {
double sumRowMaxes = 0;
int countOfRows = 0;
for (int i = 0; i < x.getNumRows(); i++) {
Extents rowExtents = x.getExtents(i);
if (rowExtents != null) {
sumRowMaxes += findScoreOfBestMatch(rowExtents, y);
countOfRows++;
}
}
if (countOfRows == 0) {
return 0;
} else {
return sumRowMaxes / (double) countOfRows;
}
}
use of org.activityinfo.model.type.geo.Extents in project activityinfo by bedatadriven.
the class GeoAreaFieldBinding method extractFieldData.
@Override
public AdminEntityDTO[] extractFieldData(AdminEntityDTO[] dataArray, ColumnSet columnSet) {
ColumnView xmin = columnSet.getColumnView(XMIN_COLUMN.asExpression());
ColumnView xmax = columnSet.getColumnView(XMAX_COLUMN.asExpression());
ColumnView ymin = columnSet.getColumnView(YMIN_COLUMN.asExpression());
ColumnView ymax = columnSet.getColumnView(YMAX_COLUMN.asExpression());
for (int i = 0; i < columnSet.getNumRows(); i++) {
if (allDefinedForRow(xmin, xmax, ymin, ymax, i)) {
Extents bounds = Extents.create(xmin.getDouble(i), ymin.getDouble(i), xmax.getDouble(i), ymax.getDouble(i));
dataArray[i].setBounds(bounds);
}
}
return dataArray;
}
Aggregations