Package org.geotools.feature.visitor

Examples of org.geotools.feature.visitor.CountVisitor


            feat.setAttribute("the_geom", GEOM_FACTORY.toGeometry(referencedEnvelope));
            sliceCat.addGranule("1", feat, t);
            t.commit();

            // read back
            CountVisitor cv = new CountVisitor();
            Query q = new Query("1");
            q.setFilter(Filter.INCLUDE);
            sliceCat.computeAggregateFunction(q, cv);
            assertEquals(2, cv.getCount());

            // create new schema 2
            final String schemaDef2 = "the_geom:Polygon,coverage:String,imageindex:Integer,new:Double";
            sliceCat.createType("2", schemaDef2);
            typeNames = sliceCat.getTypeNames();
            assertNotNull(typeNames);
            assertEquals(2, typeNames.length);

            // add features to it
            schema = DataUtilities.createType("2", schemaDef2);
            feat = DataUtilities.template(schema);
            feat.setAttribute("coverage", "b");
            feat.setAttribute("imageindex", Integer.valueOf(0));
            feat.setAttribute("new", Double.valueOf(3.22));
            feat.setAttribute("the_geom", GEOM_FACTORY.toGeometry(referencedEnvelope));
            sliceCat.addGranule("2", feat, t);

            feat = DataUtilities.template(schema);
            feat.setAttribute("coverage", "b");
            feat.setAttribute("imageindex", Integer.valueOf(1));
            feat.setAttribute("new", Double.valueOf(1.12));
            feat.setAttribute("the_geom", GEOM_FACTORY.toGeometry(referencedEnvelope));
            sliceCat.addGranule("2", feat, t);

            feat = DataUtilities.template(schema);
            feat.setAttribute("coverage", "b");
            feat.setAttribute("imageindex", Integer.valueOf(2));
            feat.setAttribute("new", Double.valueOf(1.32));
            feat.setAttribute("the_geom", GEOM_FACTORY.toGeometry(referencedEnvelope));
            sliceCat.addGranule("2", feat, t);

            t.commit();

            // read back
            cv = new CountVisitor();
            q = new Query("2");
            q.setFilter(Filter.INCLUDE);
            sliceCat.computeAggregateFunction(q, cv);
            assertEquals(3, cv.getCount());
           
            // Get the CoverageSlices
            List<CoverageSlice> slices = sliceCat.getGranules(q);
            double[] news = new double[]{3.22, 1.12, 1.32};
            for(int i = 0; i < news.length; i++){
                CoverageSlice slice = slices.get(i);
                assertTrue(slice.getGranuleBBOX().contains(referencedEnvelope));
                double newAttr = (double) slice.getOriginator().getAttribute("new");
                assertEquals(newAttr, news[i], DELTA);
            }
           
            // Creating a CoverageSliceCatalogSource and check if it behaves correctly
            CoverageSlicesCatalogSource src = new CoverageSlicesCatalogSource(sliceCat, "2");
            assertEquals(3, src.getCount(q));
            SimpleFeatureCollection coll = src.getGranules(q);
            cv.reset();
            coll.accepts(cv, null);
            assertEquals(3, cv.getCount());
            assertTrue(src.getBounds(q).contains(
                    referencedEnvelope.toBounds(referencedEnvelope.getCoordinateReferenceSystem())));
            assertEquals(src.getSchema(), schema);

            // remove
            sliceCat.removeGranules("1", Filter.INCLUDE, t);
            sliceCat.removeGranules("2", Filter.INCLUDE, t);
            t.commit();
            // check
            q = new Query("1");
            q.setFilter(Filter.INCLUDE);
            sliceCat.computeAggregateFunction(q, cv);
            assertEquals(0, cv.getCount());
            q = new Query("2");
            sliceCat.computeAggregateFunction(q, cv);
            assertEquals(0, cv.getCount());

        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            t.rollback();
        } finally {
View Full Code Here


     * Returns the count of the features for a particular feature type / table.
     */
    protected int getCount(SimpleFeatureType featureType, Query query, Connection cx)
        throws IOException {
       
        CountVisitor v = new CountVisitor();
        getAggregateValue(v,featureType,query,cx);
        return v.getCount();
    }
View Full Code Here

        for (AggregationFunction function : functionList) {
            FeatureCalc calc;
            if (function == AggregationFunction.Average) {
                calc = new AverageVisitor(attIndex, features.getSchema());
            } else if (function == AggregationFunction.Count) {
                calc = new CountVisitor();
            } else if (function == AggregationFunction.Max) {
                calc = new MaxVisitor(attIndex, features.getSchema());
            } else if (function == AggregationFunction.Median) {
                calc = new MedianVisitor(attIndex, features.getSchema());
            } else if (function == AggregationFunction.Min) {
View Full Code Here

   * @throws IllegalFilterException
   * @throws IOException
   */
  static CalcResult calculateCount(SimpleFeatureCollection collection)
      throws IllegalFilterException, IOException {
    CountVisitor countVisitor = new CountVisitor();
    collection.accepts(countVisitor, null);
    return countVisitor.getResult();
  }
View Full Code Here

        for (AggregationFunction function : functionList) {
            FeatureCalc calc;
            if (function == AggregationFunction.Average) {
                calc = new AverageVisitor(attIndex, features.getSchema());
            } else if (function == AggregationFunction.Count) {
                calc = new CountVisitor();
            } else if (function == AggregationFunction.Max) {
                calc = new MaxVisitor(attIndex, features.getSchema());
            } else if (function == AggregationFunction.Median) {
                calc = new MedianVisitor(attIndex, features.getSchema());
            } else if (function == AggregationFunction.Min) {
View Full Code Here

TOP

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

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.