@Test public void testAttributeReaderIndexed() throws IOException { URL u = TestData.url(TestCaseSupport.class, SHPFILE); File shpFile = DataUtilities.urlToFile(u); // open the test shapefile // creates both indexed and regular shapefile data store ShapefileDataStore indexedstore = new ShapefileDataStore(shpFile.toURI().toURL()); // get a random feature id from one of the stores SimpleFeatureIterator it = indexedstore.getFeatureSource().getFeatures().features(); FeatureId fid = it.next().getIdentifier(); it.close(); // query the datastore FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); Filter idFilter = ff.id(Collections.singleton(fid)); final Query query = new Query( indexedstore.getSchema().getName().getLocalPart(), idFilter, new String[] {testColumn}); final SimpleFeatureCollection indexedfeatures = indexedstore.getFeatureSource().getFeatures(query); // compare the results SimpleFeatureIterator indexIterator = indexedfeatures.features(); SimpleFeature indexedFeature = indexIterator.next(); indexIterator.close(); // get the value of the duplicate column & compare it against expectation assertEquals(expectedValue, indexedFeature.getAttribute(testColumn)); // cleanup indexedstore.dispose(); }
@Test public void testAttributeReader() throws IOException { URL u = TestData.url(TestCaseSupport.class, SHPFILE); File shpFile = DataUtilities.urlToFile(u); // open the test shapefile ShapefileDataStore store = new ShapefileDataStore(shpFile.toURI().toURL()); SimpleFeatureSource source = store.getFeatureSource(); // read the first feature SimpleFeatureIterator iter = source.getFeatures().features(); SimpleFeature feature = iter.next(); iter.close(); // get the value of the duplicate column & compare it against expectation assertEquals(expectedValue, feature.getAttribute(testColumn)); // cleanup store.dispose(); }