当前位置: 首页>>代码示例>>Java>>正文


Java Query.setSortBy方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:STEMLab,项目名称:geoserver-3d-extension,代码行数:45,代码来源:ISOGeoServerFeatureSource.java

示例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();
}
 
开发者ID:geomesa,项目名称:geomesa-tutorials,代码行数:41,代码来源:FeatureLevelVisibility.java

示例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();
}
 
开发者ID:ngageoint,项目名称:elasticgeo,代码行数:16,代码来源:ElasticFeatureFilterIT.java

示例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();
}
 
开发者ID:ngageoint,项目名称:elasticgeo,代码行数:16,代码来源:ElasticFeatureFilterIT.java

示例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();
    }
}
 
开发者ID:ngageoint,项目名称:elasticgeo,代码行数:46,代码来源:ElasticFeatureFilterIT.java


注:本文中的org.geotools.data.Query.setSortBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。