/** * Return a 'view' of the given {@code DataStore} constrained by a {@code Query}. * * @param store the data store * @param query the query * @return the constrained view * @throws IOException if the data store cannot be accessed * @throws SchemaException if the query is incompatible with the store's contents */ public static SimpleFeatureSource createView(final DataStore store, final Query query) throws IOException, SchemaException { return createView(store.getFeatureSource(query.getTypeName()), query); }
public void testCreateView() throws Exception { String[] propNames = {"id", "geom"}; Query query = new Query(roadType.getTypeName(), Filter.INCLUDE, 100, propNames, null); SimpleFeatureSource source = DataUtilities.source(roadFeatures); SimpleFeatureSource view = DataUtilities.createView(source, query); assertNotNull(view); List<AttributeDescriptor> desc = view.getSchema().getAttributeDescriptors(); assertTrue(desc.size() == propNames.length); assertTrue(desc.get(0).getLocalName().equals(propNames[0])); assertTrue(desc.get(1).getLocalName().equals(propNames[1])); }
private SimpleFeatureSource getView() throws IllegalFilterException, IOException, SchemaException { FilterFactory fac = CommonFactoryFinder.getFilterFactory(null); Filter f = fac.less(fac.property("id"), fac.literal(3)); SimpleFeatureSource view = DataUtilities.createView(fs, new Query(typeName, f)); return view; } }
@Test public void testLabelInOrigin() throws Exception { FilterFactory ff = CommonFactoryFinder.getFilterFactory(); SimpleFeatureSource view = DataUtilities.createView( this.featureSource, new Query(null, ff.id(Collections.singleton(ff.featureId("Line.4"))))); Style style = RendererBaseTest.loadStyle(this, "labelStyle.sld"); ReferencedEnvelope bounds = featureSource.getBounds(); bounds.expandBy(-1, -1); BufferedImage image = renderNonStraightLines(view, style, 768, 754, bounds); // let's see if the result image match our expectations File reference = new File( "./src/test/resources/org/geotools/renderer/lite/test-data/labelTopLeft.sld.png"); ImageAssert.assertEquals(reference, image, 3000); }
Filter filter = ECQL.toFilter(cqlFilter); fs = DataUtilities.createView( fs, new Query(fs.getSchema().getTypeName(), filter)); } catch (CQLException | SchemaException e) {
@Override protected FeatureReader<SimpleFeatureType, SimpleFeature> getReaderInternal(Query query) throws IOException { try { // get the target schema from the primary store Query psQuery = new Query(query); Name psName = config.getPrimarySourceType().getStoreName(); psQuery.setTypeName(config.getPrimarySourceType().getTypeName()); DataStore ps = getStore().getStore(psName, false); SimpleFeatureType target = DataUtilities.createView(ps, psQuery).getSchema(); target = retypeNameSchema(target); // schedule all the data retrieval operations FeatureQueue queue = new FeatureQueue(config.getSourceTypes().size()); AggregatingDataStore store = getStore(); for (SourceType st : config.getSourceTypes()) { FeatureCallable fc = new FeatureCallable(store, query, st.getStoreName(), st.getTypeName(), queue, target); queue.addSource(fc); store.submit(fc); } // build a reader out of the queue SimpleFeatureReader reader = new QueueReader(queue, target); return reader; } catch (SchemaException e) { throw new IOException("Failed to compute target feature type", e); } }