Search in sources :

Example 6 with AiLatLng

use of org.activityinfo.model.type.geo.AiLatLng in project activityinfo by bedatadriven.

the class PathUtils method addRingToPath.

private static void addRingToPath(TiledMap map, GeneralPath path, Coordinate[] coordinates) {
    System.out.println("--ring--");
    float lastX = Float.NaN;
    float lastY = Float.NaN;
    for (int j = 0; j != coordinates.length; ++j) {
        Point point = map.fromLatLngToPixel(new AiLatLng(coordinates[j].y, coordinates[j].x));
        float x = point.getX();
        float y = point.getY();
        if (x != lastX || y != lastY) {
            System.out.println(point.getX() + "," + point.getY());
            if (j == 0) {
                path.moveTo(x, y);
            } else {
                path.lineTo(x, y);
            }
        }
        lastX = x;
        lastY = y;
    }
    path.closePath();
}
Also used : AiLatLng(org.activityinfo.model.type.geo.AiLatLng) Point(org.activityinfo.legacy.shared.reports.content.Point) Point(org.activityinfo.legacy.shared.reports.content.Point)

Example 7 with AiLatLng

use of org.activityinfo.model.type.geo.AiLatLng 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)

Example 8 with AiLatLng

use of org.activityinfo.model.type.geo.AiLatLng 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 9 with AiLatLng

use of org.activityinfo.model.type.geo.AiLatLng in project activityinfo by bedatadriven.

the class PiechartMapLayerGeneratorTest method testSomething.

@Test
public void testSomething() {
    SiteDTO siteData = new SiteDTO();
    siteData.setId(42);
    siteData.setX(15.0);
    siteData.setY(0.0);
    siteData.setIndicatorValue(1, 50.0);
    siteData.setIndicatorValue(2, 10.0);
    siteData.setIndicatorValue(3, 20.0);
    siteData.setIndicatorValue(4, 40.0);
    PiechartMapLayer pcml = new PiechartMapLayer();
    pcml.setMinRadius(10);
    pcml.setMaxRadius(50);
    pcml.addIndicatorId(1);
    pcml.addIndicatorId(2);
    pcml.addIndicatorId(3);
    pcml.addIndicatorId(4);
    pcml.setClustering(new NoClustering());
    TiledMap map = new TiledMap(500, 600, new AiLatLng(15.0, 0.0), 6);
    Map<Integer, Indicator> indicators = Maps.newHashMap();
    indicators.put(1, new Indicator());
    indicators.put(2, new Indicator());
    indicators.put(3, new Indicator());
    indicators.put(4, new Indicator());
    PiechartLayerGenerator gen = new PiechartLayerGenerator(pcml, indicators);
    gen.setSites(Arrays.asList(siteData));
    MapContent mc = new MapContent();
    gen.generate(map, mc);
    assertThat(mc.getMarkers().size(), equalTo(1));
    assertThat(((PieMapMarker) mc.getMarkers().get(0)).getSlices().size(), equalTo(4));
}
Also used : MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) NoClustering(org.activityinfo.legacy.shared.reports.model.clustering.NoClustering) PieMapMarker(org.activityinfo.legacy.shared.reports.content.PieMapMarker) AiLatLng(org.activityinfo.model.type.geo.AiLatLng) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) PiechartMapLayer(org.activityinfo.legacy.shared.reports.model.layers.PiechartMapLayer) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) Test(org.junit.Test)

Example 10 with AiLatLng

use of org.activityinfo.model.type.geo.AiLatLng 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)

Aggregations

AiLatLng (org.activityinfo.model.type.geo.AiLatLng)19 PointValue (org.activityinfo.legacy.shared.reports.model.PointValue)7 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)6 Point (org.activityinfo.legacy.shared.reports.content.Point)5 Cluster (org.activityinfo.server.report.generator.map.cluster.Cluster)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 MapContent (org.activityinfo.legacy.shared.reports.content.MapContent)3 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)3 Clusterer (org.activityinfo.server.report.generator.map.cluster.Clusterer)3 PieMapMarker (org.activityinfo.legacy.shared.reports.content.PieMapMarker)2 MapReportElement (org.activityinfo.legacy.shared.reports.model.MapReportElement)2 MapSymbol (org.activityinfo.legacy.shared.reports.model.MapSymbol)2 PiechartMapLayer (org.activityinfo.legacy.shared.reports.model.layers.PiechartMapLayer)2 Extents (org.activityinfo.model.type.geo.Extents)2 BaseEvent (com.extjs.gxt.ui.client.event.BaseEvent)1 StoreEvent (com.extjs.gxt.ui.client.store.StoreEvent)1 BufferedReader (java.io.BufferedReader)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1