use of org.geotools.data.wfs.protocol.wfs.WFSException in project coastal-hazards by USGS-CIDA.
the class WFSGetDomain method getDomainValuesAsStrings.
public Set<String> getDomainValuesAsStrings(WFSService service, String attribute) throws IOException {
Set<String> domain = new HashSet<>();
URL getCapsUrl = WFSDataStoreFactory.createGetCapabilitiesRequest(new URL(service.getEndpoint()), Version.v1_1_0);
log.debug("Getting domains from wfs at " + getCapsUrl);
Map params = new HashMap<>();
params.put(WFSDataStoreFactory.URL.key, getCapsUrl);
params.put(WFSDataStoreFactory.TIMEOUT.key, TIMEOUT_MILLISECONDS);
WFSDataStore wfs = datastore.createDataStore(params);
if (wfs == null) {
log.debug("Could not set up WFS datastore");
throw new WFSException("Could not set up WFS datastore");
}
try {
Query query = new Query(service.getTypeName(), Filter.INCLUDE, new String[] { attribute });
SimpleFeatureSource featureSource = wfs.getFeatureSource(service.getTypeName());
SimpleFeatureCollection features = featureSource.getFeatures(query);
SimpleFeatureIterator iterator = features.features();
while (iterator.hasNext()) {
SimpleFeature next = iterator.next();
Object attr = next.getAttribute(attribute);
if (attr instanceof String) {
String attrVal = (String) attr;
domain.add(attrVal);
} else {
throw new UnsupportedOperationException("Currently only string attributes are allowed");
}
}
} finally {
wfs.dispose();
}
return domain;
}
Aggregations