@Test public void testBuildFeatureType() { String input = CSVTestStrategySupport.buildInputString("lat,lon,quux,morx\n1.0,2.3,dkdkd,dkskd"); CSVFileState fileState = new CSVFileState(input, "foo"); CSVLatLonStrategy strategy = new CSVLatLonStrategy(fileState); SimpleFeatureType featureType = strategy.getFeatureType(); assertEquals("Invalid attribute count", 3, featureType.getAttributeCount()); assertEquals("Invalid featuretype name", "foo", featureType.getName().getLocalPart()); assertEquals("Invalid name", "foo", featureType.getTypeName()); List<AttributeDescriptor> attrs = featureType.getAttributeDescriptors(); assertEquals("Invalid number of attributes", 3, attrs.size()); List<String> attrNames = new ArrayList<>(2); for (AttributeDescriptor attr : attrs) { if (!(attr instanceof GeometryDescriptor)) { attrNames.add(attr.getName().getLocalPart()); } } Collections.sort(attrNames); assertEquals("Invalid property descriptor", "morx", attrNames.get(0)); assertEquals("Invalid property descriptor", "quux", attrNames.get(1)); GeometryDescriptor geometryDescriptor = featureType.getGeometryDescriptor(); GeometryType geometryType = geometryDescriptor.getType(); assertEquals("Invalid geometry name", "location", geometryType.getName().getLocalPart()); }
@Override protected SimpleFeatureType buildFeatureType() { String[] headers; Map<String, Class<?>> typesFromData; CSVReader csvReader = null; try { csvReader = csvFileState.openCSVReader(); headers = csvFileState.getCSVHeaders(); typesFromData = findMostSpecificTypesFromData(csvReader, headers); } catch (IOException | CsvValidationException e) { throw new RuntimeException(e); } finally { if (csvReader != null) { try { csvReader.close(); } catch (IOException e) { } } } SimpleFeatureTypeBuilder builder = createBuilder(csvFileState, headers, typesFromData); if (latField == null || lngField == null) { for (String col : headers) { if (isLatitude(col)) { latField = col; } else if (isLongitude(col)) { lngField = col; } } } Class<?> latClass = typesFromData.get(latField); Class<?> lngClass = typesFromData.get(lngField); if (isNumeric(latClass) && isNumeric(lngClass)) { List<String> csvHeaders = Arrays.asList(headers); int index = csvHeaders.indexOf(latField); AttributeTypeBuilder builder2 = new AttributeTypeBuilder(); builder2.setCRS(_CRS); builder2.binding(Point.class); AttributeDescriptor descriptor = builder2.buildDescriptor(pointField); builder.add(index, descriptor); builder.remove(latField); builder.remove(lngField); } return builder.buildFeatureType(); }
CSVLatLonStrategy extends CSVStrategy { @Override protected SimpleFeatureType buildFeatureType() { String[] headers; Map<String, Class<?>> typesFromData; CSVReader csvReader = null; try { csvReader = csvFileState.openCSVReader(); headers = csvFileState.getCSVHeaders(); typesFromData = findMostSpecificTypesFromData(csvReader, headers); } catch (IOException | CsvValidationException e) { throw new RuntimeException(e); } finally { if (csvReader != null) { try { csvReader.close(); } catch (IOException e) { } } } SimpleFeatureTypeBuilder builder = createBuilder(csvFileState, headers, typesFromData); if (latField == null || lngField == null) { for (String col : headers) { if (isLatitude(col)) { latField = col; } else if (isLongitude(col)) { lngField = col; } } } Class<?> latClass = typesFromData.get(latField); Class<?> lngClass = typesFromData.get(lngField); if (isNumeric(latClass) && isNumeric(lngClass)) { List<String> csvHeaders = Arrays.asList(headers); int index = csvHeaders.indexOf(latField); AttributeTypeBuilder builder2 = new AttributeTypeBuilder(); builder2.setCRS(_CRS); builder2.binding(Point.class); AttributeDescriptor descriptor = builder2.buildDescriptor(pointField); builder.add(index, descriptor); builder.remove(latField); builder.remove(lngField); } return builder.buildFeatureType(); } }
CSVLatLonStrategy extends CSVStrategy { @Override protected SimpleFeatureType buildFeatureType() { String[] headers; Map<String, Class<?>> typesFromData; CSVReader csvReader = null; try { csvReader = csvFileState.openCSVReader(); headers = csvFileState.getCSVHeaders(); typesFromData = findMostSpecificTypesFromData(csvReader, headers); } catch (IOException | CsvValidationException e) { throw new RuntimeException(e); } finally { if (csvReader != null) { try { csvReader.close(); } catch (IOException e) { } } } SimpleFeatureTypeBuilder builder = createBuilder(csvFileState, headers, typesFromData); if (latField == null || lngField == null) { for (String col : headers) { if (isLatitude(col)) { latField = col; } else if (isLongitude(col)) { lngField = col; } } } Class<?> latClass = typesFromData.get(latField); Class<?> lngClass = typesFromData.get(lngField); if (isNumeric(latClass) && isNumeric(lngClass)) { List<String> csvHeaders = Arrays.asList(headers); int index = csvHeaders.indexOf(latField); AttributeTypeBuilder builder2 = new AttributeTypeBuilder(); builder2.setCRS(_CRS); builder2.binding(Point.class); AttributeDescriptor descriptor = builder2.buildDescriptor(pointField); builder.add(index, descriptor); builder.remove(latField); builder.remove(lngField); } return builder.buildFeatureType(); } CSVLatLonStrategy(CSVFileState csvFileState);  CSVLatLonStrategy(CSVFileState csvFileState, String latField, String lngField);  CSVLatLonStrategy(
            CSVFileState csvFileState, String latField, String lngField, String pointField); }
