use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class SitesResources method writeGeoJson.
private void writeGeoJson(List<SiteDTO> sites, JsonGenerator json) throws JsonGenerationException, IOException {
json.writeStartArray();
for (SiteDTO site : sites) {
if (site.hasLatLong()) {
json.writeStartObject();
json.writeStringField("type", "Feature");
json.writeNumberField("id", site.getId());
// write out the properties object
json.writeObjectFieldStart("properties");
json.writeStringField("locationName", site.getLocationName());
json.writeStringField("partnerName", site.getPartnerName());
if (!Strings.isNullOrEmpty(site.getComments())) {
json.writeStringField("comments", site.getComments());
}
json.writeEndObject();
// write out the geometry object
json.writeObjectFieldStart("geometry");
json.writeStringField("type", "Point");
json.writeArrayFieldStart("coordinates");
json.writeNumber(site.getX());
json.writeNumber(site.getY());
json.writeEndArray();
json.writeEndObject();
json.writeEndObject();
}
}
json.writeEndArray();
json.close();
}
use of org.activityinfo.shared.dto.SiteDTO 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.dto.SiteDTO 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.dto.SiteDTO in project activityinfo by bedatadriven.
the class ExcelTableRenderer method render.
@Override
public void render(Workbook book, TableElement element) {
final TableData tableData = element.getContent().getData();
new BaseExcelTableRenderer<TableElement, TableColumn>(book, element) {
@Override
public List<FilterDescription> generateFilterDescriptions() {
return element.getContent().getFilterDescriptions();
}
@Override
public void generate() {
/* Generate the column headers for the table */
initColHeaderStyles(element.getRootColumn());
generateColumnHeaders(0, element.getRootColumn());
int headerHeight = rowIndex;
sheet.createFreezePane(element.getFrozenColumns(), headerHeight);
/* Prepare the generators and indexes */
List<TableColumn> leaves = element.getRootColumn().getLeaves();
String[] colIndexes = new String[leaves.size()];
for (int i = 0; i != leaves.size(); ++i) {
colIndexes[i] = leaves.get(i).getSitePropertyName();
}
for (SiteDTO rowData : tableData.getRows()) {
Row row = sheet.createRow(rowIndex++);
for (int i = 0; i != colIndexes.length; ++i) {
Object value = null;
if (colIndexes[i] != null) {
value = rowData.get(colIndexes[i]);
}
Cell cell = row.createCell(i);
if (value instanceof Number) {
cell.setCellValue(((Number) value).doubleValue());
} else if (value instanceof Date) {
cell.setCellValue((Date) value);
} else if (value instanceof Boolean) {
cell.setCellValue((Boolean) value);
} else if (value != null) {
cell.setCellValue(factory.createRichTextString(value.toString()));
}
}
}
}
};
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class GetSitePointsHandler method toPointList.
protected SitePointList toPointList(List<SiteDTO> sites) {
Extents bounds = Extents.empty();
List<SitePointDTO> points = new ArrayList<SitePointDTO>(sites.size());
for (SiteDTO site : sites) {
if (site.hasLatLong()) {
points.add(new SitePointDTO(site.getId(), site.getLongitude(), site.getLatitude()));
bounds.grow(site.getLatitude(), site.getLongitude());
}
}
return new SitePointList(bounds, points);
}
Aggregations