Search in sources :

Example 1 with Extents

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;
}
Also used : MapMarker(org.activityinfo.legacy.shared.reports.content.MapMarker) Extents(org.activityinfo.model.type.geo.Extents)

Example 2 with 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));
    }
}
Also used : HasAdminEntityValues(org.activityinfo.legacy.shared.model.HasAdminEntityValues) Extents(org.activityinfo.model.type.geo.Extents)

Example 3 with Extents

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;
}
Also used : AdminEntity(org.activityinfo.geoadmin.model.AdminEntity) AdminLevel(org.activityinfo.geoadmin.model.AdminLevel) Extents(org.activityinfo.model.type.geo.Extents) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 4 with Extents

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;
    }
}
Also used : Extents(org.activityinfo.model.type.geo.Extents)

Example 5 with Extents

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;
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) Extents(org.activityinfo.model.type.geo.Extents)

Aggregations

Extents (org.activityinfo.model.type.geo.Extents)16 TileBaseMap (org.activityinfo.legacy.shared.model.TileBaseMap)5 Test (org.junit.Test)5 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)3 BaseMap (org.activityinfo.legacy.shared.model.BaseMap)2 IconMapLayer (org.activityinfo.legacy.shared.reports.model.layers.IconMapLayer)2 Envelope (com.vividsolutions.jts.geom.Envelope)1 ResultSet (java.sql.ResultSet)1 AdminEntity (org.activityinfo.geoadmin.model.AdminEntity)1 AdminLevel (org.activityinfo.geoadmin.model.AdminLevel)1 DimensionType (org.activityinfo.legacy.shared.command.DimensionType)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)1 AdminEntityDTO (org.activityinfo.legacy.shared.model.AdminEntityDTO)1 HasAdminEntityValues (org.activityinfo.legacy.shared.model.HasAdminEntityValues)1 IndicatorDTO (org.activityinfo.legacy.shared.model.IndicatorDTO)1 GoogleBaseMap (org.activityinfo.legacy.shared.reports.content.GoogleBaseMap)1 MapContent (org.activityinfo.legacy.shared.reports.content.MapContent)1 MapMarker (org.activityinfo.legacy.shared.reports.content.MapMarker)1 Point (org.activityinfo.legacy.shared.reports.content.Point)1