use of org.codice.ddf.spatial.geocoding.FeatureExtractionException in project ddf by codice.
the class GazetteerUpdateCommandTest method testFeatureIndexing.
@Test
public void testFeatureIndexing() throws Exception {
String resource = "example.geojson";
final FeatureExtractor featureExtractor = spy(new FeatureExtractor() {
@Override
public void pushFeaturesToExtractionCallback(String resource, ExtractionCallback extractionCallback) throws FeatureExtractionException {
/* stub */
}
});
final FeatureIndexer featureIndexer = spy(new FeatureIndexer() {
@Override
public void updateIndex(String resource, FeatureExtractor featureExtractor, boolean create, IndexCallback callback) throws FeatureExtractionException, FeatureIndexingException {
/* stub */
}
});
gazetteerUpdateCommand.setResource(resource);
gazetteerUpdateCommand.setFeatureExtractor(featureExtractor);
gazetteerUpdateCommand.setFeatureIndexer(featureIndexer);
gazetteerUpdateCommand.executeWithSubject();
verify(featureIndexer, times(1)).updateIndex(eq(resource), eq(featureExtractor), eq(false), any(FeatureIndexer.IndexCallback.class));
}
use of org.codice.ddf.spatial.geocoding.FeatureExtractionException in project ddf by codice.
the class GeoJSONFeatureExtractor method pushFeaturesToExtractionCallback.
@Override
public void pushFeaturesToExtractionCallback(String resource, ExtractionCallback extractionCallback) throws FeatureExtractionException {
Validate.notNull(extractionCallback, "extractionCallback can't be null");
Validate.notNull(resource, "resource can't be null");
File file = new File(resource);
if (file.length() == 0) {
throw new FeatureExtractionException("Empty resource");
}
FeatureIterator<SimpleFeature> iterator = null;
try (Reader reader = new InputStreamReader(new FileInputStream(file), "UTF-8")) {
iterator = getFeatureIterator(reader);
while (iterator != null && iterator.hasNext()) {
SimpleFeature feature = iterator.next();
Object featureGeometry = feature.getDefaultGeometry();
if (featureGeometry instanceof Geometry) {
Geometry geometry = (Geometry) feature.getDefaultGeometry();
if (geometry == null) {
LOGGER.debug("Failed to get geometry from {}", resource);
continue;
}
Geometry simplifiedGeometry = getSimplifiedGeometry(geometry);
if (simplifiedGeometry == null) {
LOGGER.debug("Failed to simplify geometry below {} point maximum", MAX_POINTS_PER_FEATURE);
} else {
feature.setDefaultGeometry(simplifiedGeometry);
extractionCallback.extracted(feature);
}
}
}
} catch (IOException | FeatureIndexingException e) {
throw new FeatureExtractionException("Unable to extract feature from " + resource, e);
} finally {
if (iterator != null) {
iterator.close();
}
}
}
use of org.codice.ddf.spatial.geocoding.FeatureExtractionException in project ddf by codice.
the class GazetteerUpdateCommand method executeWithSubject.
@Override
protected Object executeWithSubject() throws Exception {
final PrintStream console = System.out;
final ProgressCallback progressCallback = progress -> {
console.printf("\r%d%%", progress);
console.flush();
};
final FeatureIndexer.IndexCallback featureIndexCallback = count -> {
console.printf("\r%d features indexed", count);
console.flush();
};
console.println("Updating...");
try {
if (isResourceGeoJSON()) {
featureIndexer.updateIndex(resource, featureExtractor, create, featureIndexCallback);
} else {
geoEntryIndexer.updateIndex(resource, geoEntryExtractor, create, progressCallback);
}
console.println("\nDone.");
} catch (GeoEntryExtractionException | FeatureExtractionException e) {
LOGGER.info("Error extracting data from resource {}", resource, e);
console.printf("Could not extract data from resource %s.%n Message: %s%n Check the logs for more details.%n", resource, e.getMessage());
} catch (GeoEntryIndexingException | FeatureIndexingException e) {
LOGGER.info("Error indexing data", e);
console.printf("Could not index the data.%n Message: %s%n Check the logs for more details.%n", e.getMessage());
} catch (GeoNamesRemoteDownloadException e) {
LOGGER.info("Error downloading resource from remote source {}", resource, e);
console.printf("Could not download the GeoNames file %s.%n Message: %s%n Check the logs for more details.%n", resource, e.getMessage());
}
return null;
}
Aggregations