Java Code Examples for org.geotools.data.simple.SimpleFeatureIterator#next()
The following examples show how to use
org.geotools.data.simple.SimpleFeatureIterator#next() .
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: FeatureUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Extracts features from a {@link FeatureCollection} into an {@link STRtree}. * * @param collection the feature collection. * @return the tree containing the features. */ public static STRtree featureCollectionToSTRtree( SimpleFeatureCollection collection ) { STRtree tree = new STRtree(); SimpleFeatureIterator featureIterator = collection.features(); while( featureIterator.hasNext() ) { SimpleFeature feature = featureIterator.next(); Geometry geometry = (Geometry) feature.getDefaultGeometry(); tree.insert(geometry.getEnvelopeInternal(), feature); } featureIterator.close(); return tree; }
Example 2
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testOnlySourceFields() throws Exception { init(); Name name = new NameImpl("active"); for (final ElasticAttribute attribute : dataStore.getElasticAttributes(name) ){ if (attribute.isStored()) { attribute.setUse(false); } } featureSource = (ElasticFeatureSource) dataStore.getFeatureSource(TYPE_NAME); assertEquals(11, featureSource.getCount(Query.ALL)); SimpleFeatureIterator features = featureSource.getFeatures().features(); for (int i=0; i<11; i++) { assertTrue(features.hasNext()); features.next(); } }
Example 3
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testOnlyStoredFields() throws Exception { init(); Name name = new NameImpl("active"); for (final ElasticAttribute attribute : dataStore.getElasticAttributes(name) ){ if (!attribute.isStored()) { attribute.setUse(false); } } assertEquals(11, featureSource.getCount(Query.ALL)); SimpleFeatureIterator features = featureSource.getFeatures().features(); for (int i=0; i<11; i++) { assertTrue(features.hasNext()); features.next(); } }
Example 4
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testOnlyStoredFieldsWithSourceFiltering() throws Exception { init(); dataStore.setSourceFilteringEnabled(true); Name name = new NameImpl("active"); for (final ElasticAttribute attribute : dataStore.getElasticAttributes(name) ){ if (!attribute.isStored()) { attribute.setUse(false); } } assertEquals(11, featureSource.getCount(Query.ALL)); SimpleFeatureIterator features = featureSource.getFeatures().features(); for (int i=0; i<11; i++) { assertTrue(features.hasNext()); features.next(); } }
Example 5
Source File: TestUtils.java From geowave with Apache License 2.0 | 6 votes |
public static SimpleFeature resourceToFeature(final URL filterResource) throws IOException { final Map<String, Object> map = new HashMap<>(); DataStore dataStore = null; map.put("url", filterResource); final SimpleFeature savedFilter; SimpleFeatureIterator sfi = null; try { dataStore = DataStoreFinder.getDataStore(map); if (dataStore == null) { LOGGER.error("Could not get dataStore instance, getDataStore returned null"); throw new IOException("Could not get dataStore instance, getDataStore returned null"); } // just grab the first feature and use it as a filter sfi = dataStore.getFeatureSource(dataStore.getNames().get(0)).getFeatures().features(); savedFilter = sfi.next(); } finally { if (sfi != null) { sfi.close(); } if (dataStore != null) { dataStore.dispose(); } } return savedFilter; }
Example 6
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testOnlySourceFieldsWithSourceFiltering() throws Exception { init(); dataStore.setSourceFilteringEnabled(true); Name name = new NameImpl("active"); for (final ElasticAttribute attribute : dataStore.getElasticAttributes(name) ){ if (attribute.isStored()) { attribute.setUse(false); } } featureSource = (ElasticFeatureSource) dataStore.getFeatureSource(TYPE_NAME); assertEquals(11, featureSource.getCount(Query.ALL)); SimpleFeatureIterator features = featureSource.getFeatures().features(); for (int i=0; i<11; i++) { assertTrue(features.hasNext()); features.next(); } }
Example 7
Source File: FeatureUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Extracts features from a {@link FeatureCollection} into an {@link ArrayList}. * * @param collection the feature collection. * @return the list with the features or an empty list if no features present. */ public static List<SimpleFeature> featureCollectionToList( SimpleFeatureCollection collection ) { List<SimpleFeature> featuresList = new ArrayList<SimpleFeature>(); if (collection == null) { return featuresList; } SimpleFeatureIterator featureIterator = collection.features(); while( featureIterator.hasNext() ) { SimpleFeature feature = featureIterator.next(); featuresList.add(feature); } featureIterator.close(); return featuresList; }
Example 8
Source File: InlineFeatureUtils.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Determine geometry type. * * @param geometryDescriptor the geometry descriptor * @param simpleFeatureCollection the simple feature collection * @return the geometry type enum */ public static GeometryTypeEnum determineGeometryType( GeometryDescriptor geometryDescriptor, SimpleFeatureCollection simpleFeatureCollection) { if (geometryDescriptor == null) { return GeometryTypeEnum.UNKNOWN; } if (simpleFeatureCollection == null) { return GeometryTypeEnum.UNKNOWN; } Class<?> bindingType = geometryDescriptor.getType().getBinding(); if (bindingType == Geometry.class) { Name geometryName = geometryDescriptor.getName(); SimpleFeatureIterator iterator = simpleFeatureCollection.features(); List<GeometryTypeEnum> geometryFeatures = new ArrayList<>(); while (iterator.hasNext()) { SimpleFeature feature = iterator.next(); Object value = feature.getAttribute(geometryName); if (value != null) { GeometryTypeEnum geometryType = GeometryTypeMapping.getGeometryType(value.getClass()); if (!geometryFeatures.contains(geometryType)) { geometryFeatures.add(geometryType); } } } return (combineGeometryType(geometryFeatures)); } else { return GeometryTypeMapping.getGeometryType(bindingType); } }
Example 9
Source File: StyleGenerator.java From constellation with Apache License 2.0 | 5 votes |
private static Style createPolygonStyle(final SimpleFeatureCollection features) { // get name based rule names final List<Rule> ruleList = new ArrayList<>(); final Set<String> nameSet = new HashSet<>(); // setup custom rules for polygons final SimpleFeatureIterator featureIterator = features.features(); while (featureIterator.hasNext()) { final SimpleFeature feature = featureIterator.next(); if (nameSet.add((String) feature.getAttribute(ATTRIBUTE))) { ruleList.add(makeFillRule(feature)); } } // create a partially opaque outline stroke final Rule defaultRule = makeFillRule(); defaultRule.setElseFilter(true); defaultRule.setName("Default Rule"); ruleList.add(defaultRule); // Create rule defined style final Rule[] rules = ruleList.toArray(new Rule[ruleList.size()]); final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(); final FeatureTypeStyle featureTypeStyle = styleFactory.createFeatureTypeStyle(rules); final StyleBuilder builder = new StyleBuilder(); final Style style = builder.createStyle(); style.getDescription().setTitle("Polygon Style"); style.featureTypeStyles().add(featureTypeStyle); return style; }
Example 10
Source File: FeatureCollectionPolygonLayer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void run() { removeAllRenderables(); SimpleFeatureIterator featureIterator = featureCollectionLL.features(); while( featureIterator.hasNext() ) { SimpleFeature polygonAreaFeature = featureIterator.next(); if (mApplyExtrusion && (mHeightFieldName != null || mHasConstantHeight)) { addExtrudedPolygon(polygonAreaFeature); } else { addPolygon(polygonAreaFeature); } } featureIterator.close(); }
Example 11
Source File: FeatureUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Extracts features from a {@link FeatureCollection} into an {@link ArrayList} of {@link FeatureMate}s. * * @param collection the feature collection. * @return the list with the features or an empty list if no features present. */ public static List<FeatureMate> featureCollectionToMatesList( SimpleFeatureCollection collection ) { List<FeatureMate> featuresList = new ArrayList<FeatureMate>(); if (collection == null) { return featuresList; } SimpleFeatureIterator featureIterator = collection.features(); while( featureIterator.hasNext() ) { SimpleFeature feature = featureIterator.next(); featuresList.add(new FeatureMate(feature)); } featureIterator.close(); return featuresList; }
Example 12
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
private void assertCovered(SimpleFeatureCollection features, Integer... ids) { assertEquals(ids.length, features.size()); Set<Integer> s = new HashSet<>(Arrays.asList(ids)); SimpleFeatureIterator it = features.features(); while (it.hasNext()) { SimpleFeature f = it.next(); s.remove(Integer.parseInt(f.getAttribute("id").toString())); } assertTrue(s.isEmpty()); }
Example 13
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@Test public void testGetFeaturesWithNOTLogicFilter() throws Exception { init(); FilterFactory ff = dataStore.getFilterFactory(); PropertyIsEqualTo property1 = ff.equals(ff.property("vendor_s"), ff.literal("D-Link")); Not filter = ff.not(property1); SimpleFeatureCollection features = featureSource.getFeatures(filter); assertEquals(7, features.size()); SimpleFeatureIterator iterator = features.features(); while (iterator.hasNext()) { SimpleFeature f = iterator.next(); assertTrue(!f.getAttribute("vendor_s").equals("D-Link")); } }
Example 14
Source File: OmsVectorMerger.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
@Execute public void process() throws Exception { checkNull(inVectors); SimpleFeatureType firstType = null; FeatureExtender fEx = null; pm.beginTask("Merging features...", inVectors.size()); try { outVector = new DefaultFeatureCollection(); for( SimpleFeatureCollection featureCollection : inVectors ) { if (firstType == null) { firstType = featureCollection.getSchema(); fEx = new FeatureExtender(firstType, new String[0], new Class< ? >[0]); } else { SimpleFeatureType schema = featureCollection.getSchema(); int compare = DataUtilities.compare(firstType, schema); if (compare != 0) { throw new ModelsIllegalargumentException("Merging is done only on same feature types.", this, pm); } } SimpleFeatureIterator featureIterator = featureCollection.features(); while( featureIterator.hasNext() ) { SimpleFeature f = featureIterator.next(); SimpleFeature extendFeature = fEx.extendFeature(f, new Object[0]); ((DefaultFeatureCollection) outVector).add(extendFeature); } pm.worked(1); } } finally { pm.done(); } }
Example 15
Source File: InLineFeatureModel.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Removes the column. * * @param columnName the column name */ public void removeColumn(String columnName) { if (featureCollection != null) { if (columnList.contains(columnName)) { columnList.remove(columnName); // Find field name to remote SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder(); featureTypeBuilder.init(featureCollection.getSchema()); featureTypeBuilder.remove(columnName); SimpleFeatureType newFeatureType = featureTypeBuilder.buildFeatureType(); int attributeToRemoveIndex = 0; for (AttributeDescriptor descriptor : newFeatureType.getAttributeDescriptors()) { if (descriptor.getLocalName().compareTo(columnName) == 0) { break; } attributeToRemoveIndex++; } String typeName = userLayer.getInlineFeatureType().getTypeName(); try { SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore().getFeatureSource(typeName); SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType); ArrayList<SimpleFeature> featureList = new ArrayList<>(); SimpleFeatureIterator it = featureSource.getFeatures().features(); try { while (it.hasNext()) { SimpleFeature sf = it.next(); List<Object> attributes = sf.getAttributes(); attributes.remove(attributeToRemoveIndex); sfb.addAll(attributes); featureList.add(sfb.buildFeature(null)); } } finally { it.close(); } SimpleFeatureCollection collection = new ListFeatureCollection(newFeatureType, featureList); featureCollection = collection; cachedFeature = null; lastRow = -1; DataStore dataStore = DataUtilities.dataStore(collection); userLayer.setInlineFeatureDatastore(dataStore); userLayer.setInlineFeatureType(newFeatureType); } catch (IOException e) { ConsoleManager.getInstance().exception(this, e); } this.fireTableStructureChanged(); this.fireTableDataChanged(); if (parentObj != null) { parentObj.inlineFeatureUpdated(); } } } }
Example 16
Source File: InLineFeatureModel.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Update CRS. * * @param selectedValue the selected value */ public void updateCRS(ValueComboBoxData selectedValue) { if (selectedValue != null) { String crsCode = selectedValue.getKey(); CoordinateReferenceSystem newCRS = CoordManager.getInstance().getCRS(crsCode); SimpleFeatureType newFeatureType = SimpleFeatureTypeBuilder.retype(featureCollection.getSchema(), newCRS); String typeName = userLayer.getInlineFeatureType().getTypeName(); try { SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore().getFeatureSource(typeName); SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType); ArrayList<SimpleFeature> featureList = new ArrayList<>(); SimpleFeatureIterator it = featureSource.getFeatures().features(); try { while (it.hasNext()) { SimpleFeature sf = it.next(); List<Object> attributeValueList = sf.getAttributes(); sfb.addAll(attributeValueList); featureList.add(sfb.buildFeature(null)); } } finally { it.close(); } SimpleFeatureCollection collection = new ListFeatureCollection(newFeatureType, featureList); featureCollection = collection; cachedFeature = null; lastRow = -1; DataStore dataStore = DataUtilities.dataStore(collection); userLayer.setInlineFeatureDatastore(dataStore); userLayer.setInlineFeatureType(newFeatureType); } catch (IOException e) { ConsoleManager.getInstance().exception(this, e); } this.fireTableStructureChanged(); this.fireTableDataChanged(); if (parentObj != null) { parentObj.inlineFeatureUpdated(); } } }
Example 17
Source File: InLineFeatureModel.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** Adds the new feature. */ public void addNewFeature() { SimpleFeatureType featureType = userLayer.getInlineFeatureType(); String typeName = userLayer.getInlineFeatureType().getTypeName(); try { SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore().getFeatureSource(typeName); SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(featureType); ArrayList<SimpleFeature> featureList = new ArrayList<>(); SimpleFeatureIterator it = featureSource.getFeatures().features(); try { while (it.hasNext()) { SimpleFeature sf = it.next(); List<Object> attributeValueList = sf.getAttributes(); sfb.addAll(attributeValueList); featureList.add(sfb.buildFeature(null)); } // Add new feature String wktString = "wkt://POINT(0 0)"; Geometry geometry = WKTConversion.convertToGeometry(wktString, getSelectedCRSCode()); sfb.add(geometry); featureList.add(sfb.buildFeature(null)); } finally { it.close(); } SimpleFeatureCollection collection = new ListFeatureCollection(featureType, featureList); featureCollection = collection; cachedFeature = null; lastRow = -1; DataStore dataStore = DataUtilities.dataStore(collection); userLayer.setInlineFeatureDatastore(dataStore); } catch (IOException e) { ConsoleManager.getInstance().exception(this, e); } this.fireTableStructureChanged(); this.fireTableDataChanged(); if (parentObj != null) { parentObj.inlineFeatureUpdated(); } }
Example 18
Source File: OmsTrentoPProjectFilesGenerator.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
private SimpleFeatureCollection createNewCollection( SimpleFeatureType simpleFeatureType ) { DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(); SimpleFeatureIterator stationsIter = pOldVector.features(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(simpleFeatureType); // create the features. try { while( stationsIter.hasNext() ) { SimpleFeature networkFeature = stationsIter.next(); try { // add the geometry. builder.add(networkFeature.getDefaultGeometry()); // add the ID. Integer field = ((Integer) networkFeature.getAttribute(TrentoPFeatureType.ID_STR)); if (field == null) { throw new IllegalArgumentException(); } builder.add(field); // add the area. Double value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.DRAIN_AREA_STR)); if (value == null) { throw new IllegalArgumentException(); } builder.add(value); // add the percentage of the area which is dry. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.PERCENTAGE_OF_DRY_AREA)); builder.add(value); // the pipes elevation is the elevation of the // terrain minus the depth. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.DEPTH_INITIAL_PIPE_STR)); builder.add(value); // the pipes elevation is the elevation of the // terrain minus the depth. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.DEPTH_FINAL_PIPE_STR)); builder.add(value); // add the runoff coefficent. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.RUNOFF_COEFFICIENT_STR)); builder.add(value); // add the average residence time. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.AVERAGE_RESIDENCE_TIME_STR)); builder.add(value); // add the ks. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.KS_STR)); builder.add(value); // add the average slope. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.AVERAGE_SLOPE_STR)); builder.add(value); // add the diameters. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.DIAMETER_STR)); builder.add(value); // build the feature SimpleFeature feature = builder.buildFeature(null); featureCollection.add(feature); } catch (NullPointerException e) { throw new IllegalArgumentException(); } } } finally { stationsIter.close(); } return featureCollection; }
Example 19
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 4 votes |
@Test public void testGetFeaturesWithSort() throws Exception { init(); FilterFactory ff = dataStore.getFilterFactory(); SortBy sort = ff.sort("vendor_s", SortOrder.ASCENDING); Query query = new Query(); query.setSortBy(new SortBy[] { sort }); SimpleFeatureCollection features = featureSource.getFeatures(query); assertEquals(11, features.size()); SimpleFeatureIterator iterator = features.features(); SimpleFeature f; try { assertTrue(iterator.hasNext()); f = iterator.next(); assertEquals("Asus", f.getAttribute("vendor_s")); assertTrue(iterator.hasNext()); f = iterator.next(); assertEquals("Cisco", f.getAttribute("vendor_s")); assertTrue(iterator.hasNext()); f = iterator.next(); assertEquals("Cisco", f.getAttribute("vendor_s")); } finally { iterator.close(); } sort = ff.sort("vendor_s", SortOrder.DESCENDING); query.setSortBy(new SortBy[] { sort }); features = featureSource.getFeatures(query); iterator = features.features(); try { assertTrue(iterator.hasNext()); f = iterator.next(); assertEquals("TP-Link", f.getAttribute("vendor_s")); assertTrue(iterator.hasNext()); f = iterator.next(); assertEquals("Linksys", f.getAttribute("vendor_s")); assertTrue(iterator.hasNext()); f = iterator.next(); assertEquals("Linksys", f.getAttribute("vendor_s")); } finally { iterator.close(); } }
Example 20
Source File: WRS2GeometryStore.java From geowave with Apache License 2.0 | 4 votes |
private void init() throws MalformedURLException, IOException { if (!wrs2Shape.exists()) { if (!wrs2Directory.delete()) { LOGGER.warn("Unable to delete '" + wrs2Directory.getAbsolutePath() + "'"); } final File wsDir = wrs2Directory.getParentFile(); if (!wsDir.exists() && !wsDir.mkdirs()) { LOGGER.warn("Unable to create directory '" + wsDir.getAbsolutePath() + "'"); } if (!wrs2Directory.mkdirs()) { LOGGER.warn("Unable to create directory '" + wrs2Directory.getAbsolutePath() + "'"); } // download and unzip the shapefile final File targetFile = new File(wrs2Directory, WRS2_SHAPE_ZIP); if (targetFile.exists()) { if (!targetFile.delete()) { LOGGER.warn("Unable to delete file '" + targetFile.getAbsolutePath() + "'"); } } FileUtils.copyURLToFile(new URL(WRS2_SHAPE_URL), targetFile); final ZipFile zipFile = new ZipFile(targetFile); try { final Enumeration<ZipArchiveEntry> entries = zipFile.getEntries(); while (entries.hasMoreElements()) { final ZipArchiveEntry entry = entries.nextElement(); if (!entry.isDirectory()) { FileUtils.copyInputStreamToFile( zipFile.getInputStream(entry), new File(wrs2Directory, entry.getName())); // HP Fortify "Path Traversal" false positive // What Fortify considers "user input" comes only // from users with OS-level access anyway } } } finally { zipFile.close(); } } // read the shapefile and cache the features for quick lookup by path // and row try { final Map<String, Object> map = new HashMap<>(); map.put("url", wrs2Shape.toURI().toURL()); final DataStore dataStore = DataStoreFinder.getDataStore(map); if (dataStore == null) { LOGGER.error("Unable to get a datastore instance, getDataStore returned null"); return; } final SimpleFeatureSource source = dataStore.getFeatureSource(WRS2_TYPE_NAME); final SimpleFeatureCollection featureCollection = source.getFeatures(); wrs2Type = featureCollection.getSchema(); final SimpleFeatureIterator iterator = featureCollection.features(); while (iterator.hasNext()) { final SimpleFeature feature = iterator.next(); final Number path = (Number) feature.getAttribute("PATH"); final Number row = (Number) feature.getAttribute("ROW"); featureCache.put( new WRS2Key(path.intValue(), row.intValue()), (MultiPolygon) feature.getDefaultGeometry()); } } catch (final IOException e) { LOGGER.error( "Unable to read wrs2_asc_desc shapefile '" + wrs2Shape.getAbsolutePath() + "'", e); throw (e); } }