Search in sources :

Example 6 with Point

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

the class CircleMathTest method testCompletelyContained.

@Test
public void testCompletelyContained() {
    Point a = new Point(297, 212);
    Point b = new Point(295, 213);
    Assert.assertEquals(CircleMath.area(5), CircleMath.intersectionArea(a, b, 8, 5), DELTA);
}
Also used : Point(org.activityinfo.legacy.shared.reports.content.Point) Test(org.junit.Test)

Example 7 with Point

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

the class TileMath method tileBounds.

public static Extents tileBounds(int zoom, int x, int y) {
    Point upperLeft = pointForTile(new Tile(x, y));
    Point lowerRight = pointForTile(new Tile(x + 1, y + 1));
    AiLatLng northWest = inverse(upperLeft, zoom);
    AiLatLng southEast = inverse(lowerRight, zoom);
    return new Extents(southEast.getLat(), northWest.getLat(), northWest.getLng(), southEast.getLng());
}
Also used : AiLatLng(org.activityinfo.model.type.geo.AiLatLng) Point(org.activityinfo.legacy.shared.reports.content.Point) Extents(org.activityinfo.model.type.geo.Extents)

Example 8 with Point

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

the class TileMathTest method inverse.

@Test
public void inverse() {
    AiLatLng latlng = new AiLatLng(15, 30);
    Point px = TileMath.fromLatLngToPixel(latlng, 6);
    AiLatLng inverse = TileMath.inverse(px, 6);
    assertThat("longitude", inverse.getLng(), equalTo(latlng.getLng()));
    assertThat("latitude", inverse.getLat(), closeTo(latlng.getLat(), 0.0001));
}
Also used : AiLatLng(org.activityinfo.model.type.geo.AiLatLng) Point(org.activityinfo.legacy.shared.reports.content.Point) Test(org.junit.Test)

Example 9 with Point

use of org.activityinfo.legacy.shared.reports.content.Point 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 Point

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

the class KMeans method computeCenters.

/**
 * Computes the centers of the assigned clusters
 *
 * @param nodes      The list of nodes
 * @param membership An array containing the cluster membership for each node
 * @param centers    Array of center points to update
 */
private static void computeCenters(List<MarkerGraph.Node> nodes, int[] membership, Point[] centers) {
    int[] sumX = new int[centers.length];
    int[] sumY = new int[centers.length];
    int[] counts = new int[centers.length];
    for (int i = 0; i != nodes.size(); ++i) {
        Point point = nodes.get(i).getPoint();
        sumX[membership[i]] += point.getX();
        sumY[membership[i]] += point.getY();
        counts[membership[i]]++;
    }
    for (int i = 0; i != centers.length; ++i) {
        if (counts[i] > 0) {
            centers[i] = new Point(sumX[i] / counts[i], sumY[i] / counts[i]);
        }
    }
}
Also used : Point(org.activityinfo.legacy.shared.reports.content.Point) Point(org.activityinfo.legacy.shared.reports.content.Point)

Aggregations

Point (org.activityinfo.legacy.shared.reports.content.Point)16 PointValue (org.activityinfo.legacy.shared.reports.model.PointValue)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)5 Cluster (org.activityinfo.server.report.generator.map.cluster.Cluster)4 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 MarkerGraph (org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 List (java.util.List)1 IconLayerLegend (org.activityinfo.legacy.shared.reports.content.IconLayerLegend)1 MapSymbol (org.activityinfo.legacy.shared.reports.model.MapSymbol)1 Extents (org.activityinfo.model.type.geo.Extents)1 Clusterer (org.activityinfo.server.report.generator.map.cluster.Clusterer)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