public int getCount(Query query) throws IOException { return delegate.getCount(query); }
public int getCount(Query query) throws IOException { return delegate.getCount(query); }
@Test public void testEmptyBounds() throws Exception { // test the bounds of a single point Catalog cat = getCatalog(); FeatureTypeInfo fti = cat.getFeatureTypeByName(toString(MockData.POINTS)); assertEquals( Point.class, fti.getFeatureType().getGeometryDescriptor().getType().getBinding()); assertEquals(1, fti.getFeatureSource(null, null).getCount(Query.ALL)); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getStoreByName(MockData.CGF_PREFIX, DataStoreInfo.class)); FeatureTypeInfo built = cb.buildFeatureType(fti.getQualifiedName()); cb.setupBounds(built); assertTrue(built.getNativeBoundingBox().getWidth() > 0); assertTrue(built.getNativeBoundingBox().getHeight() > 0); }
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)); }
public void testEmpty() throws Exception { SimpleFeatureType type = DataUtilities.createType( "namespace.typename", "name:String,id:0,geom:MultiLineString"); MemoryDataStore memory = new MemoryDataStore(type); FeatureSource<SimpleFeatureType, SimpleFeature> source = memory.getFeatureSource("typename"); assertEquals(0, source.getCount(Query.ALL)); }
private int countFeatures(AppSchemaDataAccess dS) throws Exception { // we need the feature type in order to query for the number of features Name[] dSNameArray = dS.getTypeNames(); String testType = dSNameArray[0].toString(); FeatureSource<FeatureType, Feature> featureSource = dS.getFeatureSourceByName(dSNameArray[0]); int numFeatures = featureSource.getCount(new Query(testType)); return numFeatures; }
/** * Gets the number of the features that would be returned by this query for the specified * feature type. * * <p>If getBounds(Query) returns <code>-1</code> due to expense consider using <code> * getFeatures(Query).getCount()</code> as a an alternative. * * @param targetQuery Contains the Filter and MaxFeatures to find the bounds for. * @return The number of Features provided by the Query or <code>-1</code> if count is too * expensive to calculate or any errors or occur. * @throws IOException * @throws IOException if there are errors getting the count */ protected int getCount(final Query targetQuery) throws IOException { final FeatureTypeMapping mapping = getMappingByNameOrElement(getName(targetQuery)); FeatureSource mappedSource = mapping.getSource(); // Wrap with JoiningJDBCFeatureSource like in DataAccessMappingFeatureIterator // this is so it'd use the splitFilter in JoiningJDBCFeatureSource // otherwise you'll get an error when it can't find complex attributes in the // simple feature source if (mappedSource instanceof JDBCFeatureSource) { mappedSource = new JoiningJDBCFeatureSource((JDBCFeatureSource) mappedSource); } else if (mappedSource instanceof JDBCFeatureStore) { mappedSource = new JoiningJDBCFeatureSource((JDBCFeatureStore) mappedSource); } Query unmappedQuery = unrollQuery(targetQuery, mapping); return mappedSource.getCount(unmappedQuery); }
@Override public int getCount(Query query) throws IOException { return source.getCount(query); }
@Override public int getCount(Query query) throws IOException { return source.getCount(query); }
"wrong number of records for " + zone.getDisplayName(), 2, fs.getCount(new Query(tname("dates"), f)));
public void testFilterByTime() throws Exception { FeatureSource fs = dataStore.getFeatureSource(tname("dates")); FilterFactory ff = dataStore.getFilterFactory(); // greather than or equal to Filter f = ff.greaterOrEqual(ff.property(aname("t")), ff.literal("13:10:12")); assertEquals(3, fs.getCount(new Query(tname("dates"), f))); f = ff.greaterOrEqual( ff.property(aname("t")), ff.literal(new SimpleDateFormat("ss:HH:mm").parse("12:13:10"))); assertEquals(3, fs.getCount(new Query(tname("dates"), f))); } }
public void testFilterByTimeStamp() throws Exception { FeatureSource fs = dataStore.getFeatureSource(tname("dates")); FilterFactory ff = dataStore.getFilterFactory(); // equal to Filter f = ff.equals(ff.property(aname("dt")), ff.literal("2009-06-28 15:12:41")); assertEquals(1, fs.getCount(new Query(tname("dates"), f))); f = ff.equals( ff.property(aname("dt")), ff.literal( new SimpleDateFormat("HH:mm:ss,dd-yyyy-MM") .parse("15:12:41,28-2009-06"))); assertEquals(1, fs.getCount(new Query(tname("dates"), f))); }
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); }
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))); }
private Integer collectionSize(@SuppressWarnings("rawtypes") FeatureSource featureSource) { final Integer collectionSize; { int fastCount; try { fastCount = featureSource.getCount(Query.ALL); } catch (IOException e) { throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_GET_FEATURES); } collectionSize = -1 == fastCount ? null : Integer.valueOf(fastCount); } return collectionSize; }
public void testGetFeatureId() throws Exception { FeatureSource fsView = dataStore.getFeatureSource("riverReducedPk"); assertFalse(fsView instanceof FeatureStore); assertEquals(1, fsView.getCount(Query.ALL)); try (FeatureIterator<SimpleFeature> it = fsView.getFeatures().features()) { assertTrue(it.hasNext()); SimpleFeature sf = it.next(); // check the primary key is build out of the fid attribute assertEquals("riverReducedPk.0", sf.getID()); } }
public void testListAll() throws Exception { FeatureSource fsView = dataStore.getFeatureSource("riverReduced"); assertFalse(fsView instanceof FeatureStore); assertEquals(1, fsView.getCount(Query.ALL)); try (FeatureIterator<SimpleFeature> it = fsView.getFeatures().features()) { assertTrue(it.hasNext()); SimpleFeature sf = it.next(); assertEquals("rv1", sf.getAttribute(aname("river"))); assertEquals(9.0, ((Number) sf.getAttribute(aname("doubleFlow"))).doubleValue(), 0.1); assertFalse(it.hasNext()); } }
/** Checks the setup did the expected job */ @Test public void testStoreSetup() throws Exception { FeatureTypeInfo tableTypeInfo = getCatalog().getFeatureTypeByName(tableTypeName); assertNotNull(tableTypeInfo); assertEquals(5, tableTypeInfo.getFeatureSource(null, null).getCount(Query.ALL)); FeatureTypeInfo viewTypeInfo = getCatalog().getFeatureTypeByName(viewTypeName); assertNotNull(viewTypeInfo); assertEquals(1, viewTypeInfo.getFeatureSource(null, null).getCount(Query.ALL)); }
@Test public void testSentinel1Granules() throws Exception { FeatureSource<FeatureType, Feature> featureSource = osAccess.getFeatureSource(new NameImpl(TEST_NAMESPACE, "SENTINEL1")); assertEquals(0, featureSource.getCount(Query.ALL)); FeatureCollection<FeatureType, Feature> fc = featureSource.getFeatures(); assertEquals(0, fc.size()); fc.accepts( f -> {}, null); // just check trying to scroll over the feature does not make it blow }
@Test public void testCustomProductClassGranules() throws Exception { FeatureSource<FeatureType, Feature> featureSource = osAccess.getFeatureSource(new NameImpl(TEST_NAMESPACE, "GS_TEST")); assertEquals(0, featureSource.getCount(Query.ALL)); FeatureCollection<FeatureType, Feature> fc = featureSource.getFeatures(); assertGranulesViewSchema(fc.getSchema(), GS_PRODUCT); assertEquals(0, fc.size()); fc.accepts( f -> {}, null); // just check trying to scroll over the feature does not make it blow }