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;
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations