Search in sources :

Example 11 with MapLayerMetadata

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

the class AddWMSLayerComposer method onClick$addAllLayersButton.

public void onClick$addAllLayersButton() {
    LOGGER.debug("onClick$addAllLayersButton()");
    // hide (any) previous success message
    resultLabel.setVisible(false);
    // validate - DO NOT SHORT CURCUIT HERE!
    // DO NOT PUT TEST INTO IF STATEMENT (DO NOT SHORT CURCUIT HERE!)
    boolean amc = validateAutomaticModeCommon();
    boolean c = validateCommon();
    if (c && amc) {
        try {
            wmsServer = new WebMapServer(new URL(uri.getValue()));
            discoveredLayer = wmsServer.getCapabilities();
            MapLayer mapLayer = new MapLayer();
            mapLayer.setName(Validate.escapeHtmlAndTrim(label.getValue()));
            String ur = uri.getValue();
            mapLayer.setUri(ur);
            mapLayer.setLayer(layerUtilities.getLayers(ur));
            mapLayer.setOpacity(opacitySlider.getCurpos() / 100.0f);
            mapLayer.setImageFormat(layerUtilities.getImageFormat(ur));
            /* attempt to retrieve bounding box */
            List<Double> bbox = layerUtilities.getBBox(ur);
            if (bbox != null) {
                MapLayerMetadata md = new MapLayerMetadata();
                md.setBbox(bbox);
                md.setMoreInfo(ur);
                mapLayer.setMapLayerMetadata(md);
            }
            /* we don't want our user to have to type loads
                 * when adding a new layer so we just assume/generate
                 * values for the id and description
                 */
            String name = (nameAutomatically.isChecked()) ? "" : Validate.escapeHtmlAndTrim(label.getValue());
            mapLayer.setId(uri + name.replaceAll("\\s+", ""));
            mapLayer.setDescription(name);
            // wms version
            String version = layerUtilities.getVersionValue(ur);
            mapLayer.setType(layerUtilities.internalVersion(version));
            getMapComposer().addUserDefinedLayerToMenu(mapLayer, true);
            updateResult("wms_server_added");
        // addWMSServer handles showing any errors for us
        } catch (Exception e) {
            LOGGER.error("failed to get layer from url", e);
        }
    }
}
Also used : MapLayerMetadata(au.org.emii.portal.menu.MapLayerMetadata) WebMapServer(org.geotools.data.wms.WebMapServer) MapLayer(au.org.emii.portal.menu.MapLayer) URL(java.net.URL) MetadataURL(org.geotools.data.wms.xml.MetadataURL)

Example 12 with MapLayerMetadata

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

the class AddWMSLayerComposer method onClick$addDiscoveredLayerButton.

/**
     * User selected a map layer after doing "select layers" and clicked "add to
     * map"
     */
public void onClick$addDiscoveredLayerButton() {
    LOGGER.debug("onAddDiscoveredLayer()");
    // DO NOT PUT TEST INTO IF STATEMENT (DO NOT SHORT CURCUIT HERE!)
    boolean acm = validateAutomaticModeCommon();
    boolean ams = validiateAutomaticModeSelectLayer();
    boolean c = validateCommon();
    if (acm && ams && c) {
        String discoveredLayerId = ((String[]) layerName.getSelectedItem().getValue())[0];
        /*
             * we've already interogated the WMS server to find the available
             * layers - we don't need to do this again, all we need to do is
             * select the layer they user chose by looking for the layer name
             */
        Layer targetLayer = discoveredLayer.getLayerList().get(Integer.parseInt(discoveredLayerId));
        if (targetLayer != null) {
            MapLayer mapLayer = new MapLayer();
            mapLayer.setName(targetLayer.getName());
            GetMapRequest mapRequest = wmsServer.createGetMapRequest();
            mapRequest.addLayer(targetLayer);
            LOGGER.debug(mapRequest.getFinalURL());
            mapRequest.setFormat(StringConstants.IMAGE_PNG);
            String url = mapRequest.getFinalURL().toString();
            mapLayer.setUri(url);
            mapLayer.setLayer(targetLayer.getName());
            mapLayer.setOpacity(opacitySlider.getCurpos() / 100.0f);
            mapLayer.setImageFormat(layerUtilities.getImageFormat(url));
            /* attempt to retrieve bounding box */
            List<Double> bbox = layerUtilities.getBBox(url);
            if (bbox != null) {
                CRSEnvelope e = targetLayer.getLatLonBoundingBox();
                bbox.set(0, e.getMinX());
                bbox.set(1, e.getMinY());
                bbox.set(2, e.getMaxX());
                bbox.set(3, e.getMaxY());
                MapLayerMetadata md = new MapLayerMetadata();
                md.setBbox(bbox);
                md.setMoreInfo(targetLayer.getName() + "\n" + makeMetadataHtml(targetLayer));
                mapLayer.setMapLayerMetadata(md);
            }
            /* we don't want our user to have to type loads
                 * when adding a new layer so we just assume/generate
                 * values for the id and description
                 */
            String name = (nameAutomatically.isChecked()) ? targetLayer.getName() + ", " + targetLayer.getTitle() : Validate.escapeHtmlAndTrim(label.getValue());
            mapLayer.setId(url + name.replaceAll("\\s+", ""));
            mapLayer.setDescription(name);
            // wms version
            String version = layerUtilities.getVersionValue(url);
            mapLayer.setType(layerUtilities.internalVersion(version));
            getMapComposer().addUserDefinedLayerToMenu(mapLayer, true);
            // all sweet
            updateResult(StringConstants.WMS_LAYER_ADDED);
            // remove the layer from available layers to stop it being 
            // added twice
            removeLayer(discoveredLayerId);
            updateAvailableLayers();
        } else {
            getMapComposer().showMessage(CommonData.lang("error_selecting_layer") + ": '" + discoveredLayerId + "'");
        }
    }
}
Also used : MapLayerMetadata(au.org.emii.portal.menu.MapLayerMetadata) MapLayer(au.org.emii.portal.menu.MapLayer) GetMapRequest(org.geotools.data.wms.request.GetMapRequest) CRSEnvelope(org.geotools.data.ows.CRSEnvelope) Layer(org.geotools.data.ows.Layer) MapLayer(au.org.emii.portal.menu.MapLayer)

