Search in sources :

Example 16 with SelectedArea

use of au.org.emii.portal.menu.SelectedArea in project spatial-portal by AtlasOfLivingAustralia.

the class ALOCComposer method getEstimate.

@Override
public long getEstimate() {
    try {
        String sbenvsel = getSelectedLayers();
        if (sbenvsel.split(":").length > 50) {
            getMapComposer().showMessage(sbenvsel.split(":").length + " layers selected.  Please select fewer than 50 environmental layers in step 1.");
            return -1;
        }
        if (groupCount.getValue() <= 1 || groupCount.getValue() > 200) {
            getMapComposer().showMessage("Please enter the number of groups to generate (2 to 200) in step 2.");
            //highlight step 2
            return -1;
        }
        SelectedArea sa = getSelectedArea();
        //estimate analysis size in bytes
        double[][] bbox = null;
        List<Double> bb;
        if (sa.getMapLayer() != null) {
            bb = sa.getMapLayer().getMapLayerMetadata().getBbox();
        } else {
            bb = Util.getBoundingBox(sa.getWkt());
        }
        bbox = new double[][] { { bb.get(0), bb.get(1) }, { bb.get(2), bb.get(3) } };
        long cellsInBBox = (long) ((bbox[1][0] - bbox[0][0]) / 0.01 * (bbox[1][1] - bbox[0][1]) / 0.01);
        long size = (groupCount.getValue() + sbenvsel.split(":").length + 2) * cellsInBBox * 4;
        LOGGER.debug("ALOC estimate size in MB, cells=" + cellsInBBox + ", bbox=" + bbox[0][0] + "," + bbox[0][1] + "," + bbox[1][0] + "," + bbox[1][1] + ", groups=" + groupCount.getValue() + ", layers=" + sbenvsel.split(":").length + ", size=" + size / 1024 / 1024 + ", max size=" + CommonData.getSettings().getProperty("aloc_size_limit_in_mb"));
        if (size / 1024 / 1024 > Integer.parseInt(CommonData.getSettings().getProperty("aloc_size_limit_in_mb"))) {
            getMapComposer().showMessage("Analysis is too large.  Reduce the number of groups, number of layers or area.", this);
            return -1;
        }
        HttpClient client = new HttpClient();
        PostMethod get = new PostMethod((CommonData.getSatServer() + "/ws/aloc/estimate?") + "gc=" + URLEncoder.encode(String.valueOf(groupCount.getValue()), StringConstants.UTF_8) + "&envlist=" + URLEncoder.encode(sbenvsel, StringConstants.UTF_8));
        String area;
        if (sa.getMapLayer() != null && sa.getMapLayer().getEnvelope() != null) {
            area = StringConstants.ENVELOPE + "(" + sa.getMapLayer().getEnvelope() + ")";
        } else {
            area = sa.getWkt();
        }
        get.addParameter(StringConstants.AREA, area);
        get.addRequestHeader(StringConstants.ACCEPT, StringConstants.TEXT_PLAIN);
        client.executeMethod(get);
        String estimate = get.getResponseBodyAsString();
        return Long.valueOf(estimate);
    } catch (Exception e) {
        LOGGER.error("Unable to get estimates", e);
    }
    return -1;
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) SelectedArea(au.org.emii.portal.menu.SelectedArea) HttpClient(org.apache.commons.httpclient.HttpClient)

Example 17 with SelectedArea

use of au.org.emii.portal.menu.SelectedArea in project spatial-portal by AtlasOfLivingAustralia.

the class LayerLegendScatterplotController method onSelect$cbHighlightArea.

public void onSelect$cbHighlightArea(Event event) {
    if (cbHighlightArea.getSelectedItem() != null) {
        if (cbHighlightArea.getSelectedItem().getValue() instanceof MapLayer) {
            MapLayer ml = cbHighlightArea.getSelectedItem().getValue();
            SelectedArea sa = new SelectedArea(ml, ml.getFacets() == null ? ml.getWKT() : null);
            data.setHighlightSa(sa);
        } else {
            String wkt = cbHighlightArea.getSelectedItem().getValue();
            SelectedArea sa = new SelectedArea(null, wkt);
            data.setHighlightSa(sa);
        }
    } else {
        data.setHighlightSa(null);
    }
    try {
        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod(CommonData.getSatServer() + "/ws/scatterplot/style/" + data.getId());
        //add style parameters (highlight area)
        if (data.getHighlightSa() != null) {
            post.addParameter(StringConstants.HIGHLIGHT_WKT, data.getHighlightSa().getWkt());
        } else {
            post.addParameter(StringConstants.HIGHLIGHT_WKT, "");
        }
        post.addRequestHeader(StringConstants.ACCEPT, StringConstants.APPLICATION_JSON);
        client.executeMethod(post);
    } catch (Exception e) {
        LOGGER.error("error getting a new scatterplot id", e);
    }
    data.setImagePath(null);
    redraw();
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer) SelectedArea(au.org.emii.portal.menu.SelectedArea) HttpClient(org.apache.commons.httpclient.HttpClient)

