Search in sources :

Example 1 with BBox

use of eu.esdihumboldt.hale.io.wfs.capabilities.BBox in project hale by halestudio.

the class BBOXPage method updateMap.

/**
 * Update the map (i.e. set the map server).
 *
 * @param caps the WFS capabilities
 */
private void updateMap(WFSCapabilities caps) {
    CustomTileMapServer tileServer = new CustomTileMapServer();
    // use Stamen Terrain as default map here
    tileServer.setUrlPattern("http://tile.stamen.com/terrain/{z}/{x}/{y}.jpg");
    tileServer.setAttributionText("Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under CC BY SA.");
    tileServer.setZoomLevel(16);
    MapServer server = tileServer;
    Set<GeoPosition> positions = null;
    if (caps != null) {
        /*
			 * TODO optimal solution would be using the WMS that serves the
			 * layers corresponding to the feature types
			 */
        // collect BBs from feature types
        Set<QName> types = new HashSet<>(getWizard().getConfiguration().getTypeNames());
        if (types.isEmpty()) {
        // no features will be selected
        } else {
            List<BBox> bbs = new ArrayList<>();
            for (QName type : types) {
                FeatureTypeInfo info = caps.getFeatureTypes().get(type);
                if (info != null && info.getWgs84BBox() != null) {
                    bbs.add(info.getWgs84BBox());
                }
            }
            if (!bbs.isEmpty()) {
                double minX, maxX, minY, maxY;
                Iterator<BBox> it = bbs.iterator();
                BBox bb = it.next();
                minX = bb.getX1();
                minY = bb.getY1();
                maxX = bb.getX2();
                maxY = bb.getY2();
                while (it.hasNext()) {
                    bb = it.next();
                    minX = Math.min(minX, bb.getX1());
                    minY = Math.min(minY, bb.getY1());
                    maxX = Math.max(maxX, bb.getX2());
                    maxY = Math.max(maxY, bb.getY2());
                }
                GeoPosition topLeft = new GeoPosition(minX, maxY, 4326);
                GeoPosition bottomRight = new GeoPosition(maxX, minY, 4326);
                Color back = mapKit.getBackground();
                server = new ClippingMapServer(server, topLeft, bottomRight, new Color(back.getRed(), back.getGreen(), back.getBlue(), 170));
                positions = new HashSet<>();
                positions.add(topLeft);
                positions.add(bottomRight);
            } else {
            // ignore BBs, provide full map
            }
        }
    }
    mapKit.setServer(server, true);
    if (positions != null) {
        try {
            mapKit.zoomToPositions(positions);
        } catch (Exception e) {
        // ignore error
        }
    }
    mapKit.refresh();
}
Also used : QName(javax.xml.namespace.QName) Color(java.awt.Color) ArrayList(java.util.ArrayList) ClippingMapServer(eu.esdihumboldt.hale.io.wfs.ui.getfeature.internal.ClippingMapServer) CustomTileMapServer(de.fhg.igd.mapviewer.server.tiles.CustomTileMapServer) BBox(eu.esdihumboldt.hale.io.wfs.capabilities.BBox) MapServer(de.fhg.igd.mapviewer.server.MapServer) ClippingMapServer(eu.esdihumboldt.hale.io.wfs.ui.getfeature.internal.ClippingMapServer) CustomTileMapServer(de.fhg.igd.mapviewer.server.tiles.CustomTileMapServer) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) FeatureTypeInfo(eu.esdihumboldt.hale.io.wfs.capabilities.FeatureTypeInfo) HashSet(java.util.HashSet)

Example 2 with BBox

use of eu.esdihumboldt.hale.io.wfs.capabilities.BBox in project hale by halestudio.

the class WFSGetFeatureSource method determineSource.

@Override
protected void determineSource(URIFieldEditor sourceURL) {
    WFSGetFeatureConfig config = new WFSGetFeatureConfig();
    WFSGetFeatureWizard wizard = new WFSGetFeatureWizard(config, getSchemaSpace());
    HaleWizardDialog dialog = new HaleWizardDialog(Display.getCurrent().getActiveShell(), wizard);
    if (dialog.open() == WizardDialog.OK) {
        WFSGetFeatureConfig result = wizard.getConfiguration();
        // create URL
        URIBuilder builder = new URIBuilder(result.getGetFeatureUri());
        // add fixed parameters
        builder.addParameter("SERVICE", "WFS");
        builder.addParameter("VERSION", result.getVersion().toString());
        builder.addParameter("REQUEST", "GetFeature");
        // specify type names
        if (!result.getTypeNames().isEmpty()) {
            KVPUtil.addTypeNameParameter(builder, result.getTypeNames(), result.getVersion());
        }
        // BBOX
        if (result.getBbox() != null) {
            BBox bb = result.getBbox();
            List<String> vals = new ArrayList<>(5);
            vals.add(Double.toString(bb.getX1()));
            vals.add(Double.toString(bb.getY1()));
            vals.add(Double.toString(bb.getX2()));
            vals.add(Double.toString(bb.getY2()));
            String crs = result.getBboxCrsUri();
            if (crs != null && !crs.isEmpty()) {
                vals.add(crs);
            } else {
            // if no CRS is provided this may be a problem, because
            // default behavior is different for WFS 1.1 and WFS 2.0
            // WFS 1.1: WGS 84
            // WFS 2.0: Service default CRS
            }
            builder.addParameter("BBOX", Joiner.on(',').join(vals));
        }
        // MAXFEATURES (WFS 1) / COUNT (WFS 2)
        if (result.getMaxFeatures() != null) {
            switch(result.getVersion()) {
                case V1_1_0:
                    builder.addParameter("MAXFEATURES", String.valueOf(result.getMaxFeatures()));
                    break;
                case V2_0_0:
                case V2_0_2:
                default:
                    builder.addParameter("COUNT", String.valueOf(result.getMaxFeatures()));
                    break;
            }
        }
        try {
            sourceURL.setStringValue(builder.build().toString());
            getPage().setErrorMessage(null);
        } catch (URISyntaxException e) {
            getPage().setErrorMessage(e.getLocalizedMessage());
        }
    }
}
Also used : BBox(eu.esdihumboldt.hale.io.wfs.capabilities.BBox) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog) URIBuilder(org.apache.http.client.utils.URIBuilder)

Aggregations

BBox (eu.esdihumboldt.hale.io.wfs.capabilities.BBox)2 ArrayList (java.util.ArrayList)2 MapServer (de.fhg.igd.mapviewer.server.MapServer)1 CustomTileMapServer (de.fhg.igd.mapviewer.server.tiles.CustomTileMapServer)1 FeatureTypeInfo (eu.esdihumboldt.hale.io.wfs.capabilities.FeatureTypeInfo)1 ClippingMapServer (eu.esdihumboldt.hale.io.wfs.ui.getfeature.internal.ClippingMapServer)1 HaleWizardDialog (eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)1 Color (java.awt.Color)1 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 GeoPosition (org.jdesktop.swingx.mapviewer.GeoPosition)1