Example 13 with MapLayerMetadata

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

the class ImportAnalysisController method loadMapMaxent.

public void loadMapMaxent(Event event) {
    String mapurl = CommonData.getGeoServer() + "/wms?service=WMS&version=1.1.0&request=GetMap&layers=ALA:species_" + pid + "&styles=alastyles&FORMAT=image%2Fpng";
    String legendurl = CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=10&HEIGHT=1" + "&LAYER=ALA:species_" + pid + "&STYLE=alastyles";
    LOGGER.debug(legendurl);
    //get job inputs
    String layername = "Maxent - " + pid;
    getMapComposer().addWMSLayer("species_" + pid, layername, mapurl, (float) 0.5, null, legendurl, LayerUtilitiesImpl.MAXENT, null, null);
    MapLayer ml = getMapComposer().getMapLayer("species_" + pid);
    ml.setPid(pid);
    String infoUrl = CommonData.getSatServer() + "/output/maxent/" + pid + "/species.html";
    MapLayerMetadata md = ml.getMapLayerMetadata();
    md.setMoreInfo(infoUrl + "\nMaxent Output\npid:" + pid);
    md.setId(Long.valueOf(pid));
    try {
        // set off the download as well
        String fileUrl = CommonData.getSatServer() + "/ws/download/" + pid;
        Filedownload.save(new URL(fileUrl).openStream(), "application/zip", layername.replaceAll(" ", "_") + ".zip");
    } catch (Exception ex) {
        LOGGER.error("Error generating download for prediction model pid=" + pid, ex);
    }
    this.detach();
}
Also used : MapLayerMetadata(au.org.emii.portal.menu.MapLayerMetadata) MapLayer(au.org.emii.portal.menu.MapLayer) URL(java.net.URL)

Example 14 with MapLayerMetadata

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

the class ImportAnalysisController method loadMapSxS.