CSVLatLonStrategy extends CSVStrategy { @Override protected SimpleFeatureType buildFeatureType() { String[] headers; Map<String, Class<?>> typesFromData; CSVReader csvReader = null; try { csvReader = csvFileState.openCSVReader(); headers = csvFileState.getCSVHeaders(); typesFromData = findMostSpecificTypesFromData(csvReader, headers); } catch (IOException | CsvValidationException e) { throw new RuntimeException(e); } finally { if (csvReader != null) { try { csvReader.close(); } catch (IOException e) { } } } SimpleFeatureTypeBuilder builder = createBuilder(csvFileState, headers, typesFromData); if (latField == null || lngField == null) { for (String col : headers) { if (isLatitude(col)) { latField = col; } else if (isLongitude(col)) { lngField = col; } } } Class<?> latClass = typesFromData.get(latField); Class<?> lngClass = typesFromData.get(lngField); if (isNumeric(latClass) && isNumeric(lngClass)) { List<String> csvHeaders = Arrays.asList(headers); int index = csvHeaders.indexOf(latField); AttributeTypeBuilder builder2 = new AttributeTypeBuilder(); builder2.setCRS(_CRS); builder2.binding(Point.class); AttributeDescriptor descriptor = builder2.buildDescriptor(pointField); builder.add(index, descriptor); builder.remove(latField); builder.remove(lngField); } return builder.buildFeatureType(); } 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 protected SimpleFeatureType buildFeatureType() { String[] headers; Map<String, Class<?>> typesFromData; CSVReader csvReader = null; try { csvReader = csvFileState.openCSVReader(); headers = csvFileState.getCSVHeaders(); typesFromData = findMostSpecificTypesFromData(csvReader, headers); } catch (IOException | CsvValidationException e) { throw new RuntimeException(e); } finally { if (csvReader != null) { try { csvReader.close(); } catch (IOException e) { } } } SimpleFeatureTypeBuilder builder = createBuilder(csvFileState, headers, typesFromData); if (latField == null || lngField == null) { for (String col : headers) { if (isLatitude(col)) { latField = col; } else if (isLongitude(col)) { lngField = col; } } } Class<?> latClass = typesFromData.get(latField); Class<?> lngClass = typesFromData.get(lngField); if (isNumeric(latClass) && isNumeric(lngClass)) { List<String> csvHeaders = Arrays.asList(headers); int index = csvHeaders.indexOf(latField); AttributeTypeBuilder builder2 = new AttributeTypeBuilder(); builder2.setCRS(_CRS); builder2.binding(Point.class); AttributeDescriptor descriptor = builder2.buildDescriptor(pointField); builder.add(index, descriptor); builder.remove(latField); builder.remove(lngField); } return builder.buildFeatureType(); } 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; }