Search in sources :

Example 1 with Point

use of org.activityinfo.shared.report.content.Point in project activityinfo by bedatadriven.

the class GeometryProjecter method transformCoordinates.

@Override
protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) {
    int n = coords.size();
    Coordinate[] outCoords = new Coordinate[n];
    int outIndex = 0;
    for (int i = 0; i != n; ++i) {
        Point px = map.fromLatLngToPixel(new AiLatLng(coords.getY(i), coords.getX(i)));
        outCoords[outIndex] = new Coordinate(px.getDoubleX(), px.getDoubleY());
        outIndex++;
    }
    return new CoordinateArraySequence(Arrays.copyOf(outCoords, outIndex));
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) Point(org.activityinfo.shared.report.content.Point) Point(org.activityinfo.shared.report.content.Point) CoordinateArraySequence(com.vividsolutions.jts.geom.impl.CoordinateArraySequence)

Example 2 with Point

use of org.activityinfo.shared.report.content.Point 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 : BubbleLayerLegend(org.activityinfo.shared.report.content.BubbleLayerLegend) MapMarker(org.activityinfo.shared.report.content.MapMarker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) PointValue(org.activityinfo.shared.report.model.PointValue) ArrayList(java.util.ArrayList) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) Point(org.activityinfo.shared.report.content.Point) Clusterer(org.activityinfo.server.report.generator.map.cluster.Clusterer) AiLatLng(org.activityinfo.shared.report.content.AiLatLng)

Example 3 with Point

use of org.activityinfo.shared.report.content.Point in project activityinfo by bedatadriven.

the class PiechartLayerGenerator method generatePoints.

public void generatePoints(TiledMap map, PiechartMapLayer layer, Clusterer clusterer, List<PointValue> mapped, List<PointValue> unmapped) {
    for (SiteDTO site : sites) {
        if (hasValue(site, layer.getIndicatorIds())) {
            Point px = null;
            if (site.hasLatLong()) {
                px = map.fromLatLngToPixel(new AiLatLng(site.getLatitude(), site.getLongitude()));
            }
            Double value = getValue(site, layer.getIndicatorIds());
            if (value != null && value != 0) {
                PointValue pv = new PointValue(site, new MapSymbol(), value, px);
                calulateSlices(pv, site);
                if (clusterer.isMapped(site)) {
                    mapped.add(pv);
                } else {
                    unmapped.add(pv);
                }
            }
        }
    }
}
Also used : PointValue(org.activityinfo.shared.report.model.PointValue) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) SiteDTO(org.activityinfo.shared.dto.SiteDTO) Point(org.activityinfo.shared.report.content.Point) MapSymbol(org.activityinfo.shared.report.model.MapSymbol)

Example 4 with Point

use of org.activityinfo.shared.report.content.Point 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.shared.report.model.PointValue) Point(org.activityinfo.shared.report.content.Point) Point(org.activityinfo.shared.report.content.Point)

Example 5 with Point

use of org.activityinfo.shared.report.content.Point in project activityinfo by bedatadriven.

the class KMeans method cluster.

public static List<Cluster> cluster(List<MarkerGraph.Node> nodes, int numClusters) {
    List<Cluster> clusters = new ArrayList<Cluster>(numClusters);
    // sanity check
    if (numClusters > nodes.size() || nodes.size() == 0) {
        throw new IllegalArgumentException();
    }
    // randomize
    Collections.shuffle(nodes);
    // choose random centers
    Point[] centers = new Point[numClusters];
    for (int i = 0; i != numClusters; ++i) {
        centers[i] = nodes.get(i).getPoint();
    }
    // assign initial cluster membership
    int[] membership = new int[nodes.size()];
    assignClosest(nodes, centers, membership);
    // execute k-means algorithm until we achieve convergence
    boolean changed;
    do {
        computeCenters(nodes, membership, centers);
        changed = assignClosest(nodes, centers, membership);
    } while (changed);
    // create clusters
    for (int i = 0; i != numClusters; ++i) {
        clusters.add(new Cluster(centers[i]));
    }
    for (int j = 0; j != nodes.size(); ++j) {
        (clusters.get(membership[j])).addNode(nodes.get(j));
    }
    return clusters;
}
Also used : ArrayList(java.util.ArrayList) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) Point(org.activityinfo.shared.report.content.Point) Point(org.activityinfo.shared.report.content.Point)

Aggregations

Point (org.activityinfo.shared.report.content.Point)21 AiLatLng (org.activityinfo.shared.report.content.AiLatLng)10 PointValue (org.activityinfo.shared.report.model.PointValue)10 ArrayList (java.util.ArrayList)7 Cluster (org.activityinfo.server.report.generator.map.cluster.Cluster)6 Test (org.junit.Test)6 SiteDTO (org.activityinfo.shared.dto.SiteDTO)4 Clusterer (org.activityinfo.server.report.generator.map.cluster.Clusterer)3 MarkerGraph (org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph)2 BubbleMapMarker (org.activityinfo.shared.report.content.BubbleMapMarker)2 MapSymbol (org.activityinfo.shared.report.model.MapSymbol)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 CoordinateArraySequence (com.vividsolutions.jts.geom.impl.CoordinateArraySequence)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 List (java.util.List)1 BubbleFitnessFunctor (org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor)1 GeneticSolver (org.activityinfo.server.report.generator.map.cluster.genetic.GeneticSolver)1 IntersectionCalculator (org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph.IntersectionCalculator)1 Node (org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph.Node)1