0

We need to get the respective WMS layer here, ArcGIS Server WMS layer names do not match to WFS names so name matching doesn't work

import org.geotools.data.DataStore;
import org.geotools.data.ows.Layer;
import org.geotools.data.ows.WMSCapabilities;
import org.geotools.data.wfs.WFSDataStoreFactory;
import org.geotools.data.wms.WMSUtils;
import org.geotools.data.wms.WebMapServer;

import java.io.Serializable;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class TestWms {

    public static void main(String[] arg) throws Exception {
        String wfsURL = "http://<server>/arcgis/services/<service>/MapServer/WFSServer?request=GetCapabilities&service=WFS";
        String wmsURL = "http://<server>/arcgis/services/<service>/MapServer/WMSServer?request=GetCapabilities&service=WMS";

        WebMapServer wms = new WebMapServer(new URL(wmsURL));
        WMSCapabilities capabilities = wms.getCapabilities();
        Layer[] wmsLayers = WMSUtils.getNamedLayers(capabilities);

        System.out.println("WMS layers");
        for(Layer layer : wmsLayers){
            System.out.println(layer.getName());
        }

        DataStore store = getDataStore(wfsURL);
        System.out.println("WFS Layers");
        for(String str : store.getTypeNames()){
            // TODO: We need to get the respective WMS layer here
            // Note: arcgis server WMS layer names do not match to WFS names so name matching doesn't work
            System.out.println(str);
        }
    }

    private static DataStore getDataStore(String wfsURL) throws Exception {
        Map<String, Serializable> connectionParameters = new HashMap<>();
        connectionParameters.put("WFSDataStoreFactory:GET_CAPABILITIES_URL",
                wfsURL + "service=WFS&VERSION=1.1.0&REQUEST=GetCapabilities");
        return new WFSDataStoreFactory().createDataStore(connectionParameters);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.