Search in sources :

Example 1 with WFSDataStoreFactory

use of org.geotools.data.wfs.WFSDataStoreFactory 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();
}
Also used : HashMap(java.util.HashMap) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) WFSDataStore(org.geotools.data.wfs.WFSDataStore) WFSDataStoreFactory(org.geotools.data.wfs.WFSDataStoreFactory) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) URL(java.net.URL) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with WFSDataStoreFactory

use of org.geotools.data.wfs.WFSDataStoreFactory 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;
}
Also used : HashMap(java.util.HashMap) WFSDataStore(org.geotools.data.wfs.WFSDataStore) WFSDataStoreFactory(org.geotools.data.wfs.WFSDataStoreFactory) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL)

Example 3 with WFSDataStoreFactory

use of org.geotools.data.wfs.WFSDataStoreFactory 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);
}
Also used : Query(org.geotools.data.Query) HashMap(java.util.HashMap) WFSDataStore(org.geotools.data.wfs.WFSDataStore) WFSDataStoreFactory(org.geotools.data.wfs.WFSDataStoreFactory)

Example 4 with WFSDataStoreFactory

use of org.geotools.data.wfs.WFSDataStoreFactory 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);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) WFSDataStore(org.geotools.data.wfs.WFSDataStore) WFSDataStoreFactory(org.geotools.data.wfs.WFSDataStoreFactory)

Example 5 with WFSDataStoreFactory

use of org.geotools.data.wfs.WFSDataStoreFactory in project coastal-hazards by USGS-CIDA.

the class FeatureCollectionExportTest method testWriteSolo.

@Test
@Ignore
public void testWriteSolo() 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]);
    SimpleFeatureType schema = featureSource.getSchema();
    FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory("shp");
    Map datastoreConfig = new HashMap<>();
    datastoreConfig.put("url", FileUtils.getFile(FileUtils.getTempDirectory(), "test3.shp").toURI().toURL());
    ShapefileDataStore shpfileDataStore = (ShapefileDataStore) factory.createNewDataStore(datastoreConfig);
    shpfileDataStore.createSchema(schema);
    shpfileDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
    SimpleFeatureStore featureStore = (SimpleFeatureStore) shpfileDataStore.getFeatureSource();
    Transaction t = new DefaultTransaction();
    // Copied directly from Import process
    featureStore.setTransaction(t);
    Query query = new Query();
    query.setCoordinateSystem(DefaultGeographicCRS.WGS84);
    SimpleFeatureIterator fi = featureSource.getFeatures(query).features();
    SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema);
    while (fi.hasNext()) {
        SimpleFeature source = fi.next();
        fb.reset();
        for (AttributeDescriptor desc : schema.getAttributeDescriptors()) {
            fb.set(desc.getName(), source.getAttribute(desc.getName()));
        }
        SimpleFeature target = fb.buildFeature(null);
        target.setDefaultGeometry(source.getDefaultGeometry());
        featureStore.addFeatures(DataUtilities.collection(target));
    }
    t.commit();
    t.close();
}
Also used : ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) Query(org.geotools.data.Query) HashMap(java.util.HashMap) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) WFSDataStore(org.geotools.data.wfs.WFSDataStore) URL(java.net.URL) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeature(org.opengis.feature.simple.SimpleFeature) FileDataStoreFactorySpi(org.geotools.data.FileDataStoreFactorySpi) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) WFSDataStoreFactory(org.geotools.data.wfs.WFSDataStoreFactory) HashMap(java.util.HashMap) Map(java.util.Map) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)5 WFSDataStore (org.geotools.data.wfs.WFSDataStore)5 WFSDataStoreFactory (org.geotools.data.wfs.WFSDataStoreFactory)5 URL (java.net.URL)3 Map (java.util.Map)3 Query (org.geotools.data.Query)2 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 File (java.io.File)1 Serializable (java.io.Serializable)1 DefaultTransaction (org.geotools.data.DefaultTransaction)1 FileDataStoreFactorySpi (org.geotools.data.FileDataStoreFactorySpi)1 Transaction (org.geotools.data.Transaction)1 ShapefileDataStore (org.geotools.data.shapefile.ShapefileDataStore)1 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)1 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)1