private void loadMapSxS() {
    try {
        if (sxsOccurrenceDensity) {
            String mapurl = CommonData.getGeoServer() + "/wms?service=WMS&version=1.1.0&request=GetMap&layers=ALA:odensity_" + pid + "&styles=odensity_" + pid + "&FORMAT=image%2Fpng";
            String legendurl = CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=10&HEIGHT=1" + "&LAYER=ALA:odensity_" + pid + "&STYLE=odensity_" + pid;
            LOGGER.debug(legendurl);
            String layername = getMapComposer().getNextAreaLayerName(StringConstants.OCCURRENCE_DENSITY);
            getMapComposer().addWMSLayer(pid + "_odensity", layername, mapurl, (float) 0.5, null, legendurl, LayerUtilitiesImpl.ODENSITY, null, null);
            MapLayer ml = getMapComposer().getMapLayer(pid + "_odensity");
            ml.setPid(pid + "_odensity");
            String infoUrl = CommonData.getSatServer() + "/output/sitesbyspecies/" + pid + "/odensity_metadata.html";
            MapLayerMetadata md = ml.getMapLayerMetadata();
            md.setMoreInfo(infoUrl + "\nOccurrence Density\npid:" + pid);
            md.setId(Long.valueOf(pid));
        }
        if (sxsSpeciesDensity) {
            String mapurl = CommonData.getGeoServer() + "/wms?service=WMS&version=1.1.0&request=GetMap&layers=ALA:srichness_" + pid + "&styles=srichness_" + pid + "&FORMAT=image%2Fpng";
            String legendurl = CommonData.getGeoServer() + "/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=10&HEIGHT=1" + "&LAYER=ALA:srichness_" + pid + "&STYLE=srichness_" + pid;
            LOGGER.debug(legendurl);
            String layername = getMapComposer().getNextAreaLayerName(StringConstants.SPECIES_RICHNESS);
            getMapComposer().addWMSLayer(pid + "_srichness", layername, mapurl, (float) 0.5, null, legendurl, LayerUtilitiesImpl.SRICHNESS, null, null);
            MapLayer ml = getMapComposer().getMapLayer(pid + "_srichness");
            ml.setPid(pid + "_srichness");
            String infoUrl = CommonData.getSatServer() + "/output/sitesbyspecies/" + pid + "/srichness_metadata.html";
            MapLayerMetadata md = ml.getMapLayerMetadata();
            md.setMoreInfo(infoUrl + "\nSpecies Richness\npid:" + pid);
            md.setId(Long.valueOf(pid));
        }
        // set off the download as well
        String fileUrl = CommonData.getSatServer() + "/ws/download/" + pid;
        Filedownload.save(new URL(fileUrl).openStream(), "application/zip", "sites_by_species.zip");
    } catch (Exception ex) {
        LOGGER.error("Error generating download for sites by species pid=" + pid, ex);
    }
    this.detach();
}
Also used : MapLayerMetadata(au.org.emii.portal.menu.MapLayerMetadata) MapLayer(au.org.emii.portal.menu.MapLayer) URL(java.net.URL)

Example 15 with MapLayerMetadata

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

the class ImportAnalysisController method loadMapAloc.

public void loadMapAloc(Event event) {
    String layerLabel = "Classification - " + pid;
    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);
    getMapComposer().addWMSLayer("aloc_" + pid, layerLabel, mapurl, (float) 0.5, null, legendurl, LayerUtilitiesImpl.ALOC, null, null);
    MapLayer mapLayer = getMapComposer().getMapLayer("aloc_" + pid);
    mapLayer.setPid(pid);
    if (mapLayer != null) {
        WMSStyle style = new WMSStyle();
        style.setName(StringConstants.DEFAULT);
        style.setDescription("Default style");
        style.setTitle(StringConstants.DEFAULT);
        style.setLegendUri(legendurl);
        LOGGER.debug("legend:" + legendurl);
        mapLayer.addStyle(style);
        mapLayer.setSelectedStyleIndex(1);
        MapLayerMetadata md = mapLayer.getMapLayerMetadata();
        String infoUrl = CommonData.getSatServer() + "/output/layers/" + pid + "/metadata.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", layerLabel.replaceAll(" ", "_") + ".zip");
        } catch (Exception ex) {
            LOGGER.error("Error generating download for classification model pid=" + pid, ex);
        }
    }
    this.detach();
}
Also used : MapLayerMetadata(au.org.emii.portal.menu.MapLayerMetadata) WMSStyle(au.org.emii.portal.wms.WMSStyle) MapLayer(au.org.emii.portal.menu.MapLayer) URL(java.net.URL)

Aggregations

MapLayerMetadata (au.org.emii.portal.menu.MapLayerMetadata)16 MapLayer (au.org.emii.portal.menu.MapLayer)15 URL (java.net.URL)7 ParseException (org.json.simple.parser.ParseException)5 JSONObject (org.json.simple.JSONObject)4 JSONParser (org.json.simple.parser.JSONParser)4 Facet (au.org.ala.legend.Facet)3 HasMapLayer (au.org.emii.portal.menu.HasMapLayer)2 WMSStyle (au.org.emii.portal.wms.WMSStyle)2 XmlArrayList (com.thoughtworks.xstream.persistence.XmlArrayList)2 LegendObject (au.org.ala.legend.LegendObject)1 CRSEnvelope (org.geotools.data.ows.CRSEnvelope)1 Layer (org.geotools.data.ows.Layer)1 WebMapServer (org.geotools.data.wms.WebMapServer)1 GetMapRequest (org.geotools.data.wms.request.GetMapRequest)1 MetadataURL (org.geotools.data.wms.xml.MetadataURL)1 JSONArray (org.json.simple.JSONArray)1