org.geotools.data.Query.setMaxFeatures()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(149)

本文整理了Java中org.geotools.data.Query.setMaxFeatures方法的一些代码示例,展示了Query.setMaxFeatures的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setMaxFeatures方法的具体详情如下:
包路径:org.geotools.data.Query
类名称:Query
方法名:setMaxFeatures

Query.setMaxFeatures介绍

[英]Sets the maximum number of features that should be retrieved by this query. The default is to retrieve all features.
[中]设置此查询应检索的最大功能数。默认设置是检索所有功能。

代码示例

代码示例来源:origin: geoserver/geoserver

query.setMaxFeatures(Query.DEFAULT_MAX);
} else {
  sortBy = null;
  query.setMaxFeatures(Query.DEFAULT_MAX);

代码示例来源:origin: geoserver/geoserver

FF.literal(range.getMaxValue()));
query.setFilter(rangeFilter);
query.setMaxFeatures(maxEntries);
query.setPropertyNames(new String[] {descriptor.getStartAttribute()});
query.setHints(new Hints(StructuredCoverageViewReader.QUERY_FIRST_BAND, true));

代码示例来源:origin: geotools/geotools

/**
 * Builds next query for execute in data source
 *
 * @return
 */
private Query getNextSourceQuery() {
  Query nextQuery = new Query(query);
  Filter idInFilter = IndexQueryUtils.buildIdInExpression(getNextSourceIdList(), mapping);
  nextQuery.setFilter(idInFilter);
  nextQuery.setStartIndex(0);
  nextQuery.setMaxFeatures(Integer.MAX_VALUE);
  return nextQuery;
}

代码示例来源:origin: geotools/geotools

@Override
public int removeGranules(Filter filter, Hints hints) {
  try {
    int removed = catalog.removeGranules(new Query(typeName, filter));
    // we cannot re-initialize a raster manager if there are no granules
    Query q = new Query(manager.getTypeName());
    q.setMaxFeatures(1);
    if (DataUtilities.count(catalog.getGranules(q)) > 0) {
      manager.initialize(true);
    }
    return removed;
  } catch (IOException e) {
    throw new RuntimeException("Failed to remove granules matching " + filter, e);
  }
}

代码示例来源:origin: geotools/geotools

private Query queryWithLimits(int lower, int upper) {
  Query query = new Query(tname("buildings"));
  query.setStartIndex(lower);
  query.setMaxFeatures(upper);
  return query;
}

代码示例来源:origin: geotools/geotools

private Query namedQuery(Filter filter, int countLimit, boolean isJoining, Hints hints) {
  Query query = isJoining ? new JoiningQuery() : new Query();
  if (getName().getNamespaceURI() != null) {
    try {
      query.setNamespace(new URI(getName().getNamespaceURI()));
    } catch (URISyntaxException e) {
      throw new RuntimeException(e);
    }
  }
  query.setTypeName(getName().getLocalPart());
  query.setFilter(filter);
  query.setMaxFeatures(countLimit);
  query.setHints(hints);
  return query;
}

代码示例来源:origin: geotools/geotools

public void testCountWithOffsetLimit() throws Exception {
  Query query = new Query();
  query.setStartIndex(1);
  query.setMaxFeatures(1);
  assertEquals(1, featureSource.getCount(query));
}

代码示例来源:origin: geotools/geotools

/** Test of getMaxFeatures method, of class org.geotools.data.Query. */
public void testMaxFeatures() {
  // System.out.println("testMaxFeatures");
  Query query = new Query();
  assertEquals(Query.DEFAULT_MAX, query.getMaxFeatures());
  query.setMaxFeatures(5);
  assertEquals(5, query.getMaxFeatures());
}

代码示例来源:origin: geotools/geotools

public void testPaginationWithPlaceHolder() throws Exception {
    Query query = new Query("riverFullPlaceHolder");
    query.setStartIndex(1);
    query.setMaxFeatures(2);
    int count = dataStore.getFeatureSource("riverFullPlaceHolder").getCount(query);
    assertTrue(count == 1);
  }
}

代码示例来源:origin: geotools/geotools

/**
 * Build the query for execute on index source partial Implementation manages pagination by
 * itself, so remove bounds from query
 *
 * @return Query
 */
@Override
protected Query transformQueryToIdsOnly() {
  Query idsQuery = new Query(unrollIndexes(partialIQM.getIndexQuery()));
  idsQuery.setProperties(getIndexQueryProperties());
  idsQuery.setTypeName(mapping.getIndexSource().getSchema().getTypeName());
  idsQuery.setStartIndex(null);
  idsQuery.setMaxFeatures(Integer.MAX_VALUE);
  return idsQuery;
}

代码示例来源:origin: geotools/geotools

/**
 * Test the second page of one feature per page.
 *
 * @throws IOException
 */
@Test
public void oneFeatureSecondPage() throws IOException {
  Query query = new Query();
  query.setMaxFeatures(1);
  query.setStartIndex(1);
  SimpleFeatureSource fs = store.getFeatureSource(TYPENAME);
  SimpleFeature[] features = (SimpleFeature[]) fs.getFeatures(query).toArray();
  Assert.assertEquals(1, fs.getCount(query));
  Assert.assertEquals("mock.2", features[0].getID());
}

代码示例来源:origin: geotools/geotools

/**
 * Test the first page of one feature per page.
 *
 * @throws IOException
 */
