private static FeatureCollection<SimpleFeatureType, SimpleFeature> readTrack(File file, GeoCoding geoCoding) throws IOException { try (Reader reader = new FileReader(file)) { return readTrack(reader, geoCoding); } }
@Test public void testReadTrack() throws Exception { CrsGeoCoding geoCoding = new CrsGeoCoding(DefaultGeographicCRS.WGS84, new Rectangle(360, 180), new AffineTransform()); InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("TrackData.csv")); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = ImportTrackAction.readTrack(reader, geoCoding); assertNotNull(featureCollection); assertEquals(23, featureCollection.size()); // test ordering SimpleFeature[] simpleFeatures = featureCollection.toArray(new SimpleFeature[0]); assertEquals(23, simpleFeatures.length); assertEquals("ID00000000", simpleFeatures[0].getID()); assertEquals("ID00000011", simpleFeatures[11].getID()); assertEquals("ID00000022", simpleFeatures[22].getID()); } }
@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); } }