CSVSpecifiedLatLngStrategy extends CSVStrategy { @Override protected SimpleFeatureType buildFeatureType() { String[] headers; Map<String, Class<?>> typesFromData; CsvReader csvReader = null; try { csvReader = csvFileState.openCSVReader(); headers = csvReader.getHeaders(); typesFromData = CSVStrategy.findMostSpecificTypesFromData(csvReader, headers); } catch (IOException e) { throw new RuntimeException(e); } finally { if (csvReader != null) { csvReader.close(); } } SimpleFeatureTypeBuilder builder = CSVStrategy.createBuilder(csvFileState, headers, typesFromData); Class<?> latClass = typesFromData.get(latField); Class<?> lngClass = typesFromData.get(lngField); if (CSVStrategy.isNumeric(latClass) && CSVStrategy.isNumeric(lngClass)) { List<String> csvHeaders = Arrays.asList(headers); int index = csvHeaders.indexOf(latField); AttributeTypeBuilder builder2 = new AttributeTypeBuilder(); builder2.setCRS(DefaultGeographicCRS.WGS84); builder2.binding(Point.class); AttributeDescriptor descriptor = builder2.buildDescriptor(pointField); builder.add(index, descriptor); builder.remove(latField); builder.remove(lngField); } return builder.buildFeatureType(); } CSVSpecifiedLatLngStrategy(CSVFileState csvFileState, String latField, String lngField,
            String pointField);  CSVSpecifiedLatLngStrategy(CSVFileState csvFileState, String latField, String lngField); @Override void createSchema(SimpleFeatureType featureType); @Override String[] encode(SimpleFeature feature); @Override SimpleFeature decode(String recordId, String[] csvRecord);  }
@Test public void testBuildFeatureType() { String input = CSVTestStrategySupport.buildInputString("quux,morx\n"); CSVFileState fileState = new CSVFileState(input, "foo"); CSVStrategy strategy = new CSVSpecifiedLatLngStrategy(fileState, "quux", "morx"); SimpleFeatureType featureType = strategy.getFeatureType(); assertEquals("Invalid attribute count", 1, featureType.getAttributeCount()); assertEquals("Invalid featuretype name", "foo", featureType.getName().getLocalPart()); assertEquals("Invalid name", "foo", featureType.getTypeName()); GeometryDescriptor geometryDescriptor = featureType.getGeometryDescriptor(); assertEquals("Invalid geometry attribute name", "location", geometryDescriptor.getLocalName()); }