I have a further question on this. When I get the list of layers from the 
server, it’s a list of useless layer names such as “layer-234”, rather than a 
human readable (and informative) title. The title is buried in the 
WFSCapabilities object and I cannot see any way to get them out.
Is there a way?
(Since I can get the titles if I put the URL into QGIS, I am assuming that the 
server is not necessarily misconfigured).
Thanx
Gaby

From: Ian Turton <[email protected]>
Date: Monday, 8 January 2018 at 22:22
To: Gabriella Turek <[email protected]>
Cc: "[email protected]" 
<[email protected]>
Subject: Re: [Geotools-gt2-users] How do I get a list of available layers for a 
WFS service

Sorry for not replying before, I'm not sure I saw that email.

Anyway, first construct a WFSDataStore

    Map<String, Object> params = new HashMap<>();
    params.put(WFSDataStoreFactory.URL.key, baseURL);
    if (auth) {
      params.put(WFSDataStoreFactory.USERNAME.key, user);
      params.put(WFSDataStoreFactory.PASSWORD.key, passwd);
    }
    // params.put(WFSDataStoreFactory.WFS_STRATEGY.key, "mapserver");
    datastore = DataStoreFinder.getDataStore(params);

Then simply ask for the typeNames

    String[] names = datastore.getTypeNames();

and then for any name you can grab a featureSource

    SimpleFeatureSource source = datastore.getFeatureSource(name);

and features:

    SimpleFeatureCollection features = source.getFeatures(query);

Hope that helps

Ian


On 7 January 2018 at 20:21, Gabriella Turek 
<[email protected]<mailto:[email protected]>> wrote:
Hi all, I am sending this again as I did not get any replies before Xmas.
I am trying to implement a WFS service client in our app, but I can’t figure 
out how to get a list of available layers from the initial getCapabilities 
request.
Something akin to what one can do for WMS:

WebMapServer wms = null;

try {

wms = new WebMapServer(url);

WMSCapabilities capabilities = wms.getCapabilities();

Layer[] layers = WMSUtils.getNamedLayers(capabilities);

if (layers == null || layers.length == 0) {

return "the server does not provide any layers.";

}

} catch (Exception e) {}


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users



--
Ian Turton
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to