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 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; }
@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()); }
targetVDN.getFeatureCollection().addAll(featureCollection); targetVDN.setDefaultStyleCss(sourceVDN.getDefaultStyleCss()); targetVDN.setDescription(sourceVDN.getDescription()); targetVDN.getFeatureCollection().addAll(featureCollection); targetVDN.setDefaultStyleCss(sourceVDN.getDefaultStyleCss()); targetVDN.setDescription(sourceVDN.getDescription());