use of org.geotools.feature.simple.SimpleFeatureBuilder in project coastal-hazards by USGS-CIDA.
the class FeatureCollectionExportTest method testHttpComponentsGetter.
@Test
@Ignore
public void testHttpComponentsGetter() throws Exception {
HttpComponentsWFSClient wfs = new HttpComponentsWFSClient();
wfs.setupDatastoreFromEndpoint("http://cida-wiwsc-cchdev:8081/geoserver/wfs");
// FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
SimpleFeatureCollection featureCollection = wfs.getFeatureCollection("proxied:atl_cvi", null);
SimpleFeatureType schema = GMLStreamingFeatureCollection.unwrapSchema(featureCollection.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 = featureCollection.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();
}
use of org.geotools.feature.simple.SimpleFeatureBuilder in project coastal-hazards by USGS-CIDA.
the class FeatureCollectionExportTest method splitterTest.
@Test
// for now
@Ignore
public void splitterTest() throws Exception {
// get geometry
HttpComponentsWFSClient wfs1 = new HttpComponentsWFSClient();
wfs1.setupDatastoreFromEndpoint("http://cida-wiwsc-cchdev:8081/geoserver/wfs");
FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
PropertyIsEqualTo equals = filterFactory.equals(filterFactory.property("STATEFP"), filterFactory.literal(37));
SimpleFeatureCollection featureCollection = wfs1.getFeatureCollection("splitter:tl_2013_coastal_states", equals);
SimpleFeatureIterator features = featureCollection.features();
// only deal with one
Geometry geom = null;
if (features.hasNext()) {
SimpleFeature next = features.next();
geom = (Geometry) next.getDefaultGeometry();
}
// then use geometry as filter
HttpComponentsWFSClient wfs2 = new HttpComponentsWFSClient();
wfs2.setupDatastoreFromEndpoint("http://cida-wiwsc-cchdev:8081/geoserver/wfs");
FilterFactory2 filterFactory2 = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
Contains contains = filterFactory2.contains(filterFactory2.property("the_geom"), filterFactory2.literal(geom));
SimpleFeatureCollection featureCollection2 = wfs2.getFeatureCollection("proxied:atl_cvi", contains);
SimpleFeatureType schema = GMLStreamingFeatureCollection.unwrapSchema(featureCollection2.getSchema());
FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory("shp");
Map datastoreConfig = new HashMap<>();
datastoreConfig.put("url", FileUtils.getFile(FileUtils.getTempDirectory(), "splitter.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 = featureCollection2.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();
}
use of org.geotools.feature.simple.SimpleFeatureBuilder 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();
}
use of org.geotools.feature.simple.SimpleFeatureBuilder in project dhis2-core by dhis2.
the class MapUtils method createFeatureLayerFromMapObject.
/**
* Creates a feature layer based on a map object.
*/
public static Layer createFeatureLayerFromMapObject(InternalMapObject mapObject) {
Style style = mapObject.getStyle();
SimpleFeatureType featureType = mapObject.getFeatureType();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
featureBuilder.add(mapObject.getGeometry());
SimpleFeature feature = featureBuilder.buildFeature(null);
featureCollection.add(feature);
return new FeatureLayer(featureCollection, style);
}
use of org.geotools.feature.simple.SimpleFeatureBuilder in project ddf by codice.
the class CatalogFeatureIndexerTest method getExampleFeature.
private SimpleFeature getExampleFeature() {
Geometry geometry = JTSFactoryFinder.getGeometryFactory(null).createPoint(new Coordinate(1, 1));
SimpleFeatureBuilder builder = FeatureBuilder.forGeometry(geometry);
SimpleFeature simpleFeature = builder.buildFeature(COUNTRY_CODE);
simpleFeature.setAttribute("name", TITLE);
return simpleFeature;
}
Aggregations