use of org.geotools.data.simple.SimpleFeatureCollection 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.data.simple.SimpleFeatureCollection 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.data.simple.SimpleFeatureCollection in project coastal-hazards by USGS-CIDA.
the class WFSExportClientTest method testWFSExport.
@Ignore
@Test
public void testWFSExport() throws IOException {
// Can we pull this out to get served up by a dummy?
String getCaps = "http://coastalmap.marine.usgs.gov/cmgp/National/cvi_WFS/MapServer/WFSServer?service=WFS&request=GetCapabilities&version=1.1.0";
WFSExportClient client = new WFSExportClient();
client.setupDatastoreFromGetCaps(getCaps);
SimpleFeatureCollection featureCollection = client.getFeatureCollection("National_cvi_WFS:atlantic_cvi", null);
String id = featureCollection.getID();
assertThat(id, is(equalTo("featureCollection")));
}
use of org.geotools.data.simple.SimpleFeatureCollection in project coastal-hazards by USGS-CIDA.
the class RibboningProcess method execute.
@DescribeResult(name = "result", description = "Layer with ribboned clones")
public SimpleFeatureCollection execute(// geometry + attributes come from the SLD, may be static in SLD or parameters that come directly from standard WMS, can look at the geoserver rendering transforms to see what is going on here
@DescribeParameter(name = "features", min = 1, max = 1) SimpleFeatureCollection features, @DescribeParameter(name = "bbox", min = 0, max = 1) ReferencedEnvelope bbox, @DescribeParameter(name = "width", min = 1, max = 1) Integer width, @DescribeParameter(name = "height", min = 1, max = 1) Integer height, @DescribeParameter(name = "invert-side", min = 0, max = 1) Boolean invertSide, @DescribeParameter(name = "calcAngles", min = 0, max = 1) Boolean calcAngles, // which ribbon it is in the set, to be ribboned correctly, all child items in an aggregate ribboned parent must share the same bbox, if they do not, the ribboning process starts over and you'll get overlapping ribbons
@DescribeParameter(name = "ribbon-count", min = 0, max = 1) Integer ribbonCount, // how many pixels is the offset, maybe set in the sld
@DescribeParameter(name = "offset", min = 0, max = 1) Integer offset, // this is the bug ticket we have; given the feature collection it should order first N-S, the attribute it's using might be incorrect, because they're not in the right order, everything is defaulting to 45 degrees at certain zoom levels?
@DescribeParameter(name = "sort-attribute", min = 0, max = 1) String sortAttribute, // which zoom level we're at, m/pixel
@DescribeParameter(name = "scale", min = 0, max = 1) Double scale) throws Exception {
// whether or not the ribbons should be inverted, set to default false if not passed in
if (null == invertSide) {
invertSide = Boolean.FALSE;
}
// whether or not the angles are calculated, set to default false if not passed in
if (null == calcAngles) {
calcAngles = Boolean.FALSE;
}
// which ribbon currently we're working on, if not provided, defaults to 1
if (null == ribbonCount) {
ribbonCount = 1;
}
// how many pixels the offset between the ribbons is, defaults to 5 if not provided
if (null == offset) {
offset = 5;
}
// which zoom level we're at to know what constants to use in calculations
if (null == scale) {
scale = Double.MAX_VALUE;
}
SimpleFeatureCollection featuresToProcess = features;
// the attribute to sort the features by, if it's not null
if (null != sortAttribute) {
featuresToProcess = sortFeatures(sortAttribute, features);
}
CoordinateReferenceSystem bboxCRS = bbox.getCoordinateReferenceSystem();
CoordinateReferenceSystem featureCRS = CRSUtils.getCRSFromFeatureCollection(featuresToProcess);
// calculate the offset of the ribbon based on the bbox, coordinate systems, window size, offset and scale
double[] xyOffset = getXYOffset(bbox, bboxCRS, featureCRS, width, height, offset, scale);
return new Process(featuresToProcess, invertSide, sortAttribute, calcAngles, ribbonCount, xyOffset).execute();
}
use of org.geotools.data.simple.SimpleFeatureCollection in project sldeditor by robward-scisys.
the class InLineFeatureModel method addNewFeature.
/**
* Adds the new feature.
*/
public void addNewFeature() {
SimpleFeatureType featureType = userLayer.getInlineFeatureType();
String typeName = userLayer.getInlineFeatureType().getTypeName();
try {
SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore().getFeatureSource(typeName);
SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(featureType);
ArrayList<SimpleFeature> featureList = new ArrayList<>();
SimpleFeatureIterator it = featureSource.getFeatures().features();
try {
while (it.hasNext()) {
SimpleFeature sf = it.next();
List<Object> attributeValueList = sf.getAttributes();
sfb.addAll(attributeValueList);
featureList.add(sfb.buildFeature(null));
}
// Add new feature
String wktString = "wkt://POINT(0 0)";
Geometry geometry = WKTConversion.convertToGeometry(wktString, getSelectedCRSCode());
sfb.add(geometry);
featureList.add(sfb.buildFeature(null));
} finally {
it.close();
}
SimpleFeatureCollection collection = new ListFeatureCollection(featureType, featureList);
featureCollection = collection;
cachedFeature = null;
lastRow = -1;
DataStore dataStore = DataUtilities.dataStore(collection);
userLayer.setInlineFeatureDatastore(dataStore);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
this.fireTableStructureChanged();
this.fireTableDataChanged();
if (parentObj != null) {
parentObj.inlineFeatureUpdated();
}
}
Aggregations