private static VectorDataNode createVectorDataNode(FeatureStatisticsWriter featureStatisticsWriter, VectorDataNode originalVDN) { final SimpleFeatureType updatedFeatureType = featureStatisticsWriter.getUpdatedFeatureType(); final List<SimpleFeature> features = featureStatisticsWriter.getFeatures(); final ListFeatureCollection featureCollection = new ListFeatureCollection(updatedFeatureType, features); final PlacemarkDescriptor placemarkDescriptor = originalVDN.getPlacemarkDescriptor(); final VectorDataNode vectorDataNode = new VectorDataNode(originalVDN.getName(), featureCollection, placemarkDescriptor); vectorDataNode.setPermanent(originalVDN.isPermanent()); vectorDataNode.setModified(true); vectorDataNode.setDescription(originalVDN.getDescription()); return vectorDataNode; }
public static VectorDataNode[] getVectorDataNodes(VectorDataNode vectorDataNode, boolean individualShapes, String attributeName) { VectorDataNode[] vectorDataNodes; if (individualShapes) { FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = vectorDataNode.getFeatureCollection(); SimpleFeature[] features = featureCollection.toArray(new SimpleFeature[0]); vectorDataNodes = new VectorDataNode[features.length]; for (int i = 0; i < features.length; i++) { SimpleFeature feature = features[i]; String newName; if (attributeName != null && feature.getAttribute(attributeName) != null && !feature.getAttribute(attributeName).toString().isEmpty()) { newName = feature.getAttribute(attributeName).toString().replace(" ", "_").replace("-", "_"); } else { newName = vectorDataNode.getName() + "_" + (i + 1); } vectorDataNodes[i] = new VectorDataNode(newName, new ListFeatureCollection(vectorDataNode.getFeatureType(), Arrays.asList(feature))); } } else { vectorDataNodes = new VectorDataNode[]{vectorDataNode}; } return vectorDataNodes; } }
void writeNodeProperties(VectorDataNode vectorDataNode, Writer writer) throws IOException { OrderRetainingMap properties = new OrderRetainingMap(); final Map<Object, Object> userData = vectorDataNode.getFeatureType().getUserData(); final Set<Map.Entry<Object, Object>> entries = userData.entrySet(); for (Map.Entry<Object, Object> entry : entries) { if (entry.getKey() instanceof String && entry.getValue() instanceof String) { properties.put(entry.getKey().toString(), entry.getValue().toString()); } } String description = vectorDataNode.getDescription(); if (StringUtils.isNotNullAndNotEmpty(description)) { properties.put(ProductNode.PROPERTY_NAME_DESCRIPTION, description); } String defaultCSS = vectorDataNode.getDefaultStyleCss(); if (StringUtils.isNotNullAndNotEmpty(defaultCSS)) { properties.put(VectorDataNodeIO.PROPERTY_NAME_DEFAULT_CSS, defaultCSS); } writeProperties(properties, writer); }
private synchronized PlacemarkGroup createPinGroup() { final VectorDataNode vectorDataNode = new VectorDataNode(PIN_GROUP_NAME, Placemark.createPinFeatureType()); vectorDataNode.setDefaultStyleCss( "symbol:pin; fill:#0000ff; fill-opacity:0.7; stroke:#ffffff; stroke-opacity:1.0; stroke-width:0.5"); vectorDataNode.setPermanent(true); this.vectorDataGroup.add(vectorDataNode); return vectorDataNode.getPlacemarkGroup(); }
public PlacemarkGroup getPlacemarkGroup() { if (placemarkGroup == null) { synchronized (this) { if (placemarkGroup == null) { placemarkGroup = new PlacemarkGroup(getProduct(), getName(), this); } } } return placemarkGroup; }
@Test public void testAddingNonEmptyGcpVectorDataNode() throws Exception { final Product p = new Product("n", "t", 1, 1); assertNotNull(p.getGcpGroup()); final VectorDataNode node = p.getVectorDataGroup().get("ground_control_points"); // add non-empty "pins" VDN final VectorDataNode node2 = new VectorDataNode("ground_control_points", node.getFeatureType()); node2.getFeatureCollection().add(new SimpleFeatureBuilder(node.getFeatureType()).buildFeature("id")); final boolean added3 = p.getVectorDataGroup().add(node2); assertFalse(added3); assertSame(node, p.getVectorDataGroup().get("ground_control_points")); assertFalse(node.getFeatureCollection().isEmpty()); assertEquals(1, node.getPlacemarkGroup().getNodeCount()); assertTrue(node.isPermanent()); } }
for (int i = 0; i < vectorDataGroup.getNodeCount(); i++) { VectorDataNode sourceVDN = vectorDataGroup.get(i); if (!sourceVDN.isPermanent() || !sourceVDN.getFeatureCollection().isEmpty()) { allPermanentAndEmpty = false; break; for (int i = 0; i < vectorDataGroup.getNodeCount(); i++) { VectorDataNode sourceVDN = vectorDataGroup.get(i); String name = sourceVDN.getName(); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = sourceVDN.getFeatureCollection(); featureCollection = new DefaultFeatureCollection(featureCollection); if (!targetProduct.getVectorDataGroup().contains(name)) { targetProduct.getVectorDataGroup().add(new VectorDataNode(name, featureCollection.getSchema())); targetVDN.getFeatureCollection().addAll(featureCollection); targetVDN.setDefaultStyleCss(sourceVDN.getDefaultStyleCss()); targetVDN.setDescription(sourceVDN.getDescription()); String name = sourceVDN.getName(); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = sourceVDN.getFeatureCollection(); featureCollection = FeatureUtils.clipCollection(featureCollection, srcModelCrs, ProgressMonitor.NULL); if (!targetProduct.getVectorDataGroup().contains(name)) { targetProduct.getVectorDataGroup().add(new VectorDataNode(name, featureCollection.getSchema())); targetVDN.getPlacemarkGroup();
@Test public void testMaskIsRemovedWhenAllFeaturesAreRemoved() throws Exception { final Product p = new Product("P", "T", 1, 1); final SimpleFeatureType featureType = new GeometryDescriptor().getBaseFeatureType(); final VectorDataNode node = new VectorDataNode("V", featureType); p.getVectorDataGroup().add(node); node.getFeatureCollection().add(new SimpleFeatureBuilder(featureType).buildFeature("id1")); node.getFeatureCollection().add(new SimpleFeatureBuilder(featureType).buildFeature("id2")); node.getFeatureCollection().clear(); assertEquals(0, p.getMaskGroup().getNodeCount()); }
private String getInfoText(VectorDataNode vectorDataNode, SimpleFeature feature) { final String infoText; if (vectorDataNode != null) { infoText = String.format("<html>" + "Vector data node: <b>%s</b> with %d feature(s)<br>" + "Feature type: <b>%s (%s)</b><br>" + "Geometry attribute: <b>%s</b><br>" + "<br>" + "%s<br>" + "</html>", vectorDataNode.getName(), vectorDataNode.getFeatureCollection().size(), vectorDataNode.getFeatureType().getTypeName(), vectorDataNode.getPlacemarkDescriptor().getClass().getSimpleName(), vectorDataNode.getFeatureType().getGeometryDescriptor().getLocalName(), feature != null ? String.format("Selected feature <b>%s</b>:", feature.getID()) : "No feature selected."); infoLabel.setText(infoText); } else { infoText = NO_SELECTION_TEXT; // infoText = getSelectionDebugText(selectionContext, selectedValue); } return infoText; }
@Test public void testGetVectorDataNodesWithEmptyAttribute() throws Exception { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("sft"); builder.add("CAPITAL", String.class); SimpleFeatureType featureType = builder.buildFeatureType(); VectorDataNode vectorDataNode = new VectorDataNode("originalName", featureType); SimpleFeatureBuilder simpleFeatureBuilder = new SimpleFeatureBuilder(featureType); simpleFeatureBuilder.set("CAPITAL", ""); vectorDataNode.getFeatureCollection().add(simpleFeatureBuilder.buildFeature("0")); simpleFeatureBuilder.set("CAPITAL", "Coruscant"); vectorDataNode.getFeatureCollection().add(simpleFeatureBuilder.buildFeature("1")); VectorDataNode[] vectorDataNodes = VectorDataNodeIO.getVectorDataNodes(vectorDataNode, true, "CAPITAL"); assertEquals(2, vectorDataNodes.length); assertEquals("originalName_1", vectorDataNodes[0].getName()); assertEquals("Coruscant", vectorDataNodes[1].getName()); }
@Test public void testProperties() throws Exception { VectorDataNode vectorDataNode = new VectorDataNode("aName", Placemark.createGeometryFeatureType()); vectorDataNode.setDescription("Contains a set of pins"); vectorDataNode.setDefaultStyleCss("stroke:#ff0000"); VectorDataNodeWriter vectorDataNodeWriter = new VectorDataNodeWriter(); File tempFile = File.createTempFile("VectorDataNodeWriterTest_testProperties", "csv"); tempFile.deleteOnExit(); vectorDataNodeWriter.write(vectorDataNode, tempFile); FileReader fileReader = new FileReader(tempFile); LineNumberReader lineNumberReader = new LineNumberReader(fileReader); String firstLine = lineNumberReader.readLine(); assertNotNull(firstLine); assertEquals("#description=Contains a set of pins", firstLine); String secondLine = lineNumberReader.readLine(); assertNotNull(secondLine); assertEquals("#defaultCSS=stroke:#ff0000", secondLine); VectorDataNode vectorDataNode2 = VectorDataNodeReader.read("mem", new FileReader(tempFile), createDummyProduct(), new FeatureUtils.FeatureCrsProvider() { @Override public CoordinateReferenceSystem getFeatureCrs(Product product) { return DefaultGeographicCRS.WGS84; } }, placemarkDescriptorProvider, DefaultGeographicCRS.WGS84, VectorDataNodeIO.DEFAULT_DELIMITER_CHAR, ProgressMonitor.NULL); assertNotNull(vectorDataNode2); assertEquals(vectorDataNode.getDescription(), vectorDataNode2.getDescription()); assertEquals(vectorDataNode.getDefaultStyleCss(), vectorDataNode2.getDefaultStyleCss()); }
@Test public void testInitialGcpVectorDataNodeState() throws Exception { final Product p = new Product("n", "t", 1, 1); assertNotNull(p.getGcpGroup()); final VectorDataNode node = p.getVectorDataGroup().get("ground_control_points"); assertNotNull(node); assertTrue(node.getPlacemarkDescriptor() instanceof GcpDescriptor); assertSame(p.getGcpGroup(), p.getGcpGroup()); assertSame(p.getGcpGroup(), node.getPlacemarkGroup()); assertTrue(node.getFeatureCollection().isEmpty()); assertEquals(0, node.getPlacemarkGroup().getNodeCount()); assertTrue(node.isPermanent()); }
private VectorDataNode[] createVectorDataNodes(FeatureCollection<SimpleFeatureType, SimpleFeature> productFeatures) { final FeatureIterator<SimpleFeature> featureIterator = productFeatures.features(); final List<VectorDataNode> result = new ArrayList<VectorDataNode>(); while (featureIterator.hasNext()) { final SimpleFeature simpleFeature = featureIterator.next(); final DefaultFeatureCollection fc = new DefaultFeatureCollection(simpleFeature.getID(), simpleFeature.getFeatureType()); fc.add(simpleFeature); String name = Util.getFeatureName(simpleFeature); result.add(new VectorDataNode(name, fc)); } return result.toArray(new VectorDataNode[result.size()]); }
/** * @return true if the feature type's name starts with "org.esa.beam." * @deprecated Since BEAM 4.10. No use. */ @Deprecated public boolean isInternalNode() { return getFeatureType().getTypeName().startsWith("org.esa.beam."); }
@Override public VectorDataNode readVectorDataNode(File file, Product product, ProgressMonitor pm) throws IOException { FeatureCollection<SimpleFeatureType, SimpleFeature> 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); FeatureCollection<SimpleFeatureType, SimpleFeature> styledCollection = vectorDataNode.getFeatureCollection(); String defaultCSS = vectorDataNode.getDefaultStyleCss(); SLDUtils.applyStyle(styles[0], defaultCSS, featureCollection, styledCollection); return vectorDataNode; } else { return new VectorDataNode(name, featureCollection); } }
@Test public void testVectorDataNodeAndPlacemarkGroup() { Product p = new Product("p", "pt", 512, 512); ProductNodeGroup<VectorDataNode> vectorDataGroup = p.getVectorDataGroup(); Placemark placemark = Placemark.createPointPlacemark(PointDescriptor.getInstance(), "placemark_1", null, null, new PixelPos(10, 10), null, null); VectorDataNode vectorDataNode = new VectorDataNode("Features", Placemark.createPointFeatureType("feature")); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = vectorDataNode.getFeatureCollection(); vectorDataGroup.add(vectorDataNode); //Also: Sets the owner of the vectorDataNode vectorDataNode.getPlacemarkGroup(); //Also: Creates the PlacemarkGroup (owner has to be set!) featureCollection.add(placemark.getFeature()); assertEquals(1, vectorDataNode.getFeatureCollection().size()); assertEquals(vectorDataNode.getFeatureCollection().size(), vectorDataNode.getPlacemarkGroup().getNodeCount()); }
@Override public void add(int index, VectorDataNode vectorDataNode) { Assert.notNull(vectorDataNode, "node"); VectorDataNode permanentNode = getPermanentNode(vectorDataNode.getName()); if (permanentNode != null) { permanentNode.getFeatureCollection().addAll(vectorDataNode.getFeatureCollection()); return; } super.add(index, vectorDataNode); }
@Test public void testDefaultStyle() { SimpleFeatureType unknownType = PlacemarkDescriptorRegistryTest.createYetUnknownFeatureType(); Product p = new Product("p", "pt", 4, 4); VectorDataNode vdn = new VectorDataNode("vdn", unknownType); p.getVectorDataGroup().add(vdn); MyProductNodeListenerAdapter pnl = new MyProductNodeListenerAdapter(); p.addProductNodeListener(pnl); String styleCss = vdn.getStyleCss(); assertNotNull(vdn.getDefaultStyleCss()); vdn.setDefaultStyleCss("fill:#aabbcc"); assertEquals("fill:#aabbcc", vdn.getDefaultStyleCss()); assertNotNull(pnl.event); assertEquals("defaultStyleCss", pnl.event.getPropertyName()); assertEquals("fill:#aabbcc", pnl.event.getNewValue()); pnl.event = null; vdn.setDefaultStyleCss("fill:#aabbcc"); assertNull(pnl.event); vdn.setDefaultStyleCss("fill:#000000"); assertNotNull(pnl.event); assertEquals("defaultStyleCss", pnl.event.getPropertyName()); assertEquals("fill:#000000", pnl.event.getNewValue()); // test that styleCss is not affected assertEquals(styleCss, vdn.getStyleCss()); }
@Before() public void setup() { Product product = new Product("PinGroup Test", "TestType", 10, 10); VectorDataNode pinVectorDataNode = product.getVectorDataGroup().get("pins"); pinBuilder = new SimpleFeatureBuilder(pinVectorDataNode.getFeatureType()); placemarkGroup = pinVectorDataNode.getPlacemarkGroup(); pinFeatureCollection = pinVectorDataNode.getFeatureCollection(); }
public static VectorDataNode createDefaultVectorDataNode(Product product, String name, String description) { CoordinateReferenceSystem modelCrs = ImageManager.getModelCrs(product.getGeoCoding()); SimpleFeatureType type = PlainFeatureFactory.createDefaultFeatureType(modelCrs); VectorDataNode vectorDataNode = new VectorDataNode(name, type); vectorDataNode.setDescription(description); product.getVectorDataGroup().add(vectorDataNode); vectorDataNode.getPlacemarkGroup(); final ProductSceneView sceneView = VisatApp.getApp().getSelectedProductSceneView(); if (sceneView != null) { VisatApp.getApp().getProductTree().expand(vectorDataNode); sceneView.selectVectorDataLayer(vectorDataNode); final LayerFilter nodeFilter = VectorDataLayerFilterFactory.createNodeFilter(vectorDataNode); Layer vectorDataLayer = LayerUtils.getChildLayer(sceneView.getRootLayer(), LayerUtils.SEARCH_DEEP, nodeFilter); if (vectorDataLayer != null) { vectorDataLayer.setVisible(true); } } return vectorDataNode; }