use of org.activityinfo.shared.report.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;
}
use of org.activityinfo.shared.report.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);
}
use of org.activityinfo.shared.report.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;
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, createSymbol(site, layer.getColorDimensions()), value, px);
// TODO: add AdminLevel to pointvalue
if (clusterer.isMapped(site)) {
mapped.add(pv);
} else {
unmapped.add(pv);
}
}
}
}
}
use of org.activityinfo.shared.report.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)) {
if (clusterer.isMapped(site)) {
Point point = null;
if (site.hasLatLong()) {
point = map.fromLatLngToPixel(new AiLatLng(site.getLatitude(), site.getLongitude()));
}
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);
}
use of org.activityinfo.shared.report.model.PointValue in project activityinfo by bedatadriven.
the class PiechartLayerGenerator method generate.
@Override
public void generate(TiledMap map, MapContent content) {
// create the list of input point values
List<PointValue> points = new ArrayList<PointValue>();
List<PointValue> unmapped = new ArrayList<PointValue>();
// 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());
}
Clusterer clusterer = ClustererFactory.fromClustering(layer.getClustering(), radiiCalculator, new BubbleIntersectionCalculator(layer.getMaxRadius()));
generatePoints(map, layer, clusterer, points, unmapped);
// add unmapped sites
for (PointValue pv : unmapped) {
content.getUnmappedSites().add(pv.getSite().getId());
}
List<Cluster> clusters = clusterer.cluster(map, points);
// 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 PieMapMarker();
sumSlices((PieMapMarker) marker, cluster.getPointValues());
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.setIndicatorIds(new HashSet<Integer>(layer.getIndicatorIds()));
marker.setClusterAmount(cluster.getPointValues().size());
marker.setClustering(layer.getClustering());
markers.add(marker);
}
// number markers if applicable
if (layer.getLabelSequence() != null) {
numberMarkers(markers);
}
PieChartLegend legend = new PieChartLegend();
legend.setDefinition(layer);
content.getMarkers().addAll(markers);
content.addLegend(legend);
}
Aggregations