Example 18 with SelectedArea

use of au.org.emii.portal.menu.SelectedArea in project spatial-portal by AtlasOfLivingAustralia.

the class ALOCComposer method runclassification.

public boolean runclassification() {
    try {
        layerLabel = tToolName.getValue();
        String sbenvsel = getSelectedLayersWithDisplayNames();
        if (sbenvsel.split(":").length > 50) {
            getMapComposer().showMessage(sbenvsel.split(":").length + " layers selected.  Please select fewer than 50 environmental layers in step 1.");
            return false;
        }
        if (groupCount.getValue() <= 1 || groupCount.getValue() > 200) {
            getMapComposer().showMessage("Please enter the number of groups to generate (2 to 200) in step 2.");
            return false;
        }
        SelectedArea sa = getSelectedArea();
        //estimate analysis size in bytes
        double[][] bbox = null;
        //NQ: 20131219 Added extra check because BB is not supplied in all situations with the metadata (ie WKT has been drawn etc) http://code.google.com/p/ala/issues/detail?id=475
        if (sa.getMapLayer() != null && sa.getMapLayer().getMapLayerMetadata().getBbox() != null) {
            List<Double> bb = sa.getMapLayer().getMapLayerMetadata().getBbox();
            bbox = new double[][] { { bb.get(0), bb.get(1) }, { bb.get(2), bb.get(3) } };
        } else {
            List<Double> bb = Util.getBoundingBox(sa.getWkt());
            bbox = new double[][] { { bb.get(0), bb.get(1) }, { bb.get(2), bb.get(3) } };
        }
        if (bbox == null) {
            bbox = new double[][] { { -180, -90 }, { 180, 90 } };
        }
        long cellsInBBox = (long) ((bbox[1][0] - bbox[0][0]) / 0.01 * (bbox[1][1] - bbox[0][1]) / 0.01);
        long size = (groupCount.getValue() + sbenvsel.split(":").length + 2) * cellsInBBox * 4;
        LOGGER.debug("ALOC estimate size in MB, cells=" + cellsInBBox + ", bbox=" + bbox[0][0] + "," + bbox[0][1] + "," + bbox[1][0] + "," + bbox[1][1] + ", groups=" + groupCount.getValue() + ", layers=" + sbenvsel.split(":").length + ", size=" + size / 1024 / 1024 + ", max size=" + CommonData.getSettings().getProperty("aloc_size_limit_in_mb"));
        if (size / 1024 / 1024 > Integer.parseInt(CommonData.getSettings().getProperty("aloc_size_limit_in_mb"))) {
            getMapComposer().showMessage("Analysis is too large.  Reduce the number of groups, number of layers or area.", this);
            return false;
        }
        HttpClient client = new HttpClient();
        PostMethod get = new PostMethod((CommonData.getSatServer() + "/ws/aloc?") + "gc=" + URLEncoder.encode(String.valueOf(groupCount.getValue()), StringConstants.UTF_8) + "&envlist=" + URLEncoder.encode(sbenvsel, StringConstants.UTF_8));
        String area;
        if (sa.getMapLayer() != null && sa.getMapLayer().getEnvelope() != null) {
            area = StringConstants.ENVELOPE + "(" + sa.getMapLayer().getEnvelope() + ")";
        } else {
            area = sa.getWkt();
        }
        get.addParameter(StringConstants.AREA, area);
        get.addRequestHeader(StringConstants.ACCEPT, StringConstants.TEXT_PLAIN);
        client.executeMethod(get);
        String slist = get.getResponseBodyAsString();
        generationCount++;
        pid = slist;
        legendPath = "/WEB-INF/zul/legend/LayerLegendClassification.zul?pid=" + pid + "&layer=" + URLEncoder.encode(layerLabel, StringConstants.UTF_8);
        try {
            remoteLogger.logMapAnalysis(tToolName.getValue(), "Tool - Classification", area, "", sbenvsel, pid, "gc: " + groupCount.getValue(), StringConstants.STARTED);
        } catch (Exception e) {
            LOGGER.error("error with remote logger", e);
        }
        ProgressController window = (ProgressController) Executions.createComponents("WEB-INF/zul/progress/AnalysisProgress.zul", getMapComposer(), null);
        window.setParentWindow(this);
        window.start(pid, StringConstants.CLASSIFICATION);
        window.setParent(getMapComposer());
        window.doModal();
        this.setVisible(false);
        return true;
    } catch (Exception ex) {
        LOGGER.error("error opening AnalysisProgress.zul for classification: " + pid, ex);
        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) ProgressController(au.org.ala.spatial.composer.progress.ProgressController)

Example 19 with SelectedArea

use of au.org.emii.portal.menu.SelectedArea in project spatial-portal by AtlasOfLivingAustralia.

the class AreaReportComposer method onFinish.

@Override
public boolean onFinish() {
    //close any existing area report
    Window w = (Window) getPage().getFellowIfAny("popupResults");
    if (w != null) {
        w.detach();
    }
    SelectedArea sa = getSelectedArea();
    String areaName = getSelectedAreaName();
    String areaDisplayName = getSelectedAreaDisplayName();
    boolean includeEndemic = getIsEndemic();
    MapLayer ml = getMapComposer().getMapLayer(areaName);
    double[] bbox = null;
    if (ml != null && ml.getMapLayerMetadata().getBbox() != null && ml.getMapLayerMetadata().getBbox().size() == 4) {
        bbox = new double[4];
        bbox[0] = ml.getMapLayerMetadata().getBbox().get(0);
        bbox[1] = ml.getMapLayerMetadata().getBbox().get(1);
        bbox[2] = ml.getMapLayerMetadata().getBbox().get(2);
        bbox[3] = ml.getMapLayerMetadata().getBbox().get(3);
    }
    AreaReportController.open(sa, areaName, areaDisplayName, (ml == null) ? null : ml.getAreaSqKm(), bbox, includeEndemic);
    detach();
    return true;
}
Also used : Window(org.zkoss.zul.Window) SelectedArea(au.org.emii.portal.menu.SelectedArea) MapLayer(au.org.emii.portal.menu.MapLayer)

Example 20 with SelectedArea

use of au.org.emii.portal.menu.SelectedArea in project spatial-portal by AtlasOfLivingAustralia.

the class ToolComposer method getSelectedArea.

public SelectedArea getSelectedArea() {
    String area = rAreaSelected.getValue();
    SelectedArea sa = null;
    try {
        if (StringConstants.CURRENT.equals(area)) {
            sa = new SelectedArea(null, getMapComposer().getViewArea());
        } else if (StringConstants.AUSTRALIA.equals(area)) {
            sa = new SelectedArea(null, CommonData.getSettings().getProperty(CommonData.AUSTRALIA_WKT));
        } else if (StringConstants.WORLD.equals(area)) {
            sa = new SelectedArea(null, CommonData.WORLD_WKT);
        } else {
            List<MapLayer> layers = getMapComposer().getPolygonLayers();
            for (MapLayer ml : layers) {
                if (area == null || area.equals(ml.getName())) {
                    sa = new SelectedArea(ml, null);
                    break;
                }
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Unable to retrieve selected area", e);
    }
    return sa;
}
Also used : SelectedArea(au.org.emii.portal.menu.SelectedArea) MapLayer(au.org.emii.portal.menu.MapLayer) IOException(java.io.IOException)

Aggregations

SelectedArea (au.org.emii.portal.menu.SelectedArea)30 MapLayer (au.org.emii.portal.menu.MapLayer)14 Facet (au.org.ala.legend.Facet)12 HttpClient (org.apache.commons.httpclient.HttpClient)6 PostMethod (org.apache.commons.httpclient.methods.PostMethod)6 Query (au.org.ala.spatial.util.Query)5 JSONObject (org.json.simple.JSONObject)5 ArrayList (java.util.ArrayList)4 JSONParser (org.json.simple.parser.JSONParser)4 ParseException (org.json.simple.parser.ParseException)4 IOException (java.io.IOException)3 StringReader (java.io.StringReader)3 Event (org.zkoss.zk.ui.event.Event)3 CSVReader (au.com.bytecode.opencsv.CSVReader)2 Geometry (com.vividsolutions.jts.geom.Geometry)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JSONArray (org.json.simple.JSONArray)2 Component (org.zkoss.zk.ui.Component)2