Search in sources :

Example 11 with Facet

use of au.org.ala.legend.Facet in project spatial-portal by AtlasOfLivingAustralia.

the class AooEooComposer method onFinish.

@Override
public boolean onFinish() {
    SelectedArea sa = getSelectedArea();
    Query q = getSelectedSpecies();
    q = q.newFacet(new Facet("occurrence_status_s", "absent", false), false);
    Facet f = new Facet("occurrence_status_s", "absent", false);
    q = q.newFacet(f, false);
    Query newQ = QueryUtil.queryFromSelectedArea(q, sa, false, null);
    double gridSize = dResolution.doubleValue();
    // eoo, use actual points
    LegendObject legend = newQ.getLegend("lat_long");
    StringBuilder sb = new StringBuilder();
    int pointCount = processLegend(legend, sb);
    String aooWkt = aooWkt(legend, gridSize);
    // aoo = gridSize * gridSize * number of gridSize by gridSize cells with an occurrence * (approx sq degrees to sq km)
    double aoo = gridSize * gridSize * aooProcess(legend, gridSize) * 10000;
    double eoo = 0;
    WKTReader reader = new WKTReader();
    String metadata = null;
    try {
        Geometry g = reader.read(sb.toString());
        Geometry convexHull = g.convexHull();
        String wkt = convexHull.toText().replace(" (", "(").replace(", ", ",");
        eoo = SpatialUtil.calculateArea(wkt);
        //aoo area
        Geometry a = reader.read(aooWkt(legend, gridSize));
        Geometry aUnion = a.union();
        String aWkt = aUnion.toText().replace(" (", "(").replace(", ", ",");
        if (eoo > 0) {
            String name = "Extent of occurrence (area): " + q.getName();
            MapLayer ml = getMapComposer().addWKTLayer(wkt, name, name);
            name = "Area of occupancy (area): " + q.getName();
            MapLayer mla = getMapComposer().addWKTLayer(aWkt, name, name);
            metadata = "<html><body>" + "<div class='aooeoo'>" + "<div>The Sensitive Data Service may have changed the location of taxa that have a sensitive status." + " It is wise to first map the taxa and examine each record, then filter these records to create the " + "desired subset, then run the tool on the new filtered taxa layer.</div><br />" + "<table >" + "<tr><td>Number of records used for the calculations</td><td>" + newQ.getOccurrenceCount() + "</td></tr>" + "<tr><td>Species</td><td>" + q.getName() + "</td></tr>" + "<tr><td>Area of Occupancy (AOO: " + gridSize + " degree grid)</td><td>" + String.format("%.0f", aoo) + " sq km</td></tr>" + "<tr><td>Extent of Occurrence (EOO: Minimum convex hull)</td><td>" + (String.format("%.2f", eoo / 1000.0 / 1000.0)) + " sq km</td></tr></table></body></html>" + "</div>";
            ml.getMapLayerMetadata().setMoreInfo("Area of Occupancy and Extent of Occurrence\n" + metadata);
            name = "Extent of occurrence (points): " + q.getName();
            MapLayer ml2 = getMapComposer().mapSpecies(newQ, name, StringConstants.SPECIES, newQ.getOccurrenceCount(), LayerUtilitiesImpl.SPECIES, null, 0, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
            ml2.getMapLayerMetadata().setMoreInfo("Area of Occupancy and Extent of Occurrence\n" + metadata);
        } else {
            //trigger eoo unavailable message
            pointCount = 2;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    //show results
    String message = "The Sensitive Data Service may have changed the location of taxa that have a sensitive status. " + "It is wise to first map the taxa and examine each record, then filter these records to create the " + "desired subset, then run the tool on the new filtered taxa layer.\r\n" + "\r\nNumber of records used for the calculations: " + newQ.getOccurrenceCount() + "\r\nSpecies: " + q.getName() + "\r\nArea of Occupancy: " + String.format("%.0f", aoo) + " sq km" + "\r\nExtent of Occurrence: " + (pointCount < 3 ? "insufficient unique occurrence locations" : (String.format("%.2f", eoo / 1000.0 / 1000.0) + " sq km"));
    if (metadata != null) {
        Event ev = new Event(StringConstants.ONCLICK, null, "Area of Occupancy and Extent of Occurrence\n" + metadata);
        getMapComposer().openHTML(ev);
    } else {
        getMapComposer().showMessage(message);
    }
    //download metadata as text
    Filedownload.save(message, "text/plain", "Calculated AOO and EOO.txt");
    this.detach();
    return true;
}
Also used : Query(au.org.ala.spatial.util.Query) SelectedArea(au.org.emii.portal.menu.SelectedArea) MapLayer(au.org.emii.portal.menu.MapLayer) WKTReader(com.vividsolutions.jts.io.WKTReader) Geometry(com.vividsolutions.jts.geom.Geometry) LegendObject(au.org.ala.legend.LegendObject) Event(org.zkoss.zk.ui.event.Event) Facet(au.org.ala.legend.Facet)

Example 12 with Facet

use of au.org.ala.legend.Facet in project spatial-portal by AtlasOfLivingAustralia.

the class PhylogeneticDiversityComposer method onFinish.

@Override
public boolean onFinish() {
    List<SelectedArea> sa = getSelectedAreas();
    if (autoCompleteLayerSelection != null && cAreasFromLayer.isChecked()) {
        String fieldId = CommonData.getLayerFacetNameDefault(autoCompleteLayerSelection);
        String layer = CommonData.getFacetLayerName(fieldId);
        JSONObject field = CommonData.getLayer(layer);
        JSONObject lyr = (JSONObject) field.get("layer");
        String name = field.get(StringConstants.ID).toString();
        String uid = lyr.get(StringConstants.ID).toString();
        String type = lyr.get(StringConstants.TYPE).toString();
        String treeName = StringUtils.capitalize(field.get(StringConstants.NAME).toString());
        String treePath = lyr.get("displaypath").toString();
        String legendurl = CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=9&LAYER=" + name + "&styles=" + name + "_style";
        String metadata = CommonData.getLayersServer() + "/layers/view/more/" + uid;
        //is it already mapped with the same display name?
        boolean found = false;
        for (MapLayer ml : getMapComposer().getContextualLayers()) {
            if (ml.getDisplayName().equalsIgnoreCase(treeName)) {
                found = true;
                break;
            }
        }
        if (!found) {
            getMapComposer().addWMSLayer(name, treeName, treePath, (float) 0.75, metadata, legendurl, StringConstants.ENVIRONMENTAL.equalsIgnoreCase(type) ? LayerUtilitiesImpl.GRID : LayerUtilitiesImpl.CONTEXTUAL, null, null, null);
            remoteLogger.logMapArea(treeName, "Layer - " + type, treePath, name, metadata);
        }
    }
    Map<String, Object> hm = new HashMap<String, Object>();
    hm.put("selectedareas", sa);
    List<Object> st = new ArrayList<Object>();
    StringBuilder sb = new StringBuilder();
    for (Object o : treesList.getSelectedItems()) {
        st.add(trees[((Listitem) o).getIndex()]);
        if (sb.length() > 0)
            sb.append(",");
        sb.append(((Map<String, String>) trees[((Listitem) o).getIndex()]).get(StringConstants.STUDY_ID));
    }
    hm.put("selectedtrees", st);
    Query q = getSelectedSpecies();
    if (q != null)
        q = q.newFacet(new Facet("occurrence_status_s", "absent", false), false);
    hm.put("query", q);
    PhylogeneticDiversityListResults window = (PhylogeneticDiversityListResults) Executions.createComponents("WEB-INF/zul/results/PhylogeneticDiversityResults.zul", getMapComposer(), hm);
    try {
        window.setParent(getMapComposer());
        window.doModal();
    } catch (Exception e) {
        LOGGER.error("error opening PhylogeneticDiversityResults.zul", e);
    }
    remoteLogger.logMapAnalysis("PhylogeneticDiversity", "PhylogeneticDiversity", sa.size() + " areas", getSelectedSpeciesName(), sb.toString(), "", "", "");
    detach();
    return true;
}
Also used : Query(au.org.ala.spatial.util.Query) PhylogeneticDiversityListResults(au.org.ala.spatial.composer.results.PhylogeneticDiversityListResults) HashMap(java.util.HashMap) SelectedArea(au.org.emii.portal.menu.SelectedArea) MapLayer(au.org.emii.portal.menu.MapLayer) ArrayList(java.util.ArrayList) ParseException(org.json.simple.parser.ParseException) JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) Facet(au.org.ala.legend.Facet)

Example 13 with Facet

use of au.org.ala.legend.Facet in project spatial-portal by AtlasOfLivingAustralia.

the class GDMComposer method runGDMStep1.

public boolean runGDMStep1() {
    try {
        SelectedArea sa = getSelectedArea();
        query = QueryUtil.queryFromSelectedArea(getSelectedSpecies(), sa, false, getGeospatialKosher());
        query = query.newFacet(new Facet("occurrence_status_s", "absent", false), false);
        sbenvsel = getSelectedLayersWithDisplayNames();
        if (query.getSpeciesCount() < 2) {
            getMapComposer().showMessage("An list of species with multiple occurrences for each species is required by GDM.", this);
            return false;
        }
        HttpClient client = new HttpClient();
        PostMethod get = new PostMethod(CommonData.getSatServer() + "/ws/gdm/step1?" + "envlist=" + URLEncoder.encode(sbenvsel, StringConstants.UTF_8) + "&taxacount=" + query.getSpeciesCount() + "&speciesq=" + URLEncoder.encode(QueryUtil.queryFromSelectedArea(query, sa, false, getGeospatialKosher()).getQ(), StringConstants.UTF_8) + "&bs=" + URLEncoder.encode(query.getBS(), StringConstants.UTF_8));
        if (sa.getMapLayer() != null && sa.getMapLayer().getEnvelope() != null) {
            area = StringConstants.ENVELOPE + "(" + sa.getMapLayer().getEnvelope() + ")";
        } else {
            area = sa.getWkt();
        }
        if (getSelectedArea() != null) {
            get.addParameter(StringConstants.AREA, area);
        }
        get.addRequestHeader(StringConstants.ACCEPT, StringConstants.TEXT_PLAIN);
        LOGGER.debug("calling gdm ws step 1");
        client.executeMethod(get);
        step1Id = get.getResponseBodyAsString();
        //wait for step 1
        LOGGER.debug(step1Id);
        getFellow("runningMsg1").setVisible(true);
        statusMsg = ((Label) getFellow("runningMsg1")).getValue();
        startTime = System.currentTimeMillis();
        Events.echoEvent("step1Status", this, null);
        btnOk.setDisabled(true);
        return true;
    } catch (Exception e) {
        LOGGER.error("GDM error: ", e);
        getMapComposer().showMessage("Unknown error.", this);
    }
    return false;
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) SelectedArea(au.org.emii.portal.menu.SelectedArea) HttpClient(org.apache.commons.httpclient.HttpClient) Facet(au.org.ala.legend.Facet)

Example 14 with Facet

use of au.org.ala.legend.Facet in project spatial-portal by AtlasOfLivingAustralia.

the class LayerLegendScatterplotController method onCheck$chkSelectMissingRecords.

public void onCheck$chkSelectMissingRecords(Event event) {
    try {
        registerScatterPlotSelection();
        ScatterplotDataDTO d = getScatterplotData();
        d.setEnabled(true);
        Facet f = getFacetIn();
        if (f == null) {
            mapLayer.setHighlight(null);
        } else {
            mapLayer.setHighlight(f.toString());
        }
        getMapComposer().applyChange(mapLayer);
        tbxChartSelection.setText("");
        data.setImagePath(null);
        data.setMissingDataChecked(chkSelectMissingRecords.isChecked());
        redraw();
    } catch (Exception e) {
        LOGGER.error("error toggling missing records checkbox", e);
        clearSelection();
        getMapComposer().applyChange(mapLayer);
    }
}
Also used : ScatterplotDataDTO(au.org.ala.spatial.dto.ScatterplotDataDTO) Facet(au.org.ala.legend.Facet)

Example 15 with Facet

use of au.org.ala.legend.Facet in project spatial-portal by AtlasOfLivingAustralia.

the class LayerLegendScatterplotController method getFacetIn.

private Facet getFacetIn() {
    String fq = null;
    String e1 = CommonData.getLayerFacetName(data.getLayer1());
    String e2 = CommonData.getLayerFacetName(data.getLayer2());
    //cannot facet when layers are not indexed
    if (!CommonData.getBiocacheLayerList().contains(e1) || !CommonData.getBiocacheLayerList().contains(e2)) {
        return null;
    }
    if (chkSelectMissingRecords.isChecked() && data.getPrevSelection() == null) {
        fq = "-(" + e1 + ":[* TO *] AND " + e2 + ":[* TO *])";
    } else if (data.getPrevSelection() != null) {
        double x1 = data.getPrevSelection()[0];
        double x2 = data.getPrevSelection()[2];
        double y1 = data.getPrevSelection()[1];
        double y2 = data.getPrevSelection()[3];
        Facet f1 = new Facet(e1, y1, y2, true);
        Facet f2 = new Facet(e2, x1, x2, true);
        if (chkSelectMissingRecords.isChecked()) {
            fq = "-(-(" + f1.toString() + " AND " + f2.toString() + ") AND " + e1 + ":[* TO *] AND " + e2 + ":[* TO *])";
        } else {
            fq = f1.toString() + " AND " + f2.toString();
        }
    }
    return Facet.parseFacet(fq);
}
Also used : Facet(au.org.ala.legend.Facet)

Aggregations

Facet (au.org.ala.legend.Facet)35 MapLayer (au.org.emii.portal.menu.MapLayer)12 SelectedArea (au.org.emii.portal.menu.SelectedArea)12 JSONObject (org.json.simple.JSONObject)8 ArrayList (java.util.ArrayList)7 JSONParser (org.json.simple.parser.JSONParser)6 ParseException (org.json.simple.parser.ParseException)6 Query (au.org.ala.spatial.util.Query)5 LegendObject (au.org.ala.legend.LegendObject)3 MapLayerMetadata (au.org.emii.portal.menu.MapLayerMetadata)3 Geometry (com.vividsolutions.jts.geom.Geometry)3 IOException (java.io.IOException)3 StringReader (java.io.StringReader)3 HttpClient (org.apache.commons.httpclient.HttpClient)3 PostMethod (org.apache.commons.httpclient.methods.PostMethod)3 JSONArray (org.json.simple.JSONArray)3 CSVReader (au.com.bytecode.opencsv.CSVReader)2 ScatterplotDataDTO (au.org.ala.spatial.dto.ScatterplotDataDTO)2 BiocacheQuery (au.org.ala.spatial.util.BiocacheQuery)2 XmlArrayList (com.thoughtworks.xstream.persistence.XmlArrayList)2