Search in sources :

Example 1 with VectorLocalExportCommand

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;
}
Also used : TimeDescriptors(org.locationtech.geowave.core.geotime.util.TimeDescriptors) Calendar(java.util.Calendar) AddStoreCommand(org.locationtech.geowave.core.store.cli.store.AddStoreCommand) Envelope(org.locationtech.jts.geom.Envelope) Date(java.util.Date) SimpleFeature(org.opengis.feature.simple.SimpleFeature) ManualOperationParams(org.locationtech.geowave.core.cli.parser.ManualOperationParams) Geometry(org.locationtech.jts.geom.Geometry) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) GeotoolsFeatureDataAdapter(org.locationtech.geowave.core.geotime.store.GeotoolsFeatureDataAdapter) InternalGeotoolsFeatureDataAdapter(org.locationtech.geowave.core.geotime.store.InternalGeotoolsFeatureDataAdapter) VectorLocalExportCommand(org.locationtech.geowave.adapter.vector.export.VectorLocalExportCommand) VectorLocalExportOptions(org.locationtech.geowave.adapter.vector.export.VectorLocalExportOptions) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) File(java.io.File)

Aggregations

File (java.io.File)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 VectorLocalExportCommand (org.locationtech.geowave.adapter.vector.export.VectorLocalExportCommand)1 VectorLocalExportOptions (org.locationtech.geowave.adapter.vector.export.VectorLocalExportOptions)1 ManualOperationParams (org.locationtech.geowave.core.cli.parser.ManualOperationParams)1 GeotoolsFeatureDataAdapter (org.locationtech.geowave.core.geotime.store.GeotoolsFeatureDataAdapter)1 InternalGeotoolsFeatureDataAdapter (org.locationtech.geowave.core.geotime.store.InternalGeotoolsFeatureDataAdapter)1 TimeDescriptors (org.locationtech.geowave.core.geotime.util.TimeDescriptors)1 InternalDataAdapter (org.locationtech.geowave.core.store.adapter.InternalDataAdapter)1 PersistentAdapterStore (org.locationtech.geowave.core.store.adapter.PersistentAdapterStore)1 AddStoreCommand (org.locationtech.geowave.core.store.cli.store.AddStoreCommand)1 Envelope (org.locationtech.jts.geom.Envelope)1 Geometry (org.locationtech.jts.geom.Geometry)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1