Search in sources :

Example 6 with PointValue

use of org.activityinfo.legacy.shared.reports.model.PointValue 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.legacy.shared.reports.model.PointValue) AiLatLng(org.activityinfo.model.type.geo.AiLatLng) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) MapSymbol(org.activityinfo.legacy.shared.reports.model.MapSymbol)

Example 7 with PointValue

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

the class CoincidentPointsClusterTest method testRealData.

@Test
public void testRealData() throws Exception {
    // Define projection for the test case
    TiledMap map = new TiledMap(492, 690, new AiLatLng(2.293492496, 30.538372993), 9);
    // Read data
    BufferedReader in = new BufferedReader(new InputStreamReader(GraphTest.class.getResourceAsStream("/distribscolaire-points.csv")));
    double originalSum = 0;
    List<PointValue> points = new ArrayList<PointValue>();
    while (in.ready()) {
        String line = in.readLine();
        String[] columns = line.split(",");
        double lat = Double.parseDouble(columns[0]);
        double lng = Double.parseDouble(columns[1]);
        PointValue pv = new PointValue();
        pv.setPx(map.fromLatLngToPixel(new AiLatLng(lat, lng)));
        pv.setValue(Double.parseDouble(columns[2]));
        pv.setSymbol(new MapSymbol());
        pv.setSite(new SiteDTO());
        originalSum += pv.getValue();
        points.add(pv);
    }
    // Now build the graph
    MarkerGraph graph = new MarkerGraph(points, new BubbleIntersectionCalculator(15));
    // make sure nothing was lost in the merging of coincident points
    double nodeSum = 0;
    for (MarkerGraph.Node node : graph.getNodes()) {
        nodeSum += node.getPointValue().getValue();
    }
    Assert.assertEquals("values after construction of graph", originalSum, nodeSum, 0.001);
    saveGraphImage("clusterTest2", graph, 15);
    GeneticSolver solver = new GeneticSolver();
    List<Cluster> clusters = solver.solve(graph, new GsLogCalculator(5, 15), new BubbleFitnessFunctor(), UpperBoundsCalculator.calculate(graph, new FixedRadiiCalculator(5)));
    // check to make sure all values were included
    double sumAfterClustering = 0;
    for (Cluster cluster : clusters) {
        sumAfterClustering += cluster.sumValues();
    }
    Assert.assertEquals(originalSum, sumAfterClustering, 0.001);
    Assert.assertEquals(15, clusters.size());
    saveClusters(graph, "clusterTest-solution", clusters);
}
Also used : InputStreamReader(java.io.InputStreamReader) MarkerGraph(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph) PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) ArrayList(java.util.ArrayList) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) MapSymbol(org.activityinfo.legacy.shared.reports.model.MapSymbol) GeneticSolver(org.activityinfo.server.report.generator.map.cluster.genetic.GeneticSolver) BufferedReader(java.io.BufferedReader) BubbleFitnessFunctor(org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor) AiLatLng(org.activityinfo.model.type.geo.AiLatLng) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Test(org.junit.Test)

Example 8 with PointValue

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

the class BubbleLayerGenerator method generatePoints.

public void generatePoints(List<SiteDTO> sites, TiledMap map, BubbleMapLayer layer, Clusterer clusterer, List<PointValue> mapped, List<PointValue> unmapped) {
    for (SiteDTO site : sites) {
        if (hasValue(site, layer.getIndicatorIds())) {
            Point px = null;
            AiLatLng geoPoint = getPoint(site);
            if (geoPoint != null) {
                px = map.fromLatLngToPixel(geoPoint);
            }
            Double value = getValue(site, layer.getIndicatorIds());
            if (value != null && value != 0) {
                PointValue pv = new PointValue(site, createSymbol(site, layer.getColorDimensions()), value, px);
                if (geoPoint != null || clusterer.isMapped(site)) {
                    mapped.add(pv);
                } else {
                    unmapped.add(pv);
                }
            }
        }
    }
}
Also used : PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) AiLatLng(org.activityinfo.model.type.geo.AiLatLng) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO)

Example 9 with PointValue

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

the class IconLayerGenerator method generate.

@Override
public void generate(TiledMap map, MapContent content) {
    List<PointValue> points = new ArrayList<PointValue>();
    IconRectCalculator rectCalculator = new IconRectCalculator(icon);
    IntersectionCalculator intersectionCalculator = new IntersectionCalculator() {

        @Override
        public boolean intersects(Node a, Node b) {
            return a.getPointValue().getIconRect().intersects(b.getPointValue().getIconRect());
        }
    };
    Clusterer clusterer = ClustererFactory.fromClustering(layer.getClustering(), rectCalculator, intersectionCalculator);
    for (SiteDTO site : sites) {
        if (meetsCriteria(site)) {
            AiLatLng geoPoint = getPoint(site);
            if (geoPoint != null || clusterer.isMapped(site)) {
                Point point = null;
                if (geoPoint != null) {
                    point = map.fromLatLngToPixel(geoPoint);
                }
                points.add(new PointValue(site, point, point == null ? null : rectCalculator.iconRect(point), getValue(site, layer.getIndicatorIds())));
            } else {
                content.getUnmappedSites().add(site.getId());
            }
        }
    }
    List<Cluster> clusters = clusterer.cluster(map, points);
    createMarkersFrom(clusters, map, content);
    IconLayerLegend legend = new IconLayerLegend();
    legend.setDefinition(layer);
    content.addLegend(legend);
}
Also used : PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) Node(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph.Node) ArrayList(java.util.ArrayList) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) Point(org.activityinfo.legacy.shared.reports.content.Point) Clusterer(org.activityinfo.server.report.generator.map.cluster.Clusterer) IntersectionCalculator(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph.IntersectionCalculator) AiLatLng(org.activityinfo.model.type.geo.AiLatLng) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) IconLayerLegend(org.activityinfo.legacy.shared.reports.content.IconLayerLegend)

Example 10 with PointValue

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

the class PiechartLayerGenerator method sumSlices.

private void sumSlices(PieMapMarker marker, List<PointValue> pvs) {
    Map<DimensionCategory, PieMapMarker.SliceValue> slices = new HashMap<DimensionCategory, PieMapMarker.SliceValue>();
    for (PointValue pv : pvs) {
        for (PieMapMarker.SliceValue slice : pv.getSlices()) {
            PieMapMarker.SliceValue summedSlice = slices.get(slice.getCategory());
            if (summedSlice == null) {
                summedSlice = new PieMapMarker.SliceValue(slice);
                summedSlice.setIndicatorId(slice.getIndicatorId());
                slices.put(slice.getCategory(), summedSlice);
            } else {
                summedSlice.setValue(summedSlice.getValue() + slice.getValue());
            }
        }
    }
    marker.setSlices(new ArrayList<PieMapMarker.SliceValue>(slices.values()));
}
Also used : PointValue(org.activityinfo.legacy.shared.reports.model.PointValue)

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