Java Code Examples for org.geotools.data.simple.SimpleFeatureIterator#close()
The following examples show how to use
org.geotools.data.simple.SimpleFeatureIterator#close() .
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: FeatureCollectionLinesLayer.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void run() { try { removeAllRenderables(); SimpleFeatureIterator featureIterator = getfeatureCollection().features(); while( featureIterator.hasNext() ) { SimpleFeature lineFeature = featureIterator.next(); boolean doExtrude = false; if (mApplyExtrusion && (mHeightFieldName != null || mHasConstantHeight)) { doExtrude = true; } addLine(lineFeature, doExtrude); } featureIterator.close(); } catch (Exception e) { e.printStackTrace(); } }
Example 2
Source File: ElasticTemporalFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testLessDateFilterLong() throws Exception { init(); Date testDate = new Date(1005912798000L); FilterFactory ff = dataStore.getFilterFactory(); Filter f = ff.lessOrEqual(ff.property("installed_td"), ff.literal(testDate.getTime())); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(4, features.size()); SimpleFeatureIterator it = features.features(); while (it.hasNext()) { SimpleFeature next = it.next(); Date date = (Date) next.getAttribute("installed_td"); assertTrue(date.before(testDate) || date.equals(testDate)); } it.close(); }
Example 3
Source File: ElasticTemporalFilterIT.java From elasticgeo with GNU General Public License v3.0 | 6 votes |
@Test public void testGreaterDateFilterLong() throws Exception { init(); Date testDate = new Date(1005912798000L); FilterFactory ff = dataStore.getFilterFactory(); Filter f = ff.greaterOrEqual(ff.property("installed_td"), ff.literal(testDate.getTime())); SimpleFeatureCollection features = featureSource.getFeatures(f); assertEquals(7, features.size()); SimpleFeatureIterator it = features.features(); while (it.hasNext()) { SimpleFeature next = it.next(); Date date = (Date) next.getAttribute("installed_td"); assertTrue(date.after(testDate) || date.equals(testDate)); } it.close(); }
Example 4
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 5
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 6
Source File: DataSourceImpl.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Read attributes. * * @param attributeData the attribute data */ /* * (non-Javadoc) * * @see * com.sldeditor.datasource.DataSourceInterface#updateAttributes(com.sldeditor.render.iface. * RenderAttributeDataInterface) */ @Override public void readAttributes(DataSourceAttributeListInterface attributeData) { if (attributeData == null) { return; } List<DataSourceAttributeData> valueMap = new ArrayList<>(); SimpleFeatureCollection featureCollection = dataSourceInfo.getFeatureCollection(); if (featureCollection != null) { SimpleFeatureIterator iterator = featureCollection.features(); Map<Integer, Name> fieldNameMap = dataSourceInfo.getFieldNameMap(); Map<Integer, Class<?>> fieldTypeMap = dataSourceInfo.getFieldTypeMap(); if (iterator.hasNext()) { SimpleFeature feature = iterator.next(); extractAttributes(valueMap, fieldNameMap, fieldTypeMap, feature); } iterator.close(); } attributeData.setData(valueMap); }
Example 7
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 8
Source File: FeatureCollectionPointsLayer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private void loadData() throws Exception { SimpleFeatureIterator featureIterator = getfeatureCollection().features(); try { removeAllRenderables(); while( featureIterator.hasNext() ) { SimpleFeature pointFeature = featureIterator.next(); addPoint(pointFeature); } } finally { featureIterator.close(); } }
Example 9
Source File: ElasticTestSupport.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
List<SimpleFeature> readFeatures(SimpleFeatureIterator iterator) { final List<SimpleFeature> features = new ArrayList<>(); try { while (iterator.hasNext()) { features.add(iterator.next()); } } finally { iterator.close(); } return features; }
Example 10
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 11
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@Test public void testNaturalSortingAsc() throws Exception { init(); Query q = new Query(featureSource.getSchema().getTypeName()); q.setSortBy(new SortBy[] { SortBy.NATURAL_ORDER }); SimpleFeatureIterator features = featureSource.getFeatures(q).features(); String prevId = null; while (features.hasNext()) { String currId = features.next().getID(); if (prevId != null) assertTrue(prevId.compareTo(currId) <= 0); prevId = currId; } features.close(); }
Example 12
Source File: ElasticFeatureFilterIT.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@Test public void testNaturalSortingDesc() throws Exception { init(); Query q = new Query(featureSource.getSchema().getTypeName()); q.setSortBy(new SortBy[] { SortBy.REVERSE_ORDER }); SimpleFeatureIterator features = featureSource.getFeatures(q).features(); String prevId = null; while (features.hasNext()) { String currId = features.next().getID(); if (prevId != null) assertTrue(prevId.compareTo(currId) >= 0); prevId = currId; } features.close(); }
Example 13
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 14
Source File: OmsTrentoP.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
/** * Initializating the array. * * <p> * The array is the net. If there is a FeatureCollection extract values from * it. The Array is order following the ID. * </p> * oss: if the FeatureCillection is null a IllegalArgumentException is throw * in {@link OmsTrentoP#verifyParameter()}. * * @param isAreaNotAllDry it is true if there is only a percentage of the input area dry. * @throws IllegalArgumentException * if the FeatureCollection hasn't the correct parameters. */ private void setNetworkPipes( boolean isAreaNotAllDry ) throws Exception { int length = inPipes.size(); networkPipes = new Pipe[length]; SimpleFeatureIterator stationsIter = inPipes.features(); boolean existOut = false; int tmpOutIndex = 0; try { int t = 0; while( stationsIter.hasNext() ) { SimpleFeature feature = stationsIter.next(); try { /* * extract the value of the ID which is the position (minus * 1) in the array. */ Number field = ((Number) feature.getAttribute(TrentoPFeatureType.ID_STR)); if (field == null) { pm.errorMessage(msg.message("trentoP.error.number") + TrentoPFeatureType.ID_STR); throw new IllegalArgumentException(msg.message("trentoP.error.number") + TrentoPFeatureType.ID_STR); } if (field.equals(pOutPipe)) { tmpOutIndex = t; existOut = true; } networkPipes[t] = new Pipe(feature, pMode, isAreaNotAllDry, pm); t++; } catch (NullPointerException e) { pm.errorMessage(msg.message("trentop.illegalNet")); throw new IllegalArgumentException(msg.message("trentop.illegalNet")); } } } finally { stationsIter.close(); } if (!existOut) { } // set the id where drain of the outlet. networkPipes[tmpOutIndex].setIdPipeWhereDrain(0); networkPipes[tmpOutIndex].setIndexPipeWhereDrain(-1); // start to construct the net. int numberOfPoint = networkPipes[tmpOutIndex].point.length - 1; findIdThatDrainsIntoIndex(tmpOutIndex, networkPipes[tmpOutIndex].point[0]); findIdThatDrainsIntoIndex(tmpOutIndex, networkPipes[tmpOutIndex].point[numberOfPoint]); List<Integer> missingId = new ArrayList<Integer>(); for( Pipe pipe : networkPipes ) { if (pipe.getIdPipeWhereDrain() == null && pipe.getId() != pOutPipe) { missingId.add(pipe.getId()); } } if (missingId.size() > 0) { String errorMsg = "One of the following pipes doesn't have a connected pipe towards the outlet: " + Arrays.toString(missingId.toArray(new Integer[0])); pm.errorMessage(msg.message(errorMsg)); throw new IllegalArgumentException(errorMsg); } verifyNet(networkPipes, pm); }
Example 15
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 16
Source File: InLineFeatureModel.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Removes the feature. * * @param selectedRow the selected row */ public void removeFeature(int selectedRow) { if ((selectedRow < 0) || (selectedRow >= getRowCount())) { return; } 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 { int index = 0; while (it.hasNext()) { SimpleFeature sf = it.next(); if (index != selectedRow) { List<Object> attributeValueList = sf.getAttributes(); sfb.addAll(attributeValueList); featureList.add(sfb.buildFeature(null)); } index++; } } 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 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: 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 19
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 20
Source File: InLineFeatureModel.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** Adds the new column. */ public void addNewColumn() { if (featureCollection != null) { String attributeName = getUniqueAttributeName(); columnList.add(attributeName); // Populate field names SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder(); featureTypeBuilder.init(featureCollection.getSchema()); featureTypeBuilder.add(attributeName, String.class); SimpleFeatureType newFeatureType = featureTypeBuilder.buildFeatureType(); 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(); sfb.addAll(sf.getAttributes()); sfb.add(new String("")); 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(); } } }