public static VectorDataNode parse(String maskName, Path inputFile) { VectorDataNode node = null; try (InputStream inputStream = Files.newInputStream(inputFile)) { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); Handler handler = new Handler(); parser.parse(inputStream, handler); List<SimpleFeature> polygonFeatures = handler.getResult(); DefaultFeatureCollection featureCollection = new DefaultFeatureCollection("VectorMasks", featureType); featureCollection.addAll(polygonFeatures); /*for (int i = 0; i < polygonFeatures.size(); i++) { SimpleFeature feature = new SimpleFeatureImpl(new Object[]{ polygonFeatures.get(i), String.format("Polygon-%s", i)}, featureType, new FeatureIdImpl(String.format("F-%s", i)), true); featureCollection.add(feature); }*/ node = new VectorDataNode(maskName, featureCollection); } catch (Exception e) { systemLogger.warning(e.getMessage()); } return node; }
VectorDataNode windNode = new VectorDataNode(componentName + "_" + WIND_VECTOR_DATA_NODE_NAME, windFeatureType);
@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); } } }
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; }
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++; } }
public static VectorDataNode createDefaultVectorDataNode(Product product, String name, String description) { CoordinateReferenceSystem modelCrs = product.getSceneCRS(); SimpleFeatureType type = PlainFeatureFactory.createDefaultFeatureType(modelCrs); VectorDataNode vectorDataNode = new VectorDataNode(name, type); vectorDataNode.setDescription(description); product.getVectorDataGroup().add(vectorDataNode); vectorDataNode.getPlacemarkGroup(); String oldLayerId = selectVectorDataLayer(vectorDataNode); UndoRedo.Manager undoManager = SnapApp.getDefault().getUndoManager(product); if (undoManager != null) { undoManager.addEdit(new UndoableVectorDataNodeInsertion(product, vectorDataNode, oldLayerId)); } return vectorDataNode; }
if(!maskInfo.isPerPolygon()) { String snapName = String.format("%s_%dm", maskInfo.getSnapName()[i], resolution.resolution); VectorDataNode vdn = new VectorDataNode(snapName, collection); vdn.setOwner(product); product.addMask(snapName, VectorDataNode vdnPolygon = new VectorDataNode(subId, subCollection); vdnPolygon.setOwner(product); String snapName = String.format("%s_%dm", subId, resolution.resolution); VectorDataNode vdn = new VectorDataNode(snapName, collection); vdn.setOwner(product); product.addMask(snapName, VectorDataNode vdnPolygon = new VectorDataNode(subId, subCollection); vdnPolygon.setOwner(product);
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++; } }
private VectorDataNode readIn(File file, Product product) throws IOException, FactoryException, TransformException { DefaultFeatureCollection featureCollection = FeatureUtils.loadShapefileForProduct(file, product, new DummyFeatureCrsProvider(), ProgressMonitor.NULL); ProductNodeGroup<VectorDataNode> vectorDataGroup = product.getVectorDataGroup(); String name = VectorDataNodeImporter.findUniqueVectorDataNodeName(featureCollection.getSchema().getName().getLocalPart(), vectorDataGroup); return new VectorDataNode(name, featureCollection); }
@Test public void testUpdatePointDataSource() throws Exception { final BindingContext bindingContext = new BindingContext(); bindingContext.getPropertySet().addProperties(Property.create("pointDataSource", VectorDataNode.class)); bindingContext.getPropertySet().addProperties(Property.create("dataField", AttributeDescriptor.class)); final CorrelativeFieldSelector correlativeFieldSelector = new CorrelativeFieldSelector(bindingContext); final Product product = new Product("name", "type", 10, 10); product.getVectorDataGroup().add(new VectorDataNode("a", createFeatureType(Geometry.class))); product.getVectorDataGroup().add(new VectorDataNode("b", createFeatureType(Point.class))); assertEquals(0, correlativeFieldSelector.pointDataSourceList.getItemCount()); assertEquals(0, correlativeFieldSelector.dataFieldList.getItemCount()); correlativeFieldSelector.updatePointDataSource(product); assertEquals(3, correlativeFieldSelector.pointDataSourceList.getItemCount()); assertEquals(0, correlativeFieldSelector.dataFieldList.getItemCount()); correlativeFieldSelector.pointDataSourceProperty.setValue(product.getVectorDataGroup().get("b")); assertEquals(3, correlativeFieldSelector.dataFieldList.getItemCount()); }
vectorDataNode = new VectorDataNode(VECTOR_NODE_NAME, windFeatureType); targetProduct.getVectorDataGroup().add(vectorDataNode);
@Override public void actionPerformed(ActionEvent ae) { final File file = Dialogs.requestFileForOpen(Bundle.CTL_ImportSeadasTrackActionName(), false, null, "importTrack.lastDir"); if (file == null) { return; } final Product product = SnapApp.getDefault().getSelectedProduct(AUTO); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection; try { featureCollection = readTrack(file, product.getSceneGeoCoding()); } catch (IOException e) { Dialogs.showError(Bundle.CTL_ImportSeadasTrackActionName(), "Failed to load track file:\n" + e.getMessage()); return; } if (featureCollection.isEmpty()) { Dialogs.showError(Bundle.CTL_ImportSeadasTrackActionName(), "No records found."); return; } String name = FileUtils.getFilenameWithoutExtension(file); final PlacemarkDescriptor placemarkDescriptor = PlacemarkDescriptorRegistry.getInstance().getPlacemarkDescriptor(featureCollection.getSchema()); placemarkDescriptor.setUserDataOf(featureCollection.getSchema()); VectorDataNode vectorDataNode = new VectorDataNode(name, featureCollection, placemarkDescriptor); product.getVectorDataGroup().add(vectorDataNode); final ProductSceneView view = SnapApp.getDefault().getSelectedProductSceneView(); if (view != null) { view.setLayersVisible(vectorDataNode); } }
VectorDataNode targetVectorDataNode = new VectorDataNode(sourceVectorDataNode.getName(), sourceCollection.getSchema()); targetVectorDataNode.getFeatureCollection().addAll((FeatureCollection<?, ?>) targetCollection); targetVectorDataNode.setDefaultStyleCss(sourceVectorDataNode.getDefaultStyleCss());
contextProduct.getVectorDataGroup().add(new VectorDataNode(vectorDataName, vectorData.getFeatureType()));
@Before public void setUp() throws Exception { // Draw a "Z" path = new Path2D.Double(); path.moveTo(0, 0); path.lineTo(3, 0); path.lineTo(0, 3); path.lineTo(3, 3); product = new Product("p", "t", 4, 4); band = product.addBand("b", "4 * (Y-0.5) + (X-0.5) + 0.1"); dataSourceConfig = new ProfilePlotPanel.DataSourceConfig(); SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); ftb.setName("ft"); ftb.add("lat", Double.class); ftb.add("lon", Double.class); ftb.add("data", Double.class); SimpleFeatureType ft = ftb.buildFeatureType(); DefaultFeatureCollection fc = new DefaultFeatureCollection("id", ft); fc.add(new SimpleFeatureImpl(new Object[]{0, 0, 0.3}, ft, new FeatureIdImpl("id1"), false)); fc.add(new SimpleFeatureImpl(new Object[]{0, 0, 0.5}, ft, new FeatureIdImpl("id2"), false)); fc.add(new SimpleFeatureImpl(new Object[]{0, 0, 0.7}, ft, new FeatureIdImpl("id3"), false)); fc.add(new SimpleFeatureImpl(new Object[]{0, 0, 0.1}, ft, new FeatureIdImpl("id4"), false)); dataSourceConfig.pointDataSource = new VectorDataNode("vd", fc); dataSourceConfig.dataField = ft.getDescriptor("data"); dataSourceConfig.boxSize = 1; dataSourceConfig.computeInBetweenPoints = true; }