Java Code Examples for org.geotools.data.FeatureSource#getFeatures()
The following examples show how to use
org.geotools.data.FeatureSource#getFeatures() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeatureFigureEditorApp.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Override protected void loadFigureCollection(File file, FigureCollection figureCollection) throws IOException { FeatureSource<SimpleFeatureType, SimpleFeature> featureFeatureSource; FeatureCollection<SimpleFeatureType, SimpleFeature> featureTypeSimpleFeatureFeatureCollection; featureFeatureSource = getFeatureSource(file); featureTypeSimpleFeatureFeatureCollection = featureFeatureSource.getFeatures(); try(FeatureIterator<SimpleFeature> featureIterator = featureTypeSimpleFeatureFeatureCollection.features();) { while (featureIterator.hasNext()) { SimpleFeature simpleFeature = featureIterator.next(); DefaultFigureStyle figureStyle = createDefaultFigureStyle(); Object o = simpleFeature.getDefaultGeometry(); if (o instanceof Point) { figureCollection.addFigure(new SimpleFeaturePointFigure(simpleFeature, sceneTransformProvider, figureStyle)); } else { figureCollection.addFigure(new SimpleFeatureShapeFigure(simpleFeature, sceneTransformProvider, figureStyle)); } } } }
Example 2
Source File: ShpConnector.java From TripleGeo with GNU General Public License v3.0 | 6 votes |
/** * Loads the shape file from the configuration path and returns the * feature collection associated according to the configuration. * * @param shapePath with the path to the shapefile. * @param featureString with the featureString to filter. * * @return FeatureCollection with the collection of features filtered. */ private FeatureCollection getShapeFileFeatureCollection(String shapePath, String featureString) throws IOException { File file = new File(shapePath); // Create the map with the file URL to be passed to DataStore. Map map = new HashMap(); try { map.put("url", file.toURL()); } catch (MalformedURLException ex) { Logger.getLogger(ShpConnector.class.getName()).log(Level.SEVERE, null, ex); } if (map.size() > 0) { DataStore dataStore = DataStoreFinder.getDataStore(map); FeatureSource featureSource = dataStore.getFeatureSource(featureString); return featureSource.getFeatures(); } return null; }
Example 3
Source File: GeoToolsLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Override public Envelope getBounds(Filter filter) throws LayerException { FeatureSource<SimpleFeatureType, SimpleFeature> source = getFeatureSource(); if (source instanceof FeatureStore<?, ?>) { SimpleFeatureStore store = (SimpleFeatureStore) source; transactionSynchronization.synchTransaction(store); } try { FeatureCollection<SimpleFeatureType, SimpleFeature> fc; if (null == filter) { fc = source.getFeatures(); } else { fc = source.getFeatures(filter); } FeatureIterator<SimpleFeature> it = fc.features(); transactionSynchronization.addIterator(it); return fc.getBounds(); } catch (Throwable t) { // NOSONAR avoid errors (like NPE) as well throw new LayerException(t, ExceptionCode.UNEXPECTED_PROBLEM); } }
Example 4
Source File: GeoToolsLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
/** * {@inheritDoc} * */ @Transactional(readOnly = true) public Iterator<?> getElements(Filter filter, int offset, int maxResultSize) throws LayerException { FeatureSource<SimpleFeatureType, SimpleFeature> source = getFeatureSource(); try { if (source instanceof FeatureStore<?, ?>) { SimpleFeatureStore store = (SimpleFeatureStore) source; transactionSynchronization.synchTransaction(store); } Query query = new Query(); query.setFilter(filter); query.setMaxFeatures(maxResultSize > 0 ? maxResultSize : Integer.MAX_VALUE); query.setStartIndex(offset); FeatureCollection<SimpleFeatureType, SimpleFeature> fc = source.getFeatures(query); FeatureIterator<SimpleFeature> it = fc.features(); transactionSynchronization.addIterator(it); return new JavaIterator(it); } catch (Throwable t) { // NOSONAR avoid errors (like NPE) as well throw new LayerException(t, ExceptionCode.UNEXPECTED_PROBLEM); } }