use of org.geotools.data.wfs.WFSDataStore in project OpenTripPlanner by opentripplanner.
the class WFSNotePollingGraphUpdater method setup.
/**
* Setup the WFS data source and add the DynamicStreetNotesSource to the graph
*/
@Override
public void setup() throws IOException, FactoryException {
LOG.info("Setup WFS polling updater");
HashMap<String, Object> connectionParameters = new HashMap<>();
connectionParameters.put(WFSDataStoreFactory.URL.key, url);
WFSDataStore data = (new WFSDataStoreFactory()).createDataStore(connectionParameters);
// Read only single feature type from the source
query = new Query(featureType);
// Get coordinates in WGS-84
query.setCoordinateSystem(CRS.decode("EPSG:4326", true));
featureSource = data.getFeatureSource(featureType);
graph.streetNotesService.addNotesSource(notesSource);
}
use of org.geotools.data.wfs.WFSDataStore 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;
}
use of org.geotools.data.wfs.WFSDataStore in project coastal-hazards by USGS-CIDA.
the class FeatureCollectionExportTest method testWriteToShapefile.
/**
* Test of writeToShapefile method, of class FeatureCollectionExport.
* ignoring this so it doesn't hit the server too much, mock this out for real test
*/
@Test
@Ignore
public void testWriteToShapefile() throws Exception {
WFSDataStoreFactory datastore = new WFSDataStoreFactory();
Map params = new HashMap<>();
params.put(WFSDataStoreFactory.URL.key, new URL("http://coastalmap.marine.usgs.gov/cmgp/National/cvi_WFS/MapServer/WFSServer?service=WFS&request=GetCapabilities&version=1.0.0"));
params.put(WFSDataStoreFactory.WFS_STRATEGY.key, "arcgis");
params.put(WFSDataStoreFactory.TIMEOUT.key, 15000);
params.put(WFSDataStoreFactory.TRY_GZIP.key, "true");
WFSDataStore wfs = datastore.createDataStore(params);
String[] typeNames = wfs.getTypeNames();
SimpleFeatureSource featureSource = wfs.getFeatureSource(typeNames[2]);
FeatureCollectionExport featureCollectionExport = new FeatureCollectionExport(featureSource.getFeatures(), new File("/tmp/shpfile"), "test3");
featureCollectionExport.addAttribute("CVIRISK");
featureCollectionExport.writeToShapefile();
}
use of org.geotools.data.wfs.WFSDataStore in project coastal-hazards by USGS-CIDA.
the class WFSIntrospector method createDs.
private static WFSDataStore createDs(WFSService service) throws IOException {
WFSDataStoreFactory datastore = new WFSDataStoreFactory();
WFSDataStore wfs;
URL getCapsUrl = WFSDataStoreFactory.createGetCapabilitiesRequest(new URL(service.getEndpoint()), Version.v1_1_0);
Map params = new HashMap<>();
params.put(WFSDataStoreFactory.URL.key, getCapsUrl);
params.put(WFSDataStoreFactory.TIMEOUT.key, 5000);
wfs = datastore.createDataStore(params);
return wfs;
}
use of org.geotools.data.wfs.WFSDataStore in project polymap4-core by Polymap4.
the class WfsServiceInfo method of.
public static WfsServiceInfo of(IMetadata metadata, Map<String, String> params) throws ServiceException, MalformedURLException, IOException {
String url = params.get(IMetadataResourceResolver.CONNECTION_PARAM_URL);
// URL url = (URL)params.get( WFSDataStoreFactory.URL.key );
// url = WFSDataStoreFactory.createGetCapabilitiesRequest( url );
Map<String, Serializable> connParams = new HashMap();
connParams.put(WFSDataStoreFactory.URL.key, url);
connParams.put(WFSDataStoreFactory.TIMEOUT.key, 10000);
WFSDataStoreFactory dsf = new WFSDataStoreFactory();
WFSDataStore ds = dsf.createDataStore(connParams);
return new WfsServiceInfo(metadata, ds);
}
Aggregations