@Test public void testCreateSchema() throws IOException { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setCRS(DefaultGeographicCRS.WGS84); builder.setName("testCreateSchema"); builder.add("the_geom", Point.class); builder.add("id", Integer.class); builder.add("int_field", Integer.class); builder.add("string_field", String.class); SimpleFeatureType featureType = builder.buildFeatureType(); File csvFile = File.createTempFile("testCreateSchema", ".csv"); CSVFileState csvFileState = new CSVFileState(csvFile); CSVStrategy strategy = new CSVSpecifiedWKTStrategy(csvFileState, "the_geom_wkt"); strategy.createSchema(featureType); assertEquals( "Stragegy does not have provided feature type", featureType, strategy.getFeatureType()); List<String> content = Files.readAllLines(csvFile.toPath()); assertEquals("the_geom_wkt,id,int_field,string_field", content.get(0)); csvFile.delete(); }
@Override public void createSchema(SimpleFeatureType featureType) throws IOException { this.featureType = featureType; List<String> header = new ArrayList<>(); for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) { if (descriptor instanceof GeometryDescriptor) { header.add(wktField); } else { header.add(descriptor.getLocalName()); } } CSVWriter writer = new CSVWriter( new FileWriter(this.csvFileState.getFile()), getSeparator(), getQuotechar(), getEscapechar(), getLineSeparator()); try { writer.writeNext(header.toArray(new String[header.size()]), isQuoteAllFields()); } finally { writer.close(); } }
CSVSpecifiedWKTStrategy extends CSVStrategy { @Override public void createSchema(SimpleFeatureType featureType) throws IOException { this.featureType = featureType; List<String> header = new ArrayList<>(); for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) { if (descriptor instanceof GeometryDescriptor) { header.add(wktField); } else { header.add(descriptor.getLocalName()); } } CSVWriter writer = new CSVWriter( new FileWriter(this.csvFileState.getFile()), getSeparator(), getQuotechar(), getEscapechar(), getLineSeparator()); try { writer.writeNext(header.toArray(new String[header.size()]), isQuoteAllFields()); } finally { writer.close(); } } }
CSVSpecifiedWKTStrategy extends CSVStrategy { @Override public void createSchema(SimpleFeatureType featureType) throws IOException { this.featureType = featureType; List<String> header = new ArrayList<>(); for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) { if (descriptor instanceof GeometryDescriptor) { header.add(wktField); } else { header.add(descriptor.getLocalName()); } } CSVWriter writer = new CSVWriter( new FileWriter(this.csvFileState.getFile()), getSeparator(), getQuotechar(), getEscapechar(), getLineSeparator()); try { writer.writeNext(header.toArray(new String[header.size()]), isQuoteAllFields()); } finally { writer.close(); } } CSVSpecifiedWKTStrategy(CSVFileState csvFileState, String wktField); }
CSVSpecifiedWKTStrategy extends CSVStrategy { @Override public void createSchema(SimpleFeatureType featureType) throws IOException { this.featureType = featureType; List<String> header = new ArrayList<>(); for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) { if (descriptor instanceof GeometryDescriptor) { header.add(wktField); } else { header.add(descriptor.getLocalName()); } } CSVWriter writer = new CSVWriter( new FileWriter(this.csvFileState.getFile()), getSeparator(), getQuotechar(), getEscapechar(), getLineSeparator()); try { writer.writeNext(header.toArray(new String[header.size()]), isQuoteAllFields()); } finally { writer.close(); } } CSVSpecifiedWKTStrategy(CSVFileState csvFileState, String wktField); @Override void createSchema(SimpleFeatureType featureType); @Override String[] encode(SimpleFeature feature); @Override SimpleFeature decode(String recordId, String[] csvRecord); }
CSVSpecifiedWKTStrategy extends CSVStrategy { @Override public void createSchema(SimpleFeatureType featureType) throws IOException { this.featureType = featureType; List<String> header = new ArrayList<>(); for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) { if (descriptor instanceof GeometryDescriptor) { header.add(wktField); } else { header.add(descriptor.getLocalName()); } } CSVWriter writer = new CSVWriter( new FileWriter(this.csvFileState.getFile()), getSeparator(), getQuotechar(), getEscapechar(), getLineSeparator()); try { writer.writeNext(header.toArray(new String[header.size()]), isQuoteAllFields()); } finally { writer.close(); } } CSVSpecifiedWKTStrategy(CSVFileState csvFileState, String wktField); @Override void createSchema(SimpleFeatureType featureType); @Override String[] encode(SimpleFeature feature); @Override SimpleFeature decode(String recordId, String[] csvRecord);  }