Package org.geotools.data

Examples of org.geotools.data.FeatureSource


            it.close();
        }
    }
   
    public void testGetFeatureById() throws Exception {
        FeatureSource fsView = dataStore.getFeatureSource("riverReducedPk");
        assertFalse(fsView instanceof FeatureStore);
       
        // the problem is actually in pk computation
        PrimaryKey pk = dataStore.getPrimaryKey((SimpleFeatureType) fsView.getSchema());
        assertEquals("riverReducedPk", pk.getTableName());
        assertEquals(1, pk.getColumns().size());
        PrimaryKeyColumn col = pk.getColumns().get(0);
        assertEquals(aname("id"), col.getName());
        assertTrue(Number.class.isAssignableFrom(col.getType()));
       
        FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
        Id filter = ff.id(Collections.singleton(ff.featureId("riverReducedPk.0")));
       
        assertEquals(1, fsView.getCount(new Query(null, filter)));
    }
View Full Code Here


       
        assertEquals(1, fsView.getCount(new Query(null, filter)));
    }
   
    public void testWhereParam() throws Exception {
        FeatureSource fsView = dataStore.getFeatureSource("riverParam");
       
        // by default we get everything
        assertEquals(2, fsView.getCount(Query.ALL));
       
        // let's try filtering a bit dynamically
        Query q = new Query(Query.ALL);
        StringBuffer sb = new StringBuffer();
        sb.append(" where ");
        dialect.encodeColumnName(aname("flow"), sb);
        sb.append(" > 4")
        q.setHints(new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, Collections.singletonMap("where", sb.toString())));
        assertEquals(1, fsView.getCount(q));
    }
View Full Code Here

        assertEquals(1, fsView.getCount(q));
    }
   
    public void testMulParamValid() throws Exception {
        FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
        FeatureSource fsView = dataStore.getFeatureSource("riverParam");
       
        // let's change the mul param
        Query q = new Query(Query.ALL);
        q.setHints(new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, Collections.singletonMap("mul", "10")));
        q.setSortBy(new SortBy[] {ff.sort(aname("mulflow"), SortOrder.ASCENDING)});
        FeatureIterator fi = null;
        try {
            fi = fsView.getFeatures(q).features();
            assertTrue(fi.hasNext());
            SimpleFeature f = (SimpleFeature) fi.next();
            assertEquals(30.0, ((Number) f.getAttribute(aname("mulflow"))).doubleValue(), 0.1);
            assertTrue(fi.hasNext());
            f = (SimpleFeature) fi.next();
View Full Code Here

        }
       
    }
   
    public void testMulParamInvalid() throws Exception {
        FeatureSource fsView = dataStore.getFeatureSource("riverParam");
       
        // let's set an invalid mul param
        Query q = new Query(Query.ALL);
        q.setHints(new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, Collections.singletonMap("mul", "abc")));
        try {
            fsView.getFeatures(q).features();
            fail("Should have thrown an exception!");
        } catch(Exception e) {
            // fine
        }
    }
View Full Code Here

    @Override
    protected abstract JDBCEmptyTestSetup createTestSetup();
   
    public void testFeatureSource() throws Exception {
       
        FeatureSource fs = dataStore.getFeatureSource( tname("empty") );
        assertNotNull(fs);
       
        ReferencedEnvelope bounds = fs.getBounds();
        assertTrue( bounds.isNull() );
       
        int count = fs.getCount( Query.ALL );
        assertEquals( 0, count );
    }
View Full Code Here

        int count = fs.getCount( Query.ALL );
        assertEquals( 0, count );
    }
   
    public void testFeatureCollection() throws Exception {
        FeatureSource fs = dataStore.getFeatureSource( tname("empty") );
        FeatureCollection features = fs.getFeatures();
       
        assertTrue( features.getBounds().isNull() );
        assertEquals( 0, features.size() );
       
        FeatureIterator i = features.features();
View Full Code Here

                filter = filterFactory.bbox(filterFactory.property(attrName), env);
            }

            Query query = new Query(null, filter);
            query.setCoordinateSystemReproject(getMapContent().getCoordinateReferenceSystem());
            FeatureSource featureSource = getLayer().getFeatureSource();
            Collection<PropertyDescriptor> descriptors = featureSource.getSchema().getDescriptors();

            FeatureCollection queryResult = featureSource.getFeatures(query);
            FeatureIterator iter = queryResult.features();

            try {
                while (iter.hasNext()) {
                    Feature f = iter.next();
View Full Code Here

    public void testEmpty() throws Exception {
        SimpleFeatureType type = DataUtilities.createType("namespace.typename",
        "name:String,id:0,geom:MultiLineString");
        MemoryDataStore memory = new MemoryDataStore( type );
       
        FeatureSource source = memory.getFeatureSource( "typename");
        assertEquals( 0, source.getCount(Query.ALL) );
       
    }
View Full Code Here

            public String getText( Object element ) {
                if (element instanceof Layer) {
                    Layer p = (Layer) element;
                    String title = p.getTitle();
                    if (title == null || title.length() == 0) {
                        @SuppressWarnings("rawtypes")
                        FeatureSource featureSource = p.getFeatureSource();
                        if (featureSource != null) {
                            title = featureSource.getName().getLocalPart().toString();
                        }
                    }
                    return title;
                }
                return null;
View Full Code Here

        assertEquals(fc.size(), c);
    }

    public void testAttributeFilters() throws Exception {
        OGRDataStore s = new OGRDataStore(getAbsolutePath(STATE_POP), null, null, ogr);
        FeatureSource fs = s.getFeatureSource(s.getTypeNames()[0]);
       
        // equality filter
        FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
        Filter f = ff.equal(ff.property("STATE_NAME"), ff.literal("New York"), true);
        assertEquals(1, fs.getFeatures(f).size());
       
        // greater than
        f = ff.greater(ff.property("PERSONS"), ff.literal(10000000));
        assertEquals(6, fs.getFeatures(f).size());
       
        // mix in a filter that cannot be encoded
        f = ff.and(f, ff.like(ff.property("STATE_NAME"), "C*"));
        assertEquals(1, fs.getFeatures(f).size());
    }
View Full Code Here

TOP

Related Classes of org.geotools.data.FeatureSource

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.