public void testAppend() throws Exception { SimpleFeatureType type = DataUtilities.createType("trees", "the_geom:Point,FID:String,NAME:String"); expect(fs.addFeatures(isA(FeatureCollection.class))) .andReturn(Collections.singletonList((FeatureId) (new FeatureIdImpl("trees.105")))); replay(fs); expect(ds.getTypeNames()).andReturn(new String[] {"trees"}).anyTimes(); expect(ds.getSchema("trees")).andReturn(type).anyTimes(); expect(ds.getFeatureSource("trees")).andReturn(fs); replay(ds); sfb.set("NAME", "Old oak"); SimpleFeature feature = sfb.buildFeature(null); SimpleFeatureCollection fc = DataUtilities.collection(feature); List<FeatureId> ids = store.addFeatures(fc); assertEquals(1, ids.size()); String id = ((FeatureId) ids.iterator().next()).getID();
Transaction transaction = new DefaultTransaction("create"); SimpleFeatureStore featureStore = (SimpleFeatureStore) outStore.getFeatureSource(); featureStore.setTransaction(transaction); try { featureStore.addFeatures(contourFeatures); transaction.commit(); } catch (Exception e) {
@Test public void testDelete() throws Exception { final Query queryAll = new Query(RENAMED); SimpleFeatureStore store; store = (SimpleFeatureStore) rts.getFeatureSource(RENAMED); int count = store.getCount(queryAll); store.removeFeatures(fidFilter); assertEquals(count - 1, store.getCount(queryAll)); }
@Test public void testModify() throws Exception { final Query queryAll = new Query(RENAMED); SimpleFeatureStore store; store = (SimpleFeatureStore) rts.getFeatureSource(RENAMED); SimpleFeature original = store.getFeatures(fidFilter).features().next(); String newAddress = ((String) original.getAttribute("ADDRESS")) + " xxx"; store.modifyFeatures( original.getFeatureType().getDescriptor("ADDRESS"), newAddress, fidFilter); SimpleFeature modified = store.getFeatures(fidFilter).features().next(); assertEquals(newAddress, modified.getAttribute("ADDRESS")); }
public void testGetFeatureStoreModifyFeatures1() throws IOException { SimpleFeatureStore road = (SimpleFeatureStore) data.getFeatureSource("road"); AttributeDescriptor descriptor = roadType.getDescriptor("name"); road.modifyFeatures(descriptor.getName(), "changed", rd1Filter); SimpleFeatureCollection results = road.getFeatures(rd1Filter); assertEquals("changed", results.features().next().getAttribute("name")); }
public void testFeatureEvents() throws Exception { SimpleFeatureStore store1 = (SimpleFeatureStore) data.getFeatureSource(roadFeatures[0].getFeatureType().getTypeName()); SimpleFeatureStore store2 = (SimpleFeatureStore) data.getFeatureSource(roadFeatures[0].getFeatureType().getTypeName()); store1.setTransaction(defaultTransaction); class Listener implements FeatureListener { String name; Listener listener2 = new Listener("two"); store1.addFeatureListener(listener1); store2.addFeatureListener(listener2); FilterFactory factory = CommonFactoryFinder.getFilterFactory(null); store1.removeFeatures( factory.id(Collections.singleton(factory.featureId(feature.getID())))); assertEquals(1, listener1.events.size()); assertEquals(0, listener2.events.size()); store1.getTransaction().commit(); store1.addFeatures(DataUtilities.collection(feature)); store1.getTransaction().rollback(); store2.addFeatures(DataUtilities.collection(feature));
for (Iterator f = featureList.iterator(); f.hasNext(); ) { SimpleFeature feature = (SimpleFeature) f.next(); SimpleFeatureType schema = feature.getFeatureType(); ListFeatureCollection collection = (ListFeatureCollection) schema2features.get(schema); feature.getUserData().put(Hints.USE_PROVIDED_FID, true); } else { Object identifier = feature.getAttribute(new NameImpl(GML.NAMESPACE, "identifier")); if (WFSInfo.Version.V_20.compareTo(insert.getVersion()) >= 0 && identifier instanceof String) { new QName(schema.getName().getNamespaceURI(), schema.getTypeName()); SimpleFeatureStore store; store = DataUtilities.simple((FeatureStore) featureStores.get(elementName)); store.getSchema().getGeometryDescriptor(); if (defaultGeometry != null) { CoordinateReferenceSystem target = fids.addAll(store.addFeatures(collection)); store.getFeatures(filterFactory.id(new HashSet<FeatureId>(fids))); event = new TransactionEvent(
CoordinateReferenceSystem sourceCrs = featureSource.getSchema().getCoordinateReferenceSystem(); if (sourceCrs == null) { throw new GeomajasException(new UnsupportedOperationException("Incorrect or no .prj provided in " + Query query = new Query(sourceStore.getTypeNames()[0]); if (CRS.lookupEpsgCode(sourceCrs, true) == null) { query.setCoordinateSystemReproject(targetCrs); if (!Arrays.asList(dataStore.getTypeNames()).contains(layerName)) { dataStore.createSchema(builder.buildFeatureType()); SimpleFeatureStore store = (SimpleFeatureStore) dataStore.getFeatureSource(layerName); store.removeFeatures(Filter.INCLUDE); store.addFeatures(reprojectedCollection);
params.put("file", statesfile); DataStore store = DataStoreFinder.getDataStore(params); SimpleFeatureType featureType = store.getSchema("locations"); duplicate.createSchema(featureType); SimpleFeature feature, newFeature; Query query = new Query(featureType.getTypeName(), Filter.INCLUDE); reader = store.getFeatureReader(query, Transaction.AUTO_COMMIT); writer = duplicate.getFeatureWriterAppend("duplicate", Transaction.AUTO_COMMIT); newFeature = writer.next(); newFeature.setAttributes(feature.getAttributes()); writer.write(); SimpleFeatureStore featureStore = (SimpleFeatureStore) store.getFeatureSource("locations"); assertEquals(9, featureStore.getFeatures().size());
@Test public void testFeatureEventsWithTransaction() throws Exception { DataStore store = new MockContentDataStore(); SimpleFeatureStore store1 = (SimpleFeatureStore) store.getFeatureSource(TYPENAME); SimpleFeatureStore store2 = (SimpleFeatureStore) store.getFeatureSource(TYPENAME); store1.setTransaction(defaultTransaction); store2.setTransaction(anotherTransaction); store1.addFeatureListener(listener1); store2.addFeatureListener(listener2); Filter fidFilter = ff.id(feature.getIdentifier()); bounds.include(feature.getBounds()); bounds.expandToInclude(geom.getEnvelopeInternal()); store1.modifyFeatures(new Name[] {new NameImpl("geom")}, new Object[] {geom}, fidFilter); store1.getTransaction().rollback(); store1.removeFeatures(fidFilter); store1.getTransaction().commit(); store1.addFeatures(DataUtilities.collection(feature)); store1.getTransaction().rollback();
@Before public void setUp() throws Exception { SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); ftb.setName("render-test"); ftb.add("the_geom", Point.class, DefaultGeographicCRS.WGS84); ftb.setDefaultGeometry("the_geom"); ftb.add("name", String.class); featureType = ftb.buildFeatureType(); GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(); SimpleFeatureBuilder fb = new SimpleFeatureBuilder(featureType); fb.set("the_geom", gf.createPoint(new Coordinate(10, 10))); fb.set("name", "The name"); feature = fb.buildFeature(null); File shpFile = new File( "./target/screenMapTest/" + feature.getFeatureType().getName().getLocalPart() + ".shp"); shpFile.getParentFile().mkdirs(); ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory(); Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put(ShapefileDataStoreFactory.URLP.key, shpFile.toURI().toURL()); shapeFileDataStore = dataStoreFactory.createNewDataStore(params); shapeFileDataStore.createSchema(feature.getFeatureType()); SimpleFeatureStore featureStore = (SimpleFeatureStore) shapeFileDataStore.getFeatureSource(shapeFileDataStore.getTypeNames()[0]); featureStore.addFeatures(DataUtilities.collection(feature)); RendererBaseTest.setupVeraFonts(); }
((SimpleFeatureStore) storeDelegate).modifyFeatures(names, values, filter); } else if (writeQuery.getFilter() == Filter.EXCLUDE || writeQuery.getPropertyNames() == Query.NO_NAMES) { throw unsupportedOperation(); final Query local = new Query(null, filter); Query mixed = mixQueries(local, writeQuery); if (writeQuery.getPropertyNames() == Query.ALL_NAMES) { ((SimpleFeatureStore) storeDelegate).modifyFeatures(names, values, mixed.getFilter()); } else { String typeName = getSchema().getName().getLocalPart(); if (policy.getResponse() == org.geoserver.security.Response.CHALLENGE) { throw SecureCatalogImpl.unauthorizedAccess(typeName); ((SimpleFeatureStore) storeDelegate).modifyFeatures(names, values, mixed.getFilter());
"Exporting from " + path + " to " + targetStore.getName().getLocalPart() + "... "); SimpleFeature peek = peekingIt.peek(); Set<String> sourceAtts = new HashSet<String>( Lists.transform(peek.getFeatureType().getAttributeDescriptors(), toString)); Set<String> targetAtts = new HashSet<String>(Lists .transform(targetStore.getSchema().getAttributeDescriptors(), toString)); if (Sets.intersection(sourceAtts, targetAtts).isEmpty()) { throw new GeoToolsOpException(StatusCode.UNABLE_TO_ADD, targetStore.setTransaction(transaction); try { targetStore.addFeatures(asFeatureCollection);
DataUtilities.simple((FeatureStore) featureStores.get(elementName)); String typeName = store.getSchema().getTypeName(); LOGGER.finer("Transaction Delete:" + delete); WFSReprojectionUtil.getDeclaredCrs(store.getSchema(), request.getVersion()); filter = WFSReprojectionUtil.normalizeFilterCRS(filter, store.getSchema(), declaredCRS); request, elementName, store.getFeatures(filter)); event.setSource(Delete.WFS11.unadapt((Delete) delete)); listener.dataStoreChange(event); Envelope damaged = store.getBounds(new Query(elementName.getLocalPart(), filter)); damaged = store.getFeatures(filter).getBounds(); DataStore data = (DataStore) store.getDataStore(); FeatureWriter<SimpleFeatureType, SimpleFeature> writer; writer = data.getFeatureWriter(typeName, filter, store.getTransaction()); store.removeFeatures(filter); int deletedCount = store.getFeatures(filter).size(); if (deletedCount > 0) deleted += deletedCount; store.removeFeatures(filter);
SimpleFeatureCollection granules = (SimpleFeatureCollection) value; SimpleFeatureBuilder fb = new SimpleFeatureBuilder(granulesStore.getSchema()); ListFeatureCollection mappedGranules = new ListFeatureCollection(granulesStore.getSchema()); granules.accepts( f -> { SimpleFeature sf = (SimpleFeature) f; for (AttributeDescriptor ad : granulesStore.getSchema().getAttributeDescriptors()) { fb.set( ad.getLocalName(), sf.getAttribute(ad.getLocalName())); fb.set("the_geom", sf.getDefaultGeometry()); fb.set("product_id", id); SimpleFeature mappedGranule = fb.buildFeature(null);
DataUtilities.simple((FeatureStore) featureStores.values().iterator().next()); if (featureStore == null) { throw new WFSException(element, "Could not obtain feature store"); String featureTypeName = featureStore.getSchema().getTypeName(); Query query = new Query(featureTypeName, replace.getFilter()); SimpleFeatureCollection features = featureStore.getFeatures(replace.getFilter()); if (newFeatures.size() != features.size()) { throw new WFSException( while (it.hasNext()) { SimpleFeature f = it.next(); oldFeatures.put(f.getID(), f); SimpleFeature oldFeature = oldFeatures.get(newFeature.getID()); if (oldFeature == null) { leftovers.add(newFeature);
@Override public void addGranules( final String typeName, final Collection<SimpleFeature> granules, final Transaction transaction) throws IOException { Utilities.ensureNonNull("granuleMetadata", granules); // check if the index has been cleared checkStore(); SimpleFeatureStore store = (SimpleFeatureStore) getTileIndexStore().getFeatureSource(typeName); store.setTransaction(transaction); ListFeatureCollection featureCollection = new ListFeatureCollection(getTileIndexStore().getSchema(typeName)); // add them all Set<FeatureId> fids = new HashSet<FeatureId>(); for (SimpleFeature f : granules) { // Add the feature to the feature collection featureCollection.add(f); fids.add(ff.featureId(f.getID())); } store.addFeatures(featureCollection); store.setTransaction(null); }
public java.util.List<org.opengis.filter.identity.FeatureId> addFeatures( org.geotools.feature.FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection) throws IOException { ListFeatureCollection fc = new ListFeatureCollection(granulesStore.getSchema()); SimpleFeatureBuilder fb = new SimpleFeatureBuilder(granulesStore.getSchema()); try (SimpleFeatureIterator fi = (SimpleFeatureIterator) featureCollection.features()) { while (fi.hasNext()) { SimpleFeature sf = fi.next(); fb.set("product_id", dbProductId); fb.set("location", sf.getAttribute("location")); fb.set("the_geom", sf.getDefaultGeometry()); fb.set("band", sf.getAttribute("band")); SimpleFeature mapped = fb.buildFeature(null); fc.add(mapped); } } return delegate.addFeatures(fc); }; };
final Set<String> typeNames = new HashSet<>(Arrays.asList(sourceDataStore.getTypeNames())); Transaction t = new DefaultTransaction(); try { final SimpleFeatureSource source = sourceDataStore.getFeatureSource(coverage); final SimpleFeatureStore store = getTargetFeatureStore(source.getSchema(), targetStore, coverage); SimpleFeatureCollection indexWithLocation = new LocationFeatureCollection( source.getFeatures(), path, store.getSchema()); store.setTransaction(t); store.addFeatures(indexWithLocation); LOGGER.info("Migration for " + path + ":" + coverage + " succesfull"); t.close(); if (sourceDataStore != null) { sourceDataStore.dispose();
String typeName = query.getTypeName(); SimpleFeatureStore fs = null; try { fs = (SimpleFeatureStore) getTileIndexStore().getFeatureSource(typeName); boolean rollback = true; Transaction t = new DefaultTransaction(); try { final int retVal = fs.getFeatures(query).size(); // ensures we get a value if (retVal > 0) { fs.setTransaction(t); fs.removeFeatures(query.getFilter()); t.commit();