@Test
public void oneFeatureFirstPage() throws IOException {
  Query query = new Query();
  query.setMaxFeatures(1);
  query.setStartIndex(0);
  SimpleFeatureSource fs = store.getFeatureSource(TYPENAME);
  SimpleFeature[] features = (SimpleFeature[]) fs.getFeatures(query).toArray();
  Assert.assertEquals(1, fs.getCount(query));
  Assert.assertEquals("mock.1", features[0].getID());
}

代码示例来源:origin: geotools/geotools

/**
 * Test the third page of one feature per page.
 *
 * @throws IOException
 */
@Test
public void oneFeatureThirdPage() throws IOException {
  Query query = new Query();
  query.setMaxFeatures(1);
  query.setStartIndex(2);
  SimpleFeatureSource fs = store.getFeatureSource(TYPENAME);
  SimpleFeature[] features = (SimpleFeature[]) fs.getFeatures(query).toArray();
  Assert.assertEquals(1, fs.getCount(query));
  Assert.assertEquals("mock.3", features[0].getID());
}

代码示例来源:origin: geotools/geotools

/**
 * Test a page of two features that only contains one because startindex is too close to the
 * end.
 *
 * @throws IOException
 */
@Test
public void twoFeaturesReturnOne() throws IOException {
  Query query = new Query();
  query.setMaxFeatures(2);
  query.setStartIndex(2);
  SimpleFeatureSource fs = store.getFeatureSource(TYPENAME);
  SimpleFeature[] features = (SimpleFeature[]) fs.getFeatures(query).toArray();
  Assert.assertEquals(1, fs.getCount(query));
  Assert.assertEquals("mock.3", features[0].getID());
}

代码示例来源:origin: geotools/geotools

/**
 * Test the third page of one feature per page with natural sorting.
 *
 * @throws IOException
 */
@Test
public void naturalSortedOneFeatureThirdPage() throws IOException {
  Query query = new Query();
  query.setSortBy(new SortBy[] {SortBy.NATURAL_ORDER});
  query.setMaxFeatures(1);
  query.setStartIndex(2);
  SimpleFeatureSource fs = store.getFeatureSource(TYPENAME);
  SimpleFeature[] features = (SimpleFeature[]) fs.getFeatures(query).toArray();
  Assert.assertEquals(1, fs.getCount(query));
  Assert.assertEquals("mock.3", features[0].getID());
}

代码示例来源:origin: geotools/geotools

/**
 * Test the first page of one feature per page with natural sorting.
 *
 * @throws IOException
 */
@Test
public void naturalSortedOneFeatureFirstPage() throws IOException {
  Query query = new Query();
  query.setSortBy(new SortBy[] {SortBy.NATURAL_ORDER});
  query.setMaxFeatures(1);
  query.setStartIndex(0);
  SimpleFeatureSource fs = store.getFeatureSource(TYPENAME);
  SimpleFeature[] features = (SimpleFeature[]) fs.getFeatures(query).toArray();
  Assert.assertEquals(1, fs.getCount(query));
  Assert.assertEquals("mock.1", features[0].getID());
}

代码示例来源:origin: geotools/geotools

public void testUniqueWithLimitOffset() throws Exception {
  if (!dataStore.getSQLDialect().isLimitOffsetSupported()
      || !dataStore.getSQLDialect().isAggregatedSortSupported("distinct")) {
    return;
  }
  FilterFactory ff = dataStore.getFilterFactory();
  PropertyName p = ff.property(aname("stringProperty"));
  UniqueVisitor v = new MyUniqueVisitor(p);
  Query q = new Query(tname("ft1"));
  q.setStartIndex(0);
  q.setMaxFeatures(2);
  dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null);
  assertFalse(visited);
  Set result = v.getResult().toSet();
  assertEquals(2, result.size());
}

代码示例来源:origin: geotools/geotools

public void testMaxWithLimitOffset() throws Exception {
  if (!dataStore.getSQLDialect().isLimitOffsetSupported()) {
    return;
  }
  FilterFactory ff = dataStore.getFilterFactory();
  PropertyName p = ff.property(aname("doubleProperty"));
  MaxVisitor v = new MyMaxVisitor(p);
  Query q = new Query(tname("ft1"));
  q.setStartIndex(0);
  q.setMaxFeatures(2);
  dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null);
  assertFalse(visited);
  assertEquals(1.1, v.getResult().toDouble(), 0.01);
}

代码示例来源:origin: geotools/geotools

public void testSumWithLimitOffset() throws Exception {
  if (!dataStore.getSQLDialect().isLimitOffsetSupported()) {
    return;
  }
  FilterFactory ff = dataStore.getFilterFactory();
  PropertyName p = ff.property(aname("doubleProperty"));
  SumVisitor v = new MySumVisitor(p);
  Query q = new Query(tname("ft1"));
  q.setStartIndex(0);
  q.setMaxFeatures(2);
  dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null);
  assertFalse(visited);
  assertEquals(1.1, v.getResult().toDouble(), 0.01);
}

代码示例来源:origin: geotools/geotools

public void testMinWithLimitOffset() throws Exception {
  if (!dataStore.getSQLDialect().isLimitOffsetSupported()) {
    return;
  }
  FilterFactory ff = dataStore.getFilterFactory();
  PropertyName p = ff.property(aname("doubleProperty"));
  MinVisitor v = new MyMinVisitor(p);
  Query q = new Query(tname("ft1"));
  q.setStartIndex(0);
  q.setMaxFeatures(2);
  dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null);
  assertFalse(visited);
  assertEquals(0.0, v.getResult().toDouble(), 0.01);
}

相关文章