use of au.org.emii.portal.menu.MapLayer in project spatial-portal by AtlasOfLivingAustralia.
the class PointComparison method onMapClick.
public void onMapClick(Event event) {
String pointGeom = (String) event.getData();
try {
if (pointGeom.contains(StringConstants.NAN_NAN)) {
} else {
points.get(currentPoint)[0] = pointGeom.replace("POINT(", "").split(" ")[0];
points.get(currentPoint)[1] = pointGeom.split(" ")[1].replace(")", "");
lbPoints.setModel(new SimpleListModel<Object>(points));
//get the current MapComposer instance
MapComposer mc = getMapComposer();
//add feature to the map as a new layer
layerName = mc.getNextAreaLayerName("Point");
MapLayer mapLayer = mc.addWKTLayer(pointGeom, layerName, "Point");
mapLayer.getMapLayerMetadata().setMoreInfo(LayersUtil.getMetadataForWKT(CommonData.lang(StringConstants.METADATA_USER_BOUNDING_BOX), pointGeom));
layers.set(currentPoint, mapLayer);
disableEdit();
}
} catch (Exception e) {
LOGGER.error("Error adding user point", e);
}
}
use of au.org.emii.portal.menu.MapLayer in project spatial-portal by AtlasOfLivingAustralia.
the class InOutComposer method getSelectedAreas.
public List<SelectedArea> getSelectedAreas() {
List<SelectedArea> selectedAreas = new ArrayList<SelectedArea>();
Vbox vboxArea = (Vbox) getFellowIfAny("vboxArea");
for (Component c : vboxArea.getChildren()) {
if ((c instanceof Checkbox) && ((Checkbox) c).isChecked()) {
SelectedArea sa = null;
String area = ((Checkbox) c).getValue();
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.equals(ml.getName())) {
sa = new SelectedArea(ml, null);
break;
}
}
}
} catch (Exception e) {
LOGGER.warn("Unable to retrieve selected area", e);
}
if (sa != null) {
selectedAreas.add(sa);
}
}
}
return selectedAreas;
}
use of au.org.emii.portal.menu.MapLayer in project spatial-portal by AtlasOfLivingAustralia.
the class ALOCComposer method loadMap.
public void loadMap(Event event) {
//get job inputs
try {
for (String s : getJob().split(";")) {
if (s.startsWith("gc")) {
layerLabel = tToolName.getValue();
generationCount++;
break;
}
}
} catch (Exception e) {
LOGGER.error("error getting ALOC job info", e);
}
if (layerLabel == null) {
layerLabel = "My Classification " + generationCount;
generationCount++;
}
String mapurl = CommonData.getGeoServer() + "/wms?service=WMS&version=1.1.0&request=GetMap&layers=ALA:aloc_" + pid + "&FORMAT=image%2Fpng";
String legendurl = CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=10&HEIGHT=1" + "&LAYER=ALA:aloc_" + pid;
LOGGER.debug(legendurl);
legendPath = legendurl;
getMapComposer().addWMSLayer("aloc_" + pid, layerLabel, mapurl, (float) 0.5, null, legendurl, LayerUtilitiesImpl.ALOC, null, null);
MapLayer mapLayer = getMapComposer().getMapLayer("aloc_" + pid);
if (mapLayer != null) {
mapLayer.setPid(pid);
WMSStyle style = new WMSStyle();
style.setName(StringConstants.DEFAULT);
style.setDescription("Default style");
style.setTitle(StringConstants.DEFAULT);
style.setLegendUri(legendurl);
LOGGER.debug("legend:" + legendPath);
mapLayer.addStyle(style);
mapLayer.setSelectedStyleIndex(1);
MapLayerMetadata md = mapLayer.getMapLayerMetadata();
String infoUrl = CommonData.getSatServer() + "/output/aloc/" + pid + "/classification.html" + "\nClassification output\npid:" + pid;
md.setMoreInfo(infoUrl);
md.setId(Long.valueOf(pid));
getMapComposer().updateLayerControls();
try {
// set off the download as well
String fileUrl = CommonData.getSatServer() + "/ws/download/" + pid;
Filedownload.save(new URL(fileUrl).openStream(), "application/zip", tToolName.getValue().replaceAll(" ", "_") + ".zip");
} catch (Exception ex) {
LOGGER.error("Error generating download for classification model:", ex);
}
}
this.detach();
}
use of au.org.emii.portal.menu.MapLayer 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.emii.portal.menu.MapLayer 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;
}
Aggregations