@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 CSVLatLonStrategy(csvFileState, "lat_field", "long_field"); strategy.createSchema(featureType); assertEquals( "Stragegy does not have provided feature type", featureType, strategy.getFeatureType()); List<String> content = Files.readAllLines(csvFile.toPath()); assertEquals("long_field,lat_field,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<String>(); GeometryDescriptor gd = featureType.getGeometryDescriptor(); CoordinateReferenceSystem crs = gd != null ? gd.getCoordinateReferenceSystem() : null; if (gd != null && CRS.equalsIgnoreMetadata(_CRS, crs) && gd.getType().getBinding().isAssignableFrom(Point.class)) { if (crs.getCoordinateSystem().getAxis(0).getDirection().equals(AxisDirection.NORTH)) { header.add(this.latField); header.add(this.lngField); } else { header.add(this.lngField); header.add(this.latField); } } else { throw new IOException( "Unable use " + this.latField + "/" + this.lngField + " to represent " + gd); } for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) { if (descriptor instanceof GeometryDescriptor) continue; 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(); } }
CSVLatLonStrategy extends CSVStrategy { @Override public void createSchema(SimpleFeatureType featureType) throws IOException { this.featureType = featureType; List<String> header = new ArrayList<String>(); GeometryDescriptor gd = featureType.getGeometryDescriptor(); CoordinateReferenceSystem crs = gd != null ? gd.getCoordinateReferenceSystem() : null; if (gd != null && CRS.equalsIgnoreMetadata(_CRS, crs) && gd.getType().getBinding().isAssignableFrom(Point.class)) { if (crs.getCoordinateSystem().getAxis(0).getDirection().equals(AxisDirection.NORTH)) { header.add(this.latField); header.add(this.lngField); } else { header.add(this.lngField); header.add(this.latField); } } else { throw new IOException( "Unable use " + this.latField + "/" + this.lngField + " to represent " + gd); } for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) { if (descriptor instanceof GeometryDescriptor) continue; 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(); } } }
CSVLatLonStrategy extends CSVStrategy { @Override public void createSchema(SimpleFeatureType featureType) throws IOException { this.featureType = featureType; List<String> header = new ArrayList<String>(); GeometryDescriptor gd = featureType.getGeometryDescriptor(); CoordinateReferenceSystem crs = gd != null ? gd.getCoordinateReferenceSystem() : null; if (gd != null && CRS.equalsIgnoreMetadata(_CRS, crs) && gd.getType().getBinding().isAssignableFrom(Point.class)) { if (crs.getCoordinateSystem().getAxis(0).getDirection().equals(AxisDirection.NORTH)) { header.add(this.latField); header.add(this.lngField); } else { header.add(this.lngField); header.add(this.latField); } } else { throw new IOException( "Unable use " + this.latField + "/" + this.lngField + " to represent " + gd); } for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) { if (descriptor instanceof GeometryDescriptor) continue; 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(); } } CSVLatLonStrategy(CSVFileState csvFileState);  CSVLatLonStrategy(CSVFileState csvFileState, String latField, String lngField);  CSVLatLonStrategy(
            CSVFileState csvFileState, String latField, String lngField, String pointField); }
CSVLatLonStrategy extends CSVStrategy { @Override public void createSchema(SimpleFeatureType featureType) throws IOException { this.featureType = featureType; List<String> header = new ArrayList<String>(); GeometryDescriptor gd = featureType.getGeometryDescriptor(); CoordinateReferenceSystem crs = gd != null ? gd.getCoordinateReferenceSystem() : null; if (gd != null && CRS.equalsIgnoreMetadata(_CRS, crs) && gd.getType().getBinding().isAssignableFrom(Point.class)) { if (crs.getCoordinateSystem().getAxis(0).getDirection().equals(AxisDirection.NORTH)) { header.add(this.latField); header.add(this.lngField); } else { header.add(this.lngField); header.add(this.latField); } } else { throw new IOException( "Unable use " + this.latField + "/" + this.lngField + " to represent " + gd); } for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) { if (descriptor instanceof GeometryDescriptor) continue; 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(); } } CSVLatLonStrategy(CSVFileState csvFileState);  CSVLatLonStrategy(CSVFileState csvFileState, String latField, String lngField);  CSVLatLonStrategy(
            CSVFileState csvFileState, String latField, String lngField, String pointField); @Override void createSchema(SimpleFeatureType featureType); @Override SimpleFeature decode(String recordId, String[] csvRecord); @Override String[] encode(SimpleFeature feature); }
CSVLatLonStrategy extends CSVStrategy { @Override public void createSchema(SimpleFeatureType featureType) throws IOException { this.featureType = featureType; List<String> header = new ArrayList<String>(); GeometryDescriptor gd = featureType.getGeometryDescriptor(); CoordinateReferenceSystem crs = gd != null ? gd.getCoordinateReferenceSystem() : null; if (gd != null && CRS.equalsIgnoreMetadata(_CRS, crs) && gd.getType().getBinding().isAssignableFrom(Point.class)) { if (crs.getCoordinateSystem().getAxis(0).getDirection().equals(AxisDirection.NORTH)) { header.add(this.latField); header.add(this.lngField); } else { header.add(this.lngField); header.add(this.latField); } } else { throw new IOException( "Unable use " + this.latField + "/" + this.lngField + " to represent " + gd); } for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) { if (descriptor instanceof GeometryDescriptor) continue; 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(); } } CSVLatLonStrategy(CSVFileState csvFileState);  CSVLatLonStrategy(CSVFileState csvFileState, String latField, String lngField);  CSVLatLonStrategy(
            CSVFileState csvFileState, String latField, String lngField, String pointField); @Override void createSchema(SimpleFeatureType featureType); @Override SimpleFeature decode(String recordId, String[] csvRecord); @Override String[] encode(SimpleFeature feature); static final DefaultGeographicCRS _CRS; }