Search in sources :

Example 1 with PointValue

use of org.activityinfo.legacy.shared.reports.model.PointValue in project activityinfo by bedatadriven.

the class BubbleLayerGenerator method generate.

@Override
public void generate(TiledMap map, MapContent content) {
    // define our symbol scaling
    RadiiCalculator radiiCalculator;
    if (layer.getScaling() == ScalingType.None || layer.getMinRadius() == layer.getMaxRadius()) {
        radiiCalculator = new FixedRadiiCalculator(layer.getMinRadius());
    } else if (layer.getScaling() == ScalingType.Graduated) {
        radiiCalculator = new GsLogCalculator(layer.getMinRadius(), layer.getMaxRadius());
    } else {
        radiiCalculator = new FixedRadiiCalculator(layer.getMinRadius());
    }
    BubbleIntersectionCalculator intersectionCalculator = new BubbleIntersectionCalculator(layer.getMaxRadius());
    Clusterer clusterer = ClustererFactory.fromClustering(layer.getClustering(), radiiCalculator, intersectionCalculator);
    // create the list of input point values
    List<PointValue> points = new ArrayList<PointValue>();
    List<PointValue> unmapped = new ArrayList<PointValue>();
    generatePoints(sites, map, layer, clusterer, points, unmapped);
    // Cluster points by the clustering algorithm set in the layer
    List<Cluster> clusters = clusterer.cluster(map, points);
    // add unmapped sites
    for (PointValue pv : unmapped) {
        content.getUnmappedSites().add(pv.getSite().getId());
    }
    BubbleLayerLegend legend = new BubbleLayerLegend();
    legend.setDefinition(layer);
    // create the markers
    List<BubbleMapMarker> markers = new ArrayList<BubbleMapMarker>();
    for (Cluster cluster : clusters) {
        Point px = cluster.getPoint();
        AiLatLng latlng = map.fromPixelToLatLng(px);
        BubbleMapMarker marker = new BubbleMapMarker();
        for (PointValue pv : cluster.getPointValues()) {
            marker.getSiteIds().add(pv.getSite().getId());
        }
        marker.setX(px.getX());
        marker.setY(px.getY());
        marker.setValue(cluster.sumValues());
        marker.setRadius((int) cluster.getRadius());
        marker.setLat(latlng.getLat());
        marker.setLng(latlng.getLng());
        marker.setAlpha(layer.getAlpha());
        marker.setTitle(formatTitle(cluster));
        marker.setIndicatorIds(new HashSet<Integer>(layer.getIndicatorIds()));
        marker.setClusterAmount(cluster.getPointValues().size());
        marker.setClustering(layer.getClustering());
        marker.setColor(layer.getBubbleColor());
        if (marker.getValue() < legend.getMinValue()) {
            legend.setMinValue(marker.getValue());
        }
        if (marker.getValue() > legend.getMaxValue()) {
            legend.setMaxValue(marker.getValue());
        }
        markers.add(marker);
    }
    // sort order by symbol radius descending
    // (this assures that smaller symbols are drawn on
    // top of larger ones)
    Collections.sort(markers, new Comparator<MapMarker>() {

        @Override
        public int compare(MapMarker o1, MapMarker o2) {
            if (o1.getSize() > o2.getSize()) {
                return -1;
            } else if (o1.getSize() < o2.getSize()) {
                return 1;
            }
            return 0;
        }
    });
    // number markers if applicable
    if (layer.getLabelSequence() != null) {
        numberMarkers(markers);
    }
    content.addLegend(legend);
    content.getMarkers().addAll(markers);
}
Also used : PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) Clusterer(org.activityinfo.server.report.generator.map.cluster.Clusterer) AiLatLng(org.activityinfo.model.type.geo.AiLatLng)

Example 2 with PointValue

use of org.activityinfo.legacy.shared.reports.model.PointValue in project activityinfo by bedatadriven.

the class AdminLevelClusterer method cluster.

@Override
public List<Cluster> cluster(TiledMap map, List<PointValue> points) {
    // admin entity id -> cluster
    Map<Integer, Cluster> adminClusters = new HashMap<Integer, Cluster>();
    for (PointValue pv : points) {
        AdminEntityDTO entity = getAdminEntityId(pv);
        if (entity != null) {
            Cluster cluster = adminClusters.get(entity.getId());
            if (cluster == null) {
                cluster = new Cluster(pv);
                cluster.setPoint(adminCenter(map, entity));
                cluster.setTitle(entity.getName());
                adminClusters.put(entity.getId(), cluster);
            } else {
                cluster.addPointValue(pv);
            }
        }
    }
    ArrayList<Cluster> clusters = Lists.newArrayList();
    // update centers of clusters based on points, if any
    for (Cluster cluster : adminClusters.values()) {
        updateCenter(cluster);
        if (cluster.hasPoint()) {
            clusters.add(cluster);
        }
    }
    radiiCalculator.calculate(clusters);
    return clusters;
}
Also used : HashMap(java.util.HashMap) PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) AdminEntityDTO(org.activityinfo.legacy.shared.model.AdminEntityDTO)

