use of org.locationtech.geowave.adapter.vector.export.VectorLocalExportCommand in project geowave by locationtech.
the class AbstractGeoWaveBasicVectorIT method exportWithCQL.
protected static File exportWithCQL(final DataStorePluginOptions dataStoreOptions, final URL filterUrl, final DimensionalityType dimensionalityType) throws Exception {
Geometry filterGeometry = null;
Date startDate = null, endDate = null;
if (filterUrl != null) {
final SimpleFeature savedFilter = TestUtils.resourceToFeature(filterUrl);
filterGeometry = (Geometry) savedFilter.getDefaultGeometry();
final Object startObj = savedFilter.getAttribute(TestUtils.TEST_FILTER_START_TIME_ATTRIBUTE_NAME);
final Object endObj = savedFilter.getAttribute(TestUtils.TEST_FILTER_END_TIME_ATTRIBUTE_NAME);
if ((startObj != null) && (endObj != null)) {
// query
if (startObj instanceof Calendar) {
startDate = ((Calendar) startObj).getTime();
} else if (startObj instanceof Date) {
startDate = (Date) startObj;
}
if (endObj instanceof Calendar) {
endDate = ((Calendar) endObj).getTime();
} else if (endObj instanceof Date) {
endDate = (Date) endObj;
}
}
}
final PersistentAdapterStore adapterStore = dataStoreOptions.createAdapterStore();
final VectorLocalExportCommand exportCommand = new VectorLocalExportCommand();
final VectorLocalExportOptions options = exportCommand.getOptions();
final File exportDir = new File(TestUtils.TEMP_DIR, TEST_LOCAL_EXPORT_DIRECTORY);
FileUtils.deleteDirectory(exportDir);
if (!exportDir.mkdirs()) {
LOGGER.warn("Unable to create directory: " + exportDir.getAbsolutePath());
}
exportCommand.setParameters("test");
final File configFile = File.createTempFile("test_export", null);
final ManualOperationParams params = new ManualOperationParams();
params.getContext().put(ConfigOptions.PROPERTIES_FILE_CONTEXT, configFile);
final AddStoreCommand addStore = new AddStoreCommand();
addStore.setParameters("test");
addStore.setPluginOptions(dataStoreOptions);
addStore.execute(params);
options.setBatchSize(10000);
final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
for (final InternalDataAdapter<?> adapter : adapters) {
options.setTypeNames(Lists.newArrayList(adapter.getTypeName()));
if ((adapter.getAdapter() instanceof GeotoolsFeatureDataAdapter) && (filterGeometry != null) && (startDate != null) && (endDate != null)) {
final GeotoolsFeatureDataAdapter gtAdapter = (GeotoolsFeatureDataAdapter) adapter.getAdapter();
final TimeDescriptors timeDesc = gtAdapter.getTimeDescriptors();
String startTimeAttribute;
if (timeDesc.getStartRange() != null) {
startTimeAttribute = timeDesc.getStartRange().getLocalName();
} else {
startTimeAttribute = timeDesc.getTime().getLocalName();
}
final String endTimeAttribute;
if (timeDesc.getEndRange() != null) {
endTimeAttribute = timeDesc.getEndRange().getLocalName();
} else {
endTimeAttribute = timeDesc.getTime().getLocalName();
}
final String geometryAttribute = gtAdapter.getFeatureType().getGeometryDescriptor().getLocalName();
final Envelope env = filterGeometry.getEnvelopeInternal();
final double east = env.getMaxX();
final double west = env.getMinX();
final double south = env.getMinY();
final double north = env.getMaxY();
final String cqlPredicate = String.format("BBOX(\"%s\",%f,%f,%f,%f) AND \"%s\" <= '%s' AND \"%s\" >= '%s'", geometryAttribute, west, south, east, north, startTimeAttribute, CQL_DATE_FORMAT.format(endDate), endTimeAttribute, CQL_DATE_FORMAT.format(startDate));
options.setCqlFilter(cqlPredicate);
}
options.setOutputFile(new File(exportDir, adapter.getTypeName() + TEST_BASE_EXPORT_FILE_NAME));
exportCommand.execute(params);
}
TestUtils.deleteAll(dataStoreOptions);
return exportDir;
}
Aggregations