private FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection(SimpleFeatureType featureType) { return featureType2VDN.get(featureType).getFeatureCollection(); }
@Override public void undo() throws CannotUndoException { super.undo(); vectorDataNode.getFeatureCollection().removeAll(simpleFeatures); }
@Override public void redo() throws CannotRedoException { super.redo(); vectorDataNode.getFeatureCollection().removeAll(simpleFeatures); } });
@Override public void redo() throws CannotRedoException { super.redo(); vectorDataNode.getFeatureCollection().addAll(simpleFeatures); } });
@Override public void undo() throws CannotUndoException { super.undo(); vectorDataNode.getFeatureCollection().addAll(simpleFeatures); }
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 setMaskRegionName(Mask selectedMask, VectorDataNode vectorDataNode) { FeatureIterator<SimpleFeature> features = vectorDataNode.getFeatureCollection().features(); mask2RegionName.put(selectedMask, Util.getFeatureName(features.next())); features.close(); }
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); } } }); }
private void computeChartDataIfPossible() { // need to do this later: all GUI events must be processed first in order to get the correct state SwingUtilities.invokeLater(() -> { if (scatterPlotModel.pointDataSource != null && scatterPlotModel.dataField != null && scatterPlotModel.pointDataSource.getFeatureCollection() != null && scatterPlotModel.pointDataSource.getFeatureCollection().features() != null && scatterPlotModel.pointDataSource.getFeatureCollection().features().hasNext() && scatterPlotModel.pointDataSource.getFeatureCollection().features().next() != null && scatterPlotModel.pointDataSource.getFeatureCollection().features().next().getAttribute( scatterPlotModel.dataField.getLocalName()) != null && getRaster() != null) { compute(scatterPlotModel.useRoiMask ? scatterPlotModel.roiMask : null); } else { scatterpointsDataset.removeAllSeries(); acceptableDeviationDataset.removeAllSeries(); regressionDataset.removeAllSeries(); getPlot().removeAnnotation(r2Annotation); computedDatas = null; } }); }
private String[] getPolygons() { // Get polygons from the first product which is assumed to be maskProduct in BaseClassifier final ArrayList<String> geometryNames = new ArrayList<>(5); if (sourceProducts != null) { if (sourceProducts.length > 1) { final ProductNodeGroup<VectorDataNode> vectorDataNodes = sourceProducts[0].getVectorDataGroup(); for(int i=0; i< vectorDataNodes.getNodeCount(); ++i) { VectorDataNode node = vectorDataNodes.get(i); if(!node.getFeatureCollection().isEmpty()) { geometryNames.add(node.getName() + "::" + sourceProducts[0].getName()); } } } else { final ProductNodeGroup<VectorDataNode> vectorDataNodes = sourceProducts[0].getVectorDataGroup(); for(int i=0; i< vectorDataNodes.getNodeCount(); ++i) { VectorDataNode node = vectorDataNodes.get(i); if(!node.getFeatureCollection().isEmpty()) { geometryNames.add(node.getName()); } } } } return geometryNames.toArray(new String[geometryNames.size()]); }
private void doExportImport(ArrayList<SimpleFeature> features, Class<? extends Geometry> geomType) throws IOException { File tempFile = File.createTempFile("pins", null, tempDir); try { ExportGeometryAction.writeEsriShapefile(geomType, features, tempFile); assertTrue(tempFile.exists()); VectorDataNode vectorDataNode = readIn(new File(String.format("%s_%s.shp", tempFile.getAbsolutePath(), geomType.getSimpleName())), product); assertEquals(1, vectorDataNode.getFeatureCollection().getCount()); try (SimpleFeatureIterator readFeatures = vectorDataNode.getFeatureCollection().features()) { while (readFeatures.hasNext()) { SimpleFeature next = readFeatures.next(); assertNotNull(next.getDefaultGeometry()); } } } catch (Throwable t) { t.printStackTrace(); fail(String.format("Throwable '%s: %s' not expected", t.getClass().getSimpleName(), t.getMessage())); } finally { boolean deleted = tempFile.delete(); if (!deleted) { tempFile.deleteOnExit(); } } }
@Override public void deleteFigures(boolean performDelete, Figure... figures) { Debug.trace("VectorDataFigureEditor.deleteFigures " + performDelete + ", " + figures.length); if (vectorDataNode != null) { List<SimpleFeature> simpleFeatures = toSimpleFeatureList(figures); vectorDataNode.getFeatureCollection().removeAll(simpleFeatures); getUndoContext().postEdit(new FigureDeleteEdit(this, performDelete, figures) { @Override public void undo() throws CannotUndoException { super.undo(); vectorDataNode.getFeatureCollection().addAll(simpleFeatures); } @Override public void redo() throws CannotRedoException { super.redo(); vectorDataNode.getFeatureCollection().removeAll(simpleFeatures); } }); } else { // warn super.deleteFigures(performDelete, figures); } }
@Override public void insertFigures(boolean performInsert, Figure... figures) { Debug.trace("VectorDataFigureEditor.insertFigures " + performInsert + ", " + figures.length); if (vectorDataNode != null) { List<SimpleFeature> simpleFeatures = toSimpleFeatureList(figures); vectorDataNode.getFeatureCollection().addAll(simpleFeatures); getUndoContext().postEdit(new FigureInsertEdit(this, performInsert, figures) { @Override public void undo() throws CannotUndoException { super.undo(); vectorDataNode.getFeatureCollection().removeAll(simpleFeatures); } @Override public void redo() throws CannotRedoException { super.redo(); vectorDataNode.getFeatureCollection().addAll(simpleFeatures); } }); } else { // warn super.insertFigures(performInsert, figures); } }
private static Map<Class<?>, List<SimpleFeature>> createGeometryToFeaturesListMap(VectorDataNode vectorNode) throws TransformException, SchemaException { FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = vectorNode.getFeatureCollection(); CoordinateReferenceSystem crs = vectorNode.getFeatureType().getCoordinateReferenceSystem(); if (crs == null) { // for pins and GCPs crs is null
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++; } }
/** * Performs the actual "export Mask Pixels" command. */ private void exportVectorDataNode() { SnapApp snapApp = SnapApp.getDefault(); if (vectorDataNode.getFeatureCollection().isEmpty()) { Dialogs.showInformation(Bundle.CTL_ExportGeometryAction_DialogTitle(), "The selected geometry is empty. Nothing to export.", null); return; } final File file = promptForFile(vectorDataNode.getName()); if (file == null) { return; } final SwingWorker<Exception, Object> swingWorker = new ExportVectorNodeSwingWorker(snapApp, vectorDataNode, file); UIUtils.setRootFrameWaitCursor(snapApp.getMainFrame()); snapApp.setStatusBarMessage("Exporting Geometry..."); swingWorker.execute(); }
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++; } }
targetProduct.getVectorDataGroup().add(vectorDataNode); DefaultFeatureCollection collection = vectorDataNode.getFeatureCollection(); final GeometryFactory geometryFactory = new GeometryFactory(); final GeoCoding geoCoding = targetProduct.getSceneGeoCoding();
@Override public VectorDataNode readVectorDataNode(File file, Product product, ProgressMonitor pm) throws IOException { DefaultFeatureCollection featureCollection = FeatureUtils.loadShapefileForProduct(file, product, crsProvider, pm); Style[] styles = SLDUtils.loadSLD(file); ProductNodeGroup<VectorDataNode> vectorDataGroup = product.getVectorDataGroup(); String name = VectorDataNodeImporter.findUniqueVectorDataNodeName(featureCollection.getSchema().getName().getLocalPart(), vectorDataGroup); if (styles.length > 0) { SimpleFeatureType featureType = SLDUtils.createStyledFeatureType(featureCollection.getSchema()); VectorDataNode vectorDataNode = new VectorDataNode(name, featureType); DefaultFeatureCollection styledCollection = vectorDataNode.getFeatureCollection(); String defaultCSS = vectorDataNode.getDefaultStyleCss(); SLDUtils.applyStyle(styles[0], defaultCSS, featureCollection, styledCollection); return vectorDataNode; } else { return new VectorDataNode(name, featureCollection); } } }