Search in sources :

Example 46 with SiteDTO

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();
}
Also used : SiteDTO(org.activityinfo.shared.dto.SiteDTO)

Example 47 with SiteDTO

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);
                }
            }
        }
    }
}
Also used : PointValue(org.activityinfo.shared.report.model.PointValue) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) SiteDTO(org.activityinfo.shared.dto.SiteDTO) Point(org.activityinfo.shared.report.content.Point)

Example 48 with SiteDTO

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);
}
Also used : PointValue(org.activityinfo.shared.report.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.shared.report.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.shared.report.content.AiLatLng) SiteDTO(org.activityinfo.shared.dto.SiteDTO) IconLayerLegend(org.activityinfo.shared.report.content.IconLayerLegend)

Example 49 with SiteDTO

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()));
                    }
                }
            }
        }
    };
}
Also used : FilterDescription(org.activityinfo.shared.report.content.FilterDescription) TableColumn(org.activityinfo.shared.report.model.TableColumn) Date(java.util.Date) SiteDTO(org.activityinfo.shared.dto.SiteDTO) Row(org.apache.poi.ss.usermodel.Row) TableData(org.activityinfo.shared.report.content.TableData) Cell(org.apache.poi.ss.usermodel.Cell)

Example 50 with SiteDTO

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);
}
Also used : SitePointList(org.activityinfo.shared.command.result.SitePointList) ArrayList(java.util.ArrayList) SitePointDTO(org.activityinfo.shared.dto.SitePointDTO) SiteDTO(org.activityinfo.shared.dto.SiteDTO) Extents(org.activityinfo.shared.util.mapping.Extents)

Aggregations

SiteDTO (org.activityinfo.shared.dto.SiteDTO)71 Test (org.junit.Test)32 GetSites (org.activityinfo.shared.command.GetSites)16 SiteResult (org.activityinfo.shared.command.result.SiteResult)11 CreateSite (org.activityinfo.shared.command.CreateSite)9 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)8 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)7 ArrayList (java.util.ArrayList)7 CreateResult (org.activityinfo.shared.command.result.CreateResult)7 Date (java.util.Date)6 OnDataSet (org.activityinfo.server.database.OnDataSet)6 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)6 AiLatLng (org.activityinfo.shared.report.content.AiLatLng)6 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)5 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)5 KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)5 UpdateSite (org.activityinfo.shared.command.UpdateSite)5 LocationDTO (org.activityinfo.shared.dto.LocationDTO)5 PointValue (org.activityinfo.shared.report.model.PointValue)5 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)4