Search in sources :

Example 26 with SelectedArea

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

the class AreaToolComposer method detach.

@Override
public void detach() {
    super.detach();
    String parentname = (String) winProps.get(StringConstants.PARENTNAME);
    String areatype = (String) getMapComposer().getAttribute(StringConstants.ADDAREAWINDOW);
    if (areatype == null) {
        areatype = "";
    } else {
        if (areatype.startsWith("ci")) {
            areatype = areatype.substring(2);
        }
        if (areatype.startsWith("Upload")) {
            areatype = "Import - Area " + areatype.substring(6);
        } else if (areatype.startsWith("WKT")) {
            areatype = "Import - Area WKT";
        } else {
            areatype = "Area - " + areatype;
        }
    }
    //always map the user defined area
    MapLayer ml = getMapComposer().getMapLayer(layerName);
    if (ok && ml != null) {
        String displayName = ml.getDisplayName();
        String fromLayer = (String) getMapComposer().getAttribute("mappolygonlayer");
        String activeLayerName = (String) getMapComposer().getAttribute("activeLayerName");
        if (fromLayer == null) {
            fromLayer = "";
        } else {
            getMapComposer().removeAttribute("mappolygonlayer");
        }
        if (activeLayerName == null) {
            activeLayerName = "";
        } else {
            getMapComposer().removeAttribute("activeLayerName");
        }
        remoteLogger.logMapArea(layerName + ((!layerName.equalsIgnoreCase(displayName)) ? " (" + displayName + ")" : ""), areatype, ml.testWKT(), activeLayerName, fromLayer);
        //warn user when reduced WKT may be used for analysis
        getMapComposer().warnForLargeWKT(ml);
        //upload this area and replace with WMS
        getMapComposer().replaceWKTwithWMS(ml);
    }
    if (isAnalysisChild) {
        analysisParent.resetWindow(ok ? layerName : null);
        try {
            remoteLogger.logMapArea(layerName, areatype, getMapComposer().getMapLayer(layerName).testWKT());
        } catch (Exception e) {
            LOGGER.error("error with remote logging", e);
        }
    } else if (isFacetChild) {
        facetParent.resetWindow(ok ? layerName : null);
        try {
            remoteLogger.logMapArea(layerName, areatype, getMapComposer().getMapLayer(layerName).testWKT());
        } catch (Exception e) {
            LOGGER.error("error with remote logging", e);
        }
    } else if (parentname != null && "AddSpeciesInArea".equals(parentname)) {
        //was OK clicked?
        if (ok) {
            //map
            //                String wkt = null;
            //                try {
            //                    wkt = getMapComposer().getMapLayer(layerName).getWKT();
            //                } catch (Exception e) {
            //                    LOGGER.error("failed to get WKT for layer: " + layerName, e);
            //                }
            MapLayer mapLayer = getMapComposer().getMapLayer(layerName);
            Query q = null;
            if (winProps.get(StringConstants.QUERY) != null) {
                q = ((Query) winProps.get(StringConstants.QUERY));
                List<Facet> facets = mapLayer.getFacets();
                String wkt = facets == null ? mapLayer.getWKT() : null;
                SelectedArea sa = new SelectedArea(getMapComposer().getMapLayer(layerName), wkt);
                q = QueryUtil.queryFromSelectedArea(q, sa, true, null);
            }
            if (winProps.get(StringConstants.QUERY) == null) {
                mapSpeciesInArea();
            } else if (winProps.get(StringConstants.FILTER) != null && (Boolean) winProps.get(StringConstants.FILTER)) {
                ml = getMapComposer().mapSpecies(q, (String) winProps.get(StringConstants.NAME), (String) winProps.get("s"), (Integer) winProps.get(StringConstants.FEATURE_COUNT), (Integer) winProps.get(StringConstants.TYPE), null, -1, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
                ml.getMapLayerMetadata().setMoreInfo((String) winProps.get("metadata"));
            } else if (winProps.get("filterGrid") != null && (Boolean) winProps.get("filterGrid")) {
                ml = getMapComposer().mapSpecies(q, (String) winProps.get(StringConstants.NAME), (String) winProps.get("s"), (Integer) winProps.get(StringConstants.FEATURE_COUNT), (Integer) winProps.get(StringConstants.TYPE), null, -1, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
                ml.getMapLayerMetadata().setMoreInfo((String) winProps.get("metadata"));
            } else if (winProps.get("byLsid") != null && (Boolean) winProps.get("byLsid")) {
                ml = getMapComposer().mapSpecies(q, (String) winProps.get(StringConstants.NAME), (String) winProps.get("s"), (Integer) winProps.get(StringConstants.FEATURE_COUNT), (Integer) winProps.get(StringConstants.TYPE), null, -1, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
                ml.getMapLayerMetadata().setMoreInfo((String) winProps.get("metadata"));
            } else {
                getMapComposer().mapSpecies(q, (String) winProps.get(StringConstants.TAXON), (String) winProps.get(StringConstants.RANK), 0, LayerUtilitiesImpl.SPECIES, null, -1, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
            }
            if (getMapComposer().getMapLayer(layerName) != null) {
                String displayName = getMapComposer().getMapLayer(layerName).getDisplayName();
                remoteLogger.logMapArea(layerName + ((!layerName.equalsIgnoreCase(displayName)) ? " (" + displayName + ")" : ""), areatype, null);
            }
        }
    }
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer) SelectedArea(au.org.emii.portal.menu.SelectedArea) Facet(au.org.ala.legend.Facet)

Example 27 with SelectedArea

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

the class AreaReportController method addListener.

void addListener() {
    if (!addedListener) {
        addedListener = true;
        // register for viewport changes
        EventListener el = new EventListener() {

            public void onEvent(Event event) throws Exception {
                selectedArea = new SelectedArea(null, getMapComposer().getViewArea());
            }
        };
        getMapComposer().getLeftmenuSearchComposer().addViewportEventListener(StringConstants.FILTERING_RESULTS, el);
    }
}
Also used : SelectedArea(au.org.emii.portal.menu.SelectedArea) Event(org.zkoss.zk.ui.event.Event) ListDataEvent(javax.swing.event.ListDataEvent) ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent) SpeciesListEvent(au.org.ala.spatial.composer.quicklinks.SpeciesListEvent) SamplingEvent(au.org.ala.spatial.composer.quicklinks.SamplingEvent) EventListener(org.zkoss.zk.ui.event.EventListener)

Example 28 with SelectedArea

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

the class PhylogeneticDiversityListResults method populateListWithProgressBar.

public void populateListWithProgressBar() {
    areaPds = new ArrayList<Map<String, String>>();
    areaSpeciesMatches = new ArrayList<Map<String, JSONArray>>();
    for (SelectedArea sa : selectedAreas) {
        queue.add(sa);
    }
    progress = new ConcurrentHashMap();
    progress.put("label", "Starting");
    progress.put("percent", 0.0);
    Callable backgroundProcess = new Callable<Boolean>() {

        @Override
        public Boolean call() {
            //TODO: setup for multiple threads
            try {
                while (!queue.isEmpty()) {
                    SelectedArea sa = queue.take();
                    progress.put("label", "Processing area: " + (selectedAreas.size() - queue.size()) + " of " + selectedAreas.size());
                    evalArea(sa);
                    progress.put("percent", String.valueOf((selectedAreas.size() - queue.size()) / (double) selectedAreas.size()));
                }
            } catch (InterruptedException e) {
            }
            return true;
        }
    };
    pool = Executors.newFixedThreadPool(1);
    future = pool.submit(backgroundProcess);
    getMapComposer().getOpenLayersJavascript().execute("setTimeout('checkProgress()', 2000);");
    divProgress.setVisible(true);
    divResults.setVisible(false);
}
Also used : SelectedArea(au.org.emii.portal.menu.SelectedArea)

Example 29 with SelectedArea

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

the class SpeciesListResults method populateList.

public void populateList() {
    if (selectedArea == null) {
        selectedArea = new SelectedArea(null, getMapComposer().getViewArea());
    }
    try {
        Query sq = QueryUtil.queryFromSelectedArea(null, selectedArea, extraParams, false, geospatialKosher);
        sq = sq.newFacet(new Facet("occurrence_status_s", "absent", false), false);
        if (sq.getSpeciesCount() <= 0) {
            getMapComposer().showMessage("No species records in the active area.");
            results = null;
            popupListboxResults.setVisible(false);
            resultsLabel.setVisible(false);
            this.detach();
            return;
        }
        //remove header
        String speciesList = chooseEndemic ? sq.endemicSpeciesList() : sq.speciesList();
        results = speciesList.substring(speciesList.indexOf('\n') + 1).split("\n");
        java.util.Arrays.sort(results);
        // results should already be sorted
        String[] tmp = results;
        if (results.length > 200) {
            tmp = java.util.Arrays.copyOf(results, 200);
            resultsLabel.setValue("preview of first 200 of " + results.length + " species found");
        } else {
            resultsLabel.setValue("preview of all " + results.length + " species found");
        }
        popupListboxResults.setModel(new ListModelArray(tmp, false));
        popupListboxResults.setItemRenderer(new ListitemRenderer() {

            public void render(Listitem li, Object data, int itemIdx) {
                String s = (String) data;
                CSVReader reader = new CSVReader(new StringReader(s));
                String[] ss;
                try {
                    ss = reader.readNext();
                } catch (Exception e) {
                    ss = new String[0];
                }
                if (ss == null || ss.length == 0) {
                    return;
                }
                Listcell lc = new Listcell(ss[0]);
                lc.setParent(li);
                int col = 1;
                while (col < ss.length) {
                    lc = new Listcell(ss[col]);
                    lc.setParent(li);
                    col++;
                }
                try {
                    reader.close();
                } catch (IOException e) {
                    LOGGER.error("error closing after reading species list", e);
                }
            }
        });
    } catch (Exception e) {
        LOGGER.error("error reading species list data", e);
    }
}
Also used : Query(au.org.ala.spatial.util.Query) CSVReader(au.com.bytecode.opencsv.CSVReader) SelectedArea(au.org.emii.portal.menu.SelectedArea) IOException(java.io.IOException) IOException(java.io.IOException) StringReader(java.io.StringReader) Facet(au.org.ala.legend.Facet)

Example 30 with SelectedArea

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

the class SpeciesListResults method onClick$btnDownload.

public void onClick$btnDownload() {
    StringBuilder sb = new StringBuilder();
    sb.append("LSID,Scientific Name,Taxon Concept,Taxon Rank,Kingdom,Phylum,Class,Order,Family,Genus,Vernacular Name,Number of records");
    for (int i = 0; i < CommonData.getSpeciesListAdditionalColumnsHeader().size(); i++) {
        sb.append(",").append(CommonData.getSpeciesListAdditionalColumnsHeader().get(i));
    }
    sb.append("\r\n");
    for (String s : results) {
        sb.append(s);
        sb.append("\r\n");
    }
    String spid = pid;
    if (spid == null || StringConstants.NONE.equals(spid)) {
        spid = String.valueOf(System.currentTimeMillis());
    }
    SimpleDateFormat date = new SimpleDateFormat(StringConstants.DATE);
    String sdate = date.format(new Date());
    Filedownload.save(sb.toString(), StringConstants.TEXT_PLAIN, "Species_list_" + sdate + "_" + spid + ".csv");
    if (selectedArea == null) {
        selectedArea = new SelectedArea(null, getMapComposer().getViewArea());
    }
    remoteLogger.logMapAnalysis("Species List", "Export - Species List", (selectedArea.getFacets() != null ? selectedArea.getFacets().get(0).toString() : selectedArea.getWkt()), "", "", spid, "Species_list_" + sdate + "_" + spid + ".csv", "");
    detach();
}
Also used : SelectedArea(au.org.emii.portal.menu.SelectedArea) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

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