Package org.geotools.feature.visitor

Examples of org.geotools.feature.visitor.UniqueVisitor


   
    public void testUniqueWithFilter() throws Exception {
        FilterFactory ff = dataStore.getFilterFactory();
        PropertyName p = ff.property( aname("stringProperty") );
       
        UniqueVisitor v = new MyUniqueVisitor(p);
        Filter f = ff.greater( ff.property( aname("doubleProperty") ), ff.literal(1) );
        Query q = new Query( tname("ft1"), f);
        dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null);
        assertFalse(visited);
        Set result = v.getResult().toSet();
        assertEquals(2, result.size());
        assertTrue(result.contains("one"));
        assertTrue(result.contains("two"));
    }
View Full Code Here


        }
       
        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());
    }
View Full Code Here

        }
       
        FilterFactory ff = dataStore.getFilterFactory();
        PropertyName p = ff.property( aname("stringProperty") );
       
        UniqueVisitor v = new MyUniqueVisitor(p);
        v.setPreserveOrder(true);
        v.setStartIndex(0);
        v.setMaxFeatures(2);
        Query q = new Query( tname("ft1"));
        q.setSortBy(new SortBy[] { new SortByImpl(p, SortOrder.ASCENDING)});
        dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null);
        assertFalse(visited);
        Set result = v.getResult().toSet();
        assertEquals(2, result.size());
        assertEquals("one", result.iterator().next());
    }
View Full Code Here

        }
       
        FilterFactory ff = dataStore.getFilterFactory();
        PropertyName p = ff.property( aname("stringProperty") );
       
        UniqueVisitor v = new MyUniqueVisitor(p);
        v.setPreserveOrder(true);
        v.setStartIndex(1);
        v.setMaxFeatures(2);
        Query q = new Query( tname("ft1"));
        q.setSortBy(new SortBy[] { new SortByImpl(p, SortOrder.ASCENDING)});
        dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null);
        assertFalse(visited);
        Set result = v.getResult().toSet();
        assertEquals(2, result.size());
        assertEquals("two", result.iterator().next());
    }
View Full Code Here

    }
   
    @SuppressWarnings("unchecked")
    private RangedClassifier calculateNonNumerical(int classNum, FeatureCollection<?,?> featureCollection) throws IOException {
        //obtain of list of unique values, so we can enumerate
        UniqueVisitor uniqueVisit = new UniqueVisitor(getParameters().get(0));
        featureCollection.accepts(uniqueVisit, new NullProgressListener());
        List result = uniqueVisit.getResult().toList();
        //sort the results and put them in an array
        Collections.sort(result);
       
        Comparable[] values = (Comparable[]) result.toArray(new Comparable[result.size()]);
       
View Full Code Here

                attIndex = i;
                break;
            }
        }

        UniqueVisitor visitor = new UniqueVisitor(attIndex, features.getSchema());
        features.accepts(visitor, progressListener);
        List uniqueValues = visitor.getResult().toList();

        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        tb.add("value", features.getSchema().getDescriptor(attIndex).getType().getBinding());
        tb.setName("UniqueValue");
        SimpleFeatureType ft = tb.buildFeatureType();
View Full Code Here

        String featureTypeName = featureType.getTypeName();
        LOGGER.fine("PagedUnique process called on resource: " + featureTypeName
                + " - field: " + fieldName);
   
       
        UniqueVisitor visitor = new UniqueVisitor(FF.property(fieldName));
   
   
        Integer listSize = 0;
        List<String> list = new ArrayList<String>();
   
        try {
            // counts total elements
            features.accepts(visitor, null);
            if(visitor.getResult() == null || visitor.getResult().toList() == null) {
                listSize = 0;
                list = new ArrayList<String>(0);
            } else {
                listSize = visitor.getResult().toList().size();
                if(maxFeatures == null || maxFeatures > listSize) {
                    maxFeatures = listSize;
                }
                // Reset visitor and set pagination
                visitor.reset();
                if(startIndex != null) {
                    visitor.setStartIndex(startIndex);
                }
                if(maxFeatures != null) {
                    visitor.setMaxFeatures(maxFeatures);
                }
                visitor.setPreserveOrder(true);
           
                features.accepts(visitor, null);
                if(visitor.getResult() == null || visitor.getResult().toList() == null) {
                    list = new ArrayList<String>(0);
                } else {
                    list = visitor.getResult().toList();
                }
           
            }
            return new Results(featureTypeName, fieldName, listSize, list);
        } catch (Exception e) {
View Full Code Here

        FeatureCollection collection = getDimensionCollection(typeInfo, time);

        TreeSet<Date> result = new TreeSet<Date>();
        if (time.getPresentation() == DimensionPresentation.LIST) {
            final UniqueVisitor visitor = new UniqueVisitor(time.getAttribute());
            collection.accepts(visitor, null);

            @SuppressWarnings("unchecked")
            Set<Date> values = visitor.getUnique();
            if (values.size() <= 0) {
                result = null;
            } else {
                // we might get null values out of the visitor, strip them
                values.remove(null);
View Full Code Here

        TreeSet<Double> result = new TreeSet<Double>();
        if (elevation.getPresentation() == DimensionPresentation.LIST
                || (elevation.getPresentation() == DimensionPresentation.DISCRETE_INTERVAL && elevation
                        .getResolution() == null)) {
            final UniqueVisitor visitor = new UniqueVisitor(elevation.getAttribute());
            collection.accepts(visitor, null);

            @SuppressWarnings("unchecked")
            Set<Object> values = visitor.getUnique();
            if (values.size() <= 0) {
                result = null;
            } else {
                for (Object value : values) {
                    result.add(((Number) value).doubleValue());
View Full Code Here

TOP

Related Classes of org.geotools.feature.visitor.UniqueVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.