Java Code Examples for org.geotools.data.Query#setMaxFeatures()

The following examples show how to use org.geotools.data.Query#setMaxFeatures() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGetFeaturesWithOffsetLimit() throws Exception {
    init();
    Query q = new Query(featureSource.getSchema().getTypeName());
    // no sorting, let's see if the database can use native one
    q.setStartIndex(1);
    q.setMaxFeatures(1);
    SimpleFeatureCollection features = featureSource.getFeatures(q);

    // check size
    assertEquals(1, features.size());

    // check actual iteration
    try (SimpleFeatureIterator it = features.features()) {
        assertTrue(it.hasNext());
        SimpleFeature f = it.next();
        assertEquals(2, Integer.parseInt((String) f.getAttribute("id")));
        assertFalse(it.hasNext());
    }
}
 
Example 2
Source File: GeoToolsLayer.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 */
@Transactional(readOnly = true)
public Iterator<?> getElements(Filter filter, int offset, int maxResultSize) throws LayerException {
	FeatureSource<SimpleFeatureType, SimpleFeature> source = getFeatureSource();
	try {
		if (source instanceof FeatureStore<?, ?>) {
			SimpleFeatureStore store = (SimpleFeatureStore) source;
			transactionSynchronization.synchTransaction(store);
		}
		Query query = new Query();
		query.setFilter(filter);
		query.setMaxFeatures(maxResultSize > 0 ? maxResultSize : Integer.MAX_VALUE);
		query.setStartIndex(offset);
		FeatureCollection<SimpleFeatureType, SimpleFeature> fc = source.getFeatures(query);
		FeatureIterator<SimpleFeature> it = fc.features();
		transactionSynchronization.addIterator(it);
		return new JavaIterator(it);
	} catch (Throwable t) { // NOSONAR avoid errors (like NPE) as well
		throw new LayerException(t, ExceptionCode.UNEXPECTED_PROBLEM);
	}
}
 
Example 3
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCountWithOffsetLimit() throws Exception {
    init();
    Query query = new Query();
    query.setStartIndex(5);
    query.setMaxFeatures(11);

    assertEquals(6, featureSource.getCount(query));
}
 
Example 4
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testScrollHonorsMaxFeatures() throws Exception {
    init();
    dataStore.setScrollSize(1L);
    Query q = new Query();
    q.setMaxFeatures(7);
    List<SimpleFeature> features = readFeatures(featureSource.getFeatures(q).features());
    assertEquals(7, features.size());
}
 
Example 5
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected=NoSuchElementException.class)
public void testScrollNoSuchElement() throws Exception {
    init();
    dataStore.setScrollSize(1L);
    Query q = new Query();
    q.setMaxFeatures(1);
    SimpleFeatureIterator it = featureSource.getFeatures(q).features();
    assertTrue(it.hasNext());
    it.next();
    assertTrue(!it.hasNext());
    it.next();
}