本文整理汇总了Java中org.geotools.data.Query.setSortBy方法的典型用法代码示例。如果您正苦于以下问题:Java Query.setSortBy方法的具体用法?Java Query.setSortBy怎么用?Java Query.setSortBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.geotools.data.Query
的用法示例。
在下文中一共展示了Query.setSortBy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeDefinitionQuery
import org.geotools.data.Query; //导入方法依赖的package包/类
/**
* Takes a query and adapts it to match re definitionQuery filter
* configured for a feature type.
*
* @param query Query against this DataStore
* @param schema TODO
*
* @return Query restricted to the limits of definitionQuery
*
* @throws IOException See DataSourceException
* @throws DataSourceException If query could not meet the restrictions of
* definitionQuery
*/
protected Query makeDefinitionQuery(Query query, SimpleFeatureType schema) throws IOException {
if ((query == Query.ALL) || query.equals(Query.ALL)) {
return query;
}
try {
String[] propNames = extractAllowedAttributes(query, schema);
Filter filter = query.getFilter();
filter = makeDefinitionFilter(filter);
Query defQuery = new Query(query);
defQuery.setFilter(filter);
defQuery.setPropertyNames(propNames);
// set sort by
if (query.getSortBy() != null) {
defQuery.setSortBy(query.getSortBy());
}
// tell the data sources about the default linearization tolerance for curved
// geometries they might be reading
if (linearizationTolerance != null) {
query.getHints().put(Hints.LINEARIZATION_TOLERANCE, linearizationTolerance);
}
return defQuery;
} catch (Exception ex) {
throw new DataSourceException(
"Could not restrict the query to the definition criteria: " + ex.getMessage(), ex);
}
}
示例2: secondaryIndexExample
import org.geotools.data.Query; //导入方法依赖的package包/类
static void secondaryIndexExample(String simpleFeatureTypeName,
DataStore dataStore,
String[] attributeFields,
String attributesQuery,
int maxFeatures,
String sortByField)
throws CQLException, IOException {
// construct a (E)CQL filter from the search parameters,
// and use that as the basis for the query
Filter cqlFilter = CQL.toFilter(attributesQuery);
Query query = new Query(simpleFeatureTypeName, cqlFilter);
query.setPropertyNames(attributeFields);
query.setMaxFeatures(maxFeatures);
if (!sortByField.equals("")) {
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
SortBy[] sort = new SortBy[]{ff.sort(sortByField, SortOrder.DESCENDING)};
query.setSortBy(sort);
}
// submit the query, and get back an iterator over matching features
FeatureSource featureSource = dataStore.getFeatureSource(simpleFeatureTypeName);
FeatureIterator featureItr = featureSource.getFeatures(query).features();
// loop through all results
int n = 0;
while (featureItr.hasNext()) {
Feature feature = featureItr.next();
StringBuilder sb = new StringBuilder();
sb.append("Feature ID ").append(feature.getIdentifier());
for (String field : attributeFields) {
sb.append(" | ").append(field).append(": ").append(feature.getProperty(field).getValue());
}
System.out.println(sb.toString());
}
featureItr.close();
}
示例3: testNaturalSortingAsc
import org.geotools.data.Query; //导入方法依赖的package包/类
@Test
public void testNaturalSortingAsc() throws Exception {
init();
Query q = new Query(featureSource.getSchema().getTypeName());
q.setSortBy(new SortBy[] { SortBy.NATURAL_ORDER });
SimpleFeatureIterator features = featureSource.getFeatures(q).features();
String prevId = null;
while (features.hasNext()) {
String currId = features.next().getID();
if (prevId != null)
assertTrue(prevId.compareTo(currId) <= 0);
prevId = currId;
}
features.close();
}
示例4: testNaturalSortingDesc
import org.geotools.data.Query; //导入方法依赖的package包/类
@Test
public void testNaturalSortingDesc() throws Exception {
init();
Query q = new Query(featureSource.getSchema().getTypeName());
q.setSortBy(new SortBy[] { SortBy.REVERSE_ORDER });
SimpleFeatureIterator features = featureSource.getFeatures(q).features();
String prevId = null;
while (features.hasNext()) {
String currId = features.next().getID();
if (prevId != null)
assertTrue(prevId.compareTo(currId) >= 0);
prevId = currId;
}
features.close();
}
示例5: testGetFeaturesWithSort
import org.geotools.data.Query; //导入方法依赖的package包/类
@Test
public void testGetFeaturesWithSort() throws Exception {
init();
FilterFactory ff = dataStore.getFilterFactory();
SortBy sort = ff.sort("vendor_s", SortOrder.ASCENDING);
Query query = new Query();
query.setSortBy(new SortBy[] { sort });
SimpleFeatureCollection features = featureSource.getFeatures(query);
assertEquals(11, features.size());
SimpleFeatureIterator iterator = features.features();
SimpleFeature f;
try {
assertTrue(iterator.hasNext());
f = iterator.next();
assertEquals("Asus", f.getAttribute("vendor_s"));
assertTrue(iterator.hasNext());
f = iterator.next();
assertEquals("Cisco", f.getAttribute("vendor_s"));
assertTrue(iterator.hasNext());
f = iterator.next();
assertEquals("Cisco", f.getAttribute("vendor_s"));
} finally {
iterator.close();
}
sort = ff.sort("vendor_s", SortOrder.DESCENDING);
query.setSortBy(new SortBy[] { sort });
features = featureSource.getFeatures(query);
iterator = features.features();
try {
assertTrue(iterator.hasNext());
f = iterator.next();
assertEquals("TP-Link", f.getAttribute("vendor_s"));
assertTrue(iterator.hasNext());
f = iterator.next();
assertEquals("Linksys", f.getAttribute("vendor_s"));
assertTrue(iterator.hasNext());
f = iterator.next();
assertEquals("Linksys", f.getAttribute("vendor_s"));
} finally {
iterator.close();
}
}