Search in sources :

Example 6 with WFSDataStore

use of org.geotools.data.wfs.WFSDataStore in project polymap4-core by Polymap4.

the class WfsServiceResolver method createParams.

@Override
public Map<String, String> createParams(Object service) {
    assert service instanceof WFSDataStore : "Service has to be an instanceof WFSDataStore.";
    WFSDataStore ds = (WFSDataStore) service;
    Map<String, String> result = new HashMap();
    result.put(CONNECTION_PARAM_TYPE, CONNECTION_TYPE);
    result.put(CONNECTION_PARAM_URL, ds.getInfo().getSource().toString());
    return result;
}
Also used : HashMap(java.util.HashMap) WFSDataStore(org.geotools.data.wfs.WFSDataStore)

Example 7 with WFSDataStore

use of org.geotools.data.wfs.WFSDataStore 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)

Example 8 with WFSDataStore

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

the class WFSIntrospector method getBbox.

public static Bbox getBbox(WFSService service) throws IOException {
    WFSDataStore wfs = createDs(service);
    ReferencedEnvelope env = wfs.getFeatureTypeWGS84Bounds(service.getTypeName());
    Bbox bbox = new Bbox();
    bbox.setBbox(env.getMinX(), env.getMinY(), env.getMaxX(), env.getMaxY());
    return bbox;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Bbox(gov.usgs.cida.coastalhazards.model.Bbox) WFSDataStore(org.geotools.data.wfs.WFSDataStore)

Example 9 with WFSDataStore

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

the class WFSIntrospector method getAttrs.

public static List<String> getAttrs(WFSService service) throws IOException {
    List<String> attrs = new LinkedList<>();
    WFSDataStore wfs = createDs(service);
    SimpleFeatureType schema = wfs.getSchema(service.getTypeName());
    List<AttributeDescriptor> attributeDescriptors = schema.getAttributeDescriptors();
    for (AttributeDescriptor desc : attributeDescriptors) {
        String localName = desc.getLocalName();
        attrs.add(localName);
    }
    return attrs;
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) WFSDataStore(org.geotools.data.wfs.WFSDataStore) LinkedList(java.util.LinkedList)

Aggregations

WFSDataStore (org.geotools.data.wfs.WFSDataStore)9 HashMap (java.util.HashMap)7 WFSDataStoreFactory (org.geotools.data.wfs.WFSDataStoreFactory)5 URL (java.net.URL)4 Map (java.util.Map)4 Query (org.geotools.data.Query)3 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)3 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)2 Bbox (gov.usgs.cida.coastalhazards.model.Bbox)1 File (java.io.File)1 Serializable (java.io.Serializable)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 DefaultTransaction (org.geotools.data.DefaultTransaction)1 FileDataStoreFactorySpi (org.geotools.data.FileDataStoreFactorySpi)1