public void testSize() throws Exception { // in the common case it's as big as the max MaxSimpleFeatureCollection max = new MaxSimpleFeatureCollection(delegate, 2); assertEquals(2, max.size()); // however if we skip much it's going to be just as big as the remainder max = new MaxSimpleFeatureCollection(delegate, delegate.size() - 1, 10); assertEquals(1, max.size()); // and if we skip more than the size max = new MaxSimpleFeatureCollection(delegate, delegate.size() + 1, 10); assertEquals(0, max.size()); }
public void testIteratorSkipMoreSize() throws Exception { MaxSimpleFeatureCollection max = new MaxSimpleFeatureCollection(delegate, delegate.size() + 1, 2); SimpleFeatureIterator i = max.features(); try { assertFalse(i.hasNext()); } finally { i.close(); } } }
@Test public void testSortNaturalPartialLastPage() throws IOException { // make it so that we are not going to hit the disk, but // some of the data won't fit in the last page, used to be // left in memory and forgotten SimpleFeatureReader sr = null; try { final int PRIME = 173; sr = new SortedFeatureReader(fr, fidAsc, PRIME); String prev = null; int count = 0; while (sr.hasNext()) { SimpleFeature f = sr.next(); String id = f.getID(); if (prev != null) { assertTrue(id.compareTo(prev) >= 0); } prev = id; count++; } assertEquals(fc.size(), count); } finally { if (sr != null) { sr.close(); } } }
public void testIteratorSkipMax() throws Exception { MaxSimpleFeatureCollection max = new MaxSimpleFeatureCollection(delegate, delegate.size() - 1, 2); SimpleFeatureIterator i = max.features(); try { assertTrue(i.hasNext()); i.next(); assertFalse(i.hasNext()); } finally { i.close(); } }
private String createToolTip(final VectorDataNode vectorDataNode) { final StringBuilder tooltip = new StringBuilder(); append(tooltip, vectorDataNode.getDescription()); append(tooltip, String.format("type %s, %d feature(s)", vectorDataNode.getFeatureType().getTypeName(), vectorDataNode.getFeatureCollection().size())); return tooltip.toString(); } }
private void addGMLMasks(Product target, ImageMetadata metadata) { List<ImageMetadata.MaskInfo> gmlMasks = metadata.getMasks(); final Iterator<Color> colorIterator = ColorIterator.create(); Band refBand = findReferenceBand(target, metadata.getRasterWidth()); boolean isMultiSize = this.metadata.getImageMetadataList().size() > 1; gmlMasks.stream().forEach(mask -> { logger.info(String.format("Parsing mask %s of component %s", mask.name, metadata.getFileName())); VectorDataNode node = GMLReader.parse(mask.name, mask.path); if (node != null && node.getFeatureCollection().size() > 0) { node.setOwner(target); String maskName = mask.name; if (isMultiSize) { String resolution = "_" + new DecimalFormat("#.#").format(metadata.getPixelSize()) + "m"; maskName += resolution.endsWith(".") ? resolution.substring(0, resolution.length() - 1) : resolution; } if (refBand != null) { target.addMask(maskName, node, mask.description, colorIterator.next(), 0.5, refBand); } else { target.addMask(mask.name, node, mask.description, colorIterator.next(), 0.5); } } }); }
private void addGMLMasks(Product target, ImageMetadata metadata) { List<ImageMetadata.MaskInfo> gmlMasks = metadata.getMasks(); final Iterator<Color> colorIterator = ColorIterator.create(); Band refBand = findReferenceBand(target, metadata.getRasterWidth()); boolean isMultiSize = this.metadata.getImageMetadataList().size() > 1; gmlMasks.stream().forEach(mask -> { logger.info(String.format("Parsing mask %s of component %s", mask.name, metadata.getFileName())); VectorDataNode node = GMLReader.parse(mask.name, mask.path); if (node != null && node.getFeatureCollection().size() > 0) { node.setOwner(target); String maskName = mask.name; if (isMultiSize) { String resolution = "_" + new DecimalFormat("#.#").format(metadata.getPixelSize()) + "m"; maskName += resolution.endsWith(".") ? resolution.substring(0, resolution.length() - 1) : resolution; } if (refBand != null) { target.addMask(maskName, node, mask.description, colorIterator.next(), 0.5, refBand); } else { target.addMask(mask.name, node, mask.description, colorIterator.next(), 0.5); } } }); }
SimpleFeatureType styledFeatureType = styledCollection.getSchema(); List<SimpleFeature> featuresToStyle = new ArrayList<>(featureCollection.size()); try (FeatureIterator<SimpleFeature> iterator = featureCollection.features()) { while (iterator.hasNext()) {
public void accepts(org.opengis.feature.FeatureVisitor visitor, org.opengis.util.ProgressListener progress) { Iterator iterator = null; if (progress == null) progress = new NullProgressListener(); try{ float size = size(); float position = 0; progress.started(); for( iterator = iterator(); !progress.isCanceled() && iterator.hasNext(); progress.progress( position++/size )){ try { SimpleFeature feature = (SimpleFeature) iterator.next(); visitor.visit(feature); } catch( Exception erp ){ progress.exceptionOccurred( erp ); } } } finally { progress.complete(); close( iterator ); } }
/** * Accepts a visitor, which then visits each feature in the collection. * @throws IOException */ public void accepts(FeatureVisitor visitor, ProgressListener progress ) throws IOException { Iterator iterator = null; if (progress == null) progress = new NullProgressListener(); try{ float size = size(); float position = 0; progress.started(); for( iterator = iterator(); !progress.isCanceled() && iterator.hasNext(); progress.progress( position++/size )){ try { Feature feature = (Feature) iterator.next(); visitor.visit(feature); } catch( Exception erp ){ progress.exceptionOccurred( erp ); } } } finally { progress.complete(); close( iterator ); } }
private synchronized void AddShipRecordsAsVectors(final List<ShipRecord> clusterList) { VectorDataNode vectorDataNode = targetProduct.getVectorDataGroup().get(VECTOR_NODE_NAME); if (vectorDataNode == null) { vectorDataNode = new VectorDataNode(VECTOR_NODE_NAME, shipFeatureType); targetProduct.getVectorDataGroup().add(vectorDataNode); } DefaultFeatureCollection collection = vectorDataNode.getFeatureCollection(); final GeometryFactory geometryFactory = new GeometryFactory(); int c = collection.size(); for (ShipRecord rec : clusterList) { final String name = "target_" + StringUtils.padNum(c, 3, '0'); final SimpleFeatureBuilder fb = new SimpleFeatureBuilder(shipFeatureType); fb.add(geometryFactory.createPoint(new Coordinate(rec.x, rec.y))); fb.add(rec.x); fb.add(rec.y); fb.add(rec.lat); fb.add(rec.lon); fb.add(rec.width); fb.add(rec.length); fb.add(STYLE_FORMAT); final SimpleFeature feature = fb.buildFeature(name); collection.add(feature); c++; } }
private synchronized void AddWindRecordsAsVectors(final List<WindFieldRecord> recordList) { VectorDataNode vectorDataNode = targetProduct.getVectorDataGroup().get(VECTOR_NODE_NAME); if (vectorDataNode == null) { vectorDataNode = new VectorDataNode(VECTOR_NODE_NAME, windFeatureType); targetProduct.getVectorDataGroup().add(vectorDataNode); } DefaultFeatureCollection collection = vectorDataNode.getFeatureCollection(); final GeometryFactory geometryFactory = new GeometryFactory(); final GeoCoding geoCoding = targetProduct.getSceneGeoCoding(); final GeoPos geoPos1 = new GeoPos(); final GeoPos geoPos2 = new GeoPos(); int c = collection.size(); for (WindFieldRecord rec : recordList) { geoCoding.getGeoPos(new PixelPos(rec.x, rec.y), geoPos1); geoCoding.getGeoPos(new PixelPos(rec.x + rec.dx, rec.y + rec.dy), geoPos2); GeoUtils.DistanceHeading heading = GeoUtils.vincenty_inverse(geoPos1, geoPos2); final SimpleFeatureBuilder fb = new SimpleFeatureBuilder(windFeatureType); fb.add(geometryFactory.createPoint(new Coordinate(rec.x, rec.y))); fb.add(rec.speed); fb.add(heading.heading1); fb.add(rec.dx); fb.add(rec.dy); fb.add(rec.ratio); fb.add(STYLE_FORMAT); final SimpleFeature feature = fb.buildFeature("wind_" + c); collection.add(feature); c++; } }
final GeoPos slvGeoPos = new GeoPos(); int c = collection.size(); for (int i = 0; i < numGCPsPerAzLine; i++) { for (int j = 0; j < numGCPsPerRgLine; j++) {
@Test public void testDecodingDelimiter() throws IOException { final FeatureCollection<SimpleFeatureType, SimpleFeature> readCollection = VectorDataNodeReader.read("mem", new StringReader(stringWriter.toString()), createDummyProduct(), new FeatureUtils.FeatureCrsProvider() { @Override public CoordinateReferenceSystem getFeatureCrs(Product product) { return DefaultGeographicCRS.WGS84; } }, placemarkDescriptorProvider, DefaultGeographicCRS.WGS84, VectorDataNodeIO.DEFAULT_DELIMITER_CHAR, ProgressMonitor.NULL).getFeatureCollection(); assertEquals(testCollection.size(), readCollection.size()); final FeatureIterator<SimpleFeature> expectedIterator = testCollection.features(); final FeatureIterator<SimpleFeature> actualIterator = readCollection.features(); while (expectedIterator.hasNext()) { final SimpleFeature expectedFeature = expectedIterator.next(); final SimpleFeature actualFeature = actualIterator.next(); final Object expectedAttribute = expectedFeature.getAttribute(ATTRIBUTE_NAME_LABEL); final Object actualAttribute = actualFeature.getAttribute(ATTRIBUTE_NAME_LABEL); assertEquals(expectedAttribute, actualAttribute); } }
String attributeName = null; GeometryDescriptor geometryDescriptor = vectorDataNode.getFeatureType().getGeometryDescriptor(); int featureCount = vectorDataNode.getFeatureCollection().size(); if (featureCount > 1 && geometryDescriptor != null