Example 3 with PointValue

use of org.activityinfo.legacy.shared.reports.model.PointValue in project activityinfo by bedatadriven.

the class Cluster method bboxCenter.

/**
 * @return The weighted centroid of the cluster
 */
public Point bboxCenter() {
    int minX = Integer.MAX_VALUE;
    int minY = Integer.MAX_VALUE;
    int maxX = Integer.MIN_VALUE;
    int maxY = Integer.MIN_VALUE;
    for (PointValue pointValue : pointValues) {
        Point p = pointValue.getPx();
        if (p.getX() < minX) {
            minX = p.getX();
        }
        if (p.getY() < minY) {
            minY = p.getY();
        }
        if (p.getX() > maxX) {
            maxX = p.getX();
        }
        if (p.getY() > maxY) {
            maxY = p.getY();
        }
    }
    return new Point((minX + maxX) / 2, (minY + maxY) / 2);
}
Also used : PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) Point(org.activityinfo.legacy.shared.reports.content.Point) Point(org.activityinfo.legacy.shared.reports.content.Point)

Example 4 with PointValue

use of org.activityinfo.legacy.shared.reports.model.PointValue in project activityinfo by bedatadriven.

the class NullClusterer method cluster.

/**
 * Maps each Point to a cluster, not performing an actual
 * clued.report.model.clustering.Clusteristering algorithm whatsoever
 *
 * @see org.activityinfo.sharng#cluster(java.util.List,
 * org.activityinfo.server.report.generator.map.RadiiCalculator)
 */
@Override
public List<Cluster> cluster(TiledMap map, List<PointValue> points) {
    List<Cluster> clusters = new ArrayList<Cluster>();
    // cluster
    for (PointValue point : points) {
        clusters.add(new Cluster(point));
    }
    radiiCalculator.calculate(clusters);
    return clusters;
}
Also used : PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) ArrayList(java.util.ArrayList)

Example 5 with PointValue

use of org.activityinfo.legacy.shared.reports.model.PointValue in project activityinfo by bedatadriven.

the class IconLayerGenerator method createMarkersFrom.

private void createMarkersFrom(List<Cluster> clusters, TiledMap map, MapContent content) {
    for (Cluster cluster : clusters) {
        IconMapMarker marker = new IconMapMarker();
        marker.setX(cluster.getPoint().getX());
        marker.setY(cluster.getPoint().getY());
        AiLatLng latlng = map.fromPixelToLatLng(cluster.getPoint());
        marker.setLat(latlng.getLat());
        marker.setLng(latlng.getLng());
        marker.setTitle(formatTitle(cluster));
        marker.setIcon(icon);
        marker.setIndicatorId(layer.getIndicatorIds().get(0));
        for (PointValue pv : cluster.getPointValues()) {
            marker.getSiteIds().add(pv.getSite().getId());
        }
        content.getMarkers().add(marker);
    }
}
Also used : PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) IconMapMarker(org.activityinfo.legacy.shared.reports.content.IconMapMarker) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) AiLatLng(org.activityinfo.model.type.geo.AiLatLng)

Aggregations

PointValue (org.activityinfo.legacy.shared.reports.model.PointValue)15 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)7 Cluster (org.activityinfo.server.report.generator.map.cluster.Cluster)7 ArrayList (java.util.ArrayList)6 Point (org.activityinfo.legacy.shared.reports.content.Point)6 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)5 MapSymbol (org.activityinfo.legacy.shared.reports.model.MapSymbol)3 Clusterer (org.activityinfo.server.report.generator.map.cluster.Clusterer)3 MarkerGraph (org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph)3 Test (org.junit.Test)3 BubbleFitnessFunctor (org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor)2 GeneticSolver (org.activityinfo.server.report.generator.map.cluster.genetic.GeneticSolver)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1 List (java.util.List)1 AdminEntityDTO (org.activityinfo.legacy.shared.model.AdminEntityDTO)1 IconLayerLegend (org.activityinfo.legacy.shared.reports.content.IconLayerLegend)1