VectorDataNodeReader { public static VectorDataNode read(String sourceName, Reader reader, Product product, FeatureUtils.FeatureCrsProvider crsProvider, PlacemarkDescriptorProvider placemarkDescriptorProvider, CoordinateReferenceSystem modelCrs, char delimiterChar, ProgressMonitor pm) throws IOException { return new VectorDataNodeReader(sourceName, product, reader, crsProvider, placemarkDescriptorProvider, true, delimiterChar).read(modelCrs, pm); } 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(expected = IOException.class) public void testMissingGeometry() throws IOException { InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("exported_pin_input_without_geometry.csv")); Product dummyProduct = createDummyProduct(); VectorDataNodeReader.read("blah", reader, dummyProduct, crsProvider, placemarkDescriptorProvider, DefaultGeographicCRS.WGS84, VectorDataNodeIO.DEFAULT_DELIMITER_CHAR, ProgressMonitor.NULL); }
@Test public void testReadPropertiesInInput1() throws IOException { InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("input_with_properties.csv")); final VectorDataNode dataNode = VectorDataNodeReader.read("non-empty", reader, createDummyProduct(), crsProvider, placemarkDescriptorProvider, DefaultGeographicCRS.WGS84, VectorDataNodeIO.DEFAULT_DELIMITER_CHAR, ProgressMonitor.NULL); final Map<Object, Object> properties = dataNode.getFeatureType().getUserData(); assertNotNull(properties); assertEquals(4, properties.size()); assertEquals("color:0,0,255", properties.get("styleCss")); assertEquals("TAB", properties.get("separator")); assertEquals("org.esa.beam.framework.datamodel.GeometryDescriptor", properties.get("placemarkDescriptor")); assertEquals("geom", properties.get("defaultGeometry")); }
@Test public void testReadFeaturesInInput1() throws IOException { InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("input_with_properties.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(); SimpleFeatureType simpleFeatureType = fc.getSchema(); assertNotNull(simpleFeatureType); assertNotNull(simpleFeatureType.getCoordinateReferenceSystem()); assertEquals("org.esa.beam.FT1", simpleFeatureType.getTypeName()); assertEquals(4, simpleFeatureType.getAttributeCount()); List<AttributeDescriptor> list = simpleFeatureType.getAttributeDescriptors(); AttributeDescriptor ad0 = list.get(0); AttributeDescriptor ad1 = list.get(1); AttributeDescriptor ad2 = list.get(2); AttributeDescriptor ad3 = list.get(3); assertEquals("name", ad0.getType().getName().getLocalPart()); assertEquals(String.class, ad0.getType().getBinding()); assertEquals("geom", ad1.getType().getName().getLocalPart()); assertEquals(Geometry.class, ad1.getType().getBinding()); assertEquals("pixel", ad2.getType().getName().getLocalPart()); assertEquals(Integer.class, ad2.getType().getBinding()); assertEquals("description", ad3.getType().getName().getLocalPart()); assertEquals(String.class, ad3.getType().getBinding()); GeometryDescriptor geometryDescriptor = simpleFeatureType.getGeometryDescriptor(); assertEquals("geom", geometryDescriptor.getType().getName().getLocalPart()); assertEquals(3, fc.size()); FeatureIterator<SimpleFeature> featureIterator = fc.features(); SimpleFeature f1 = featureIterator.next(); assertEquals("ID65", f1.getID()); assertEquals("mark1", f1.getAttribute(0)); assertEquals(0, f1.getAttribute(2)); assertEquals("This is mark1.", f1.getAttribute(3)); SimpleFeature f2 = featureIterator.next(); assertEquals("ID66", f2.getID()); assertEquals("mark2", f2.getAttribute(0)); assertEquals(1, f2.getAttribute(2)); assertEquals(null, f2.getAttribute(3)); SimpleFeature f3 = featureIterator.next(); assertEquals("ID67", f3.getID()); assertEquals("mark3", f3.getAttribute(0)); assertEquals(2, f3.getAttribute(2)); assertEquals("This is mark3.", f3.getAttribute(3)); }
@Test public void testReadFeaturesInInput2() throws IOException { InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("input_with_only_one_point.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(); SimpleFeatureType simpleFeatureType = fc.getSchema(); assertNotNull(simpleFeatureType); assertEquals("org.esa.beam.FT2", simpleFeatureType.getTypeName()); assertEquals(3, simpleFeatureType.getAttributeCount()); List<AttributeDescriptor> list = simpleFeatureType.getAttributeDescriptors(); AttributeDescriptor ad0 = list.get(0); AttributeDescriptor ad1 = list.get(1); AttributeDescriptor ad2 = list.get(2); assertEquals("name", ad0.getType().getName().getLocalPart()); assertEquals(String.class, ad0.getType().getBinding()); assertEquals("geom", ad1.getType().getName().getLocalPart()); assertEquals(Point.class, ad1.getType().getBinding()); assertEquals("weight", ad2.getType().getName().getLocalPart()); assertEquals(Float.class, ad2.getType().getBinding()); }
@Test public void testCRS() throws Exception { InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("input_with_only_one_point.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(); SimpleFeatureType simpleFeatureType = fc.getSchema(); assertNotNull(simpleFeatureType); CoordinateReferenceSystem crs = simpleFeatureType.getCoordinateReferenceSystem(); assertNotNull(crs); }
@Test public void testWrongUsages() { try { expectException(""); } catch (IOException expected) { } try { expectException("org.esa.beam.FT\ta:\n"); } catch (IOException expected) { } try { expectException("org.esa.beam.FT\t:Integer\n"); } catch (IOException expected) { } try { expectException("org.esa.beam.FT\ta:Integer\tlat\tlon\n" + "ID1\t1234\tABC\n"); } catch (IOException expected) { } try { VectorDataNodeReader.read("blah", new StringReader("org.esa.beam.FT\ta:Integer\tno_lat\tlon\n" + "ID1\t1234\tABC\n"), new Product("name", "type", 360, 90), crsProvider, placemarkDescriptorProvider, DefaultGeographicCRS.WGS84, VectorDataNodeIO.DEFAULT_DELIMITER_CHAR, ProgressMonitor.NULL).getFeatureCollection(); } catch (IOException expected) { } try { String source = "org.esa.beam.FT\ta\tlat\tlon\n" + "ID1\t10\t5.0\t50.0\n"; FeatureCollection<SimpleFeatureType, SimpleFeature> fc = VectorDataNodeReader.read("blah", new StringReader(source), createDummyProduct(), crsProvider, placemarkDescriptorProvider, DefaultGeographicCRS.WGS84, VectorDataNodeIO.DEFAULT_DELIMITER_CHAR, ProgressMonitor.NULL).getFeatureCollection(); assertEquals(1, fc.size()); assertEquals(Double.class, fc.getSchema().getType(0).getBinding()); assertEquals(10.0, fc.features().next().getAttribute("a")); } catch (IOException e) { fail("Not expected: IOException: " + e.getMessage()); } }