VectorDataNodeReader { static FeatureCollection<SimpleFeatureType, SimpleFeature> convertPointsToVertices(FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection) { final FeatureIterator<SimpleFeature> featureIterator = featureCollection.features(); List<Coordinate> coordList = new ArrayList<Coordinate>(); while (featureIterator.hasNext()) { final SimpleFeature feature = featureIterator.next(); final Point pt = (Point) feature.getDefaultGeometry(); coordList.add(pt.getCoordinate()); } if (coordList.size() >= 2) { final GeometryFactory geometryFactory = new GeometryFactory(); SimpleFeatureType featureType; SimpleFeatureBuilder featureBuilder; SimpleFeature feature; try { if (isClosedPolygon(coordList)) { featureType = DataUtilities.createType("Geometry", "geometry:Polygon"); featureBuilder = new SimpleFeatureBuilder(featureType); feature = featureBuilder.buildFeature(Integer.toString(coordList.size() + 1)); final LinearRing polygon = geometryFactory.createLinearRing(coordList.toArray(new Coordinate[coordList.size()])); feature.setDefaultGeometry(polygon); } else { featureType = DataUtilities.createType("Geometry", "geometry:LineString"); featureBuilder = new SimpleFeatureBuilder(featureType); feature = featureBuilder.buildFeature(Integer.toString(coordList.size() + 1)); final LineString lineString = geometryFactory.createLineString(coordList.toArray(new Coordinate[coordList.size()])); feature.setDefaultGeometry(lineString); } } catch (SchemaException e) { BeamLogManager.getSystemLogger().warning("Cannot create line/polygon geometry: " + e.getMessage() + " --> Will interpret points as they are."); return featureCollection; } FeatureCollection<SimpleFeatureType, SimpleFeature> vertexCollection = new DefaultFeatureCollection(featureCollection.getID() + "_vertex", featureType); vertexCollection.add(feature); return vertexCollection; } else { return featureCollection; } } private  VectorDataNodeReader(String sourceName, Product product, Reader reader, FeatureUtils.FeatureCrsProvider crsProvider,
                                 PlacemarkDescriptorProvider placemarkDescriptorProvider, boolean convertToVertices, char delimiterChar); static VectorDataNode read(String sourceName, Reader reader, Product product, FeatureUtils.FeatureCrsProvider crsProvider,
                                      PlacemarkDescriptorProvider placemarkDescriptorProvider, CoordinateReferenceSystem modelCrs,
                                      char delimiterChar, ProgressMonitor pm); static VectorDataNode read(String sourceName, Reader reader, Product product, FeatureUtils.FeatureCrsProvider crsProvider,
                                      PlacemarkDescriptorProvider placemarkDescriptorProvider, CoordinateReferenceSystem modelCrs,
                                      char delimiterChar, boolean convertToVertices, ProgressMonitor pm);  }
@Test public void testConvertPointsToVertices() throws IOException { InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("exported_pin_input1.csv")); final VectorDataNode dataNode = VectorDataNodeReader.read("blah", reader, createDummyProduct(), crsProvider, placemarkDescriptorProvider, DefaultGeographicCRS.WGS84, VectorDataNodeIO.DEFAULT_DELIMITER_CHAR, ProgressMonitor.NULL); FeatureCollection<SimpleFeatureType, SimpleFeature> fc = dataNode.getFeatureCollection(); final FeatureCollection<SimpleFeatureType, SimpleFeature> vertexFeatureCollection = VectorDataNodeReader.convertPointsToVertices(fc); assertNotNull(vertexFeatureCollection); assertEquals(1, vertexFeatureCollection.size()); final SimpleFeature feature = vertexFeatureCollection.features().next(); assertEquals(1, feature.getAttributeCount()); final String expected = "LINESTRING (7.777766 47.96903, 1.5681322 45.38434, 0.6210307 45.669746, 7.8942046 43.675922, 6.9614143 46.88921, 5.0080223 46.710358)"; assertEquals(expected, feature.getAttribute(0).toString()); final Object geometry = feature.getDefaultGeometry(); assertNotNull(geometry); assertTrue(geometry instanceof LineString); final LineString lineString = (LineString) geometry; assertEquals(6, lineString.getCoordinates().length); assertEquals(7.777766, lineString.getCoordinates()[0].x, 1.E-6); assertEquals(47.96903, lineString.getCoordinates()[0].y, 1.E-6); assertEquals(1.5681322, lineString.getCoordinates()[1].x, 1.E-6); assertEquals(45.38434, lineString.getCoordinates()[1].y, 1.E-6); assertEquals(5.0080223, lineString.getCoordinates()[5].x, 1.E-6); assertEquals(46.710358, lineString.getCoordinates()[5].y, 1.E-6); }