use of org.locationtech.geowave.core.geotime.util.ExtractGeometryFilterVisitorResult in project geowave by locationtech.
the class KMeansRunner method run.
public void run() throws IOException {
initContext();
// Validate inputs
if (inputDataStore == null) {
LOGGER.error("You must supply an input datastore!");
throw new IOException("You must supply an input datastore!");
}
if (isUseTime()) {
scaledRange = KMeansUtils.setRunnerTimeParams(this, inputDataStore, typeName);
if (scaledRange == null) {
LOGGER.error("Failed to set time params for kmeans. Please specify a valid feature type.");
throw new ParameterException("--useTime option: Failed to set time params");
}
}
// Retrieve the feature adapters
final VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder();
List<String> featureTypeNames;
// If provided, just use the one
if (typeName != null) {
featureTypeNames = new ArrayList<>();
featureTypeNames.add(typeName);
} else {
// otherwise, grab all the feature adapters
featureTypeNames = FeatureDataUtils.getFeatureTypeNames(inputDataStore);
}
bldr.setTypeNames(featureTypeNames.toArray(new String[0]));
// This is required due to some funkiness in GeoWaveInputFormat
final PersistentAdapterStore adapterStore = inputDataStore.createAdapterStore();
final InternalAdapterStore internalAdapterStore = inputDataStore.createInternalAdapterStore();
// Add a spatial filter if requested
try {
if (cqlFilter != null) {
Geometry bbox = null;
String cqlTypeName;
if (typeName == null) {
cqlTypeName = featureTypeNames.get(0);
} else {
cqlTypeName = typeName;
}
final short adapterId = internalAdapterStore.getAdapterId(cqlTypeName);
final DataTypeAdapter<?> adapter = adapterStore.getAdapter(adapterId).getAdapter();
if (adapter instanceof GeotoolsFeatureDataAdapter) {
final String geometryAttribute = ((GeotoolsFeatureDataAdapter) adapter).getFeatureType().getGeometryDescriptor().getLocalName();
Filter filter;
filter = ECQL.toFilter(cqlFilter);
final ExtractGeometryFilterVisitorResult geoAndCompareOpData = (ExtractGeometryFilterVisitorResult) filter.accept(new ExtractGeometryFilterVisitor(GeometryUtils.getDefaultCRS(), geometryAttribute), null);
bbox = geoAndCompareOpData.getGeometry();
}
if ((bbox != null) && !bbox.equals(GeometryUtils.infinity())) {
bldr.constraints(bldr.constraintsFactory().spatialTemporalConstraints().spatialConstraints(bbox).build());
}
}
} catch (final CQLException e) {
LOGGER.error("Unable to parse CQL: " + cqlFilter);
}
// Load RDD from datastore
final RDDOptions kmeansOpts = new RDDOptions();
kmeansOpts.setMinSplits(minSplits);
kmeansOpts.setMaxSplits(maxSplits);
kmeansOpts.setQuery(bldr.build());
final GeoWaveRDD kmeansRDD = GeoWaveRDDLoader.loadRDD(session.sparkContext(), inputDataStore, kmeansOpts);
// Retrieve the input centroids
LOGGER.debug("Retrieving input centroids from RDD...");
centroidVectors = RDDUtils.rddFeatureVectors(kmeansRDD, timeField, scaledTimeRange);
centroidVectors.cache();
// Init the algorithm
final KMeans kmeans = new KMeans();
kmeans.setInitializationMode("kmeans||");
kmeans.setK(numClusters);
kmeans.setMaxIterations(numIterations);
if (epsilon > -1.0) {
kmeans.setEpsilon(epsilon);
}
// Run KMeans
LOGGER.debug("Running KMeans algorithm...");
outputModel = kmeans.run(centroidVectors.rdd());
LOGGER.debug("Writing results to output store...");
writeToOutputStore();
LOGGER.debug("Results successfully written!");
}
use of org.locationtech.geowave.core.geotime.util.ExtractGeometryFilterVisitorResult in project geowave by locationtech.
the class ExtractGeometryFilterVisitorTest method testCrosses.
@Test
public void testCrosses() throws CQLException, TransformException, ParseException {
final Filter filter = CQL.toFilter(String.format("CROSSES(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))", geomAttributeName));
final Query query = new Query("type", filter);
final ExtractGeometryFilterVisitorResult result = (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);
final Envelope bounds = new Envelope(0, 10, 0, 25);
final Geometry bbox = new GeometryFactory().toGeometry(bounds);
assertTrue(bbox.equalsTopo(result.getGeometry()));
assertTrue(result.getCompareOp() == CompareOperation.CROSSES);
}
use of org.locationtech.geowave.core.geotime.util.ExtractGeometryFilterVisitorResult in project geowave by locationtech.
the class ExtractGeometryFilterVisitorTest method testEquals.
@Test
public void testEquals() throws CQLException, TransformException, ParseException {
final Filter filter = CQL.toFilter(String.format("EQUALS(geom, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))", geomAttributeName));
final Query query = new Query("type", filter);
final ExtractGeometryFilterVisitorResult result = (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);
final Envelope bounds = new Envelope(0, 10, 0, 25);
final Geometry bbox = new GeometryFactory().toGeometry(bounds);
assertTrue(bbox.equalsTopo(result.getGeometry()));
assertTrue(result.getCompareOp() == CompareOperation.EQUALS);
}
use of org.locationtech.geowave.core.geotime.util.ExtractGeometryFilterVisitorResult in project geowave by locationtech.
the class ExtractGeometryFilterVisitorTest method testOverlapsOrCrosses.
@Test
public void testOverlapsOrCrosses() throws CQLException, TransformException, ParseException {
// TOUCHES geometry is completely contained within OVERLAPS geometry
// we are testing to see if we are able to combine dissimilar geometric
// relations correctly
// to extract query geometry. Note, we can't combine two different
// predicates into one but
// we can combine geometries for the purpose of deriving linear
// constraints
final Filter filter = CQL.toFilter(String.format("OVERLAPS(%s, POLYGON((0 0, 0 50, 20 50, 20 0, 0 0))) OR TOUCHES(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))", geomAttributeName, geomAttributeName));
final Query query = new Query("type", filter);
final ExtractGeometryFilterVisitorResult result = (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);
final Envelope bounds = new Envelope(0, 20, 0, 50);
final Geometry bbox = new GeometryFactory().toGeometry(bounds);
assertTrue(bbox.equalsTopo(result.getGeometry()));
assertTrue(result.getCompareOp() == null);
}
use of org.locationtech.geowave.core.geotime.util.ExtractGeometryFilterVisitorResult in project geowave by locationtech.
the class ExtractGeometryFilterVisitorTest method testDisjoint.
@Test
public void testDisjoint() throws CQLException, TransformException, ParseException {
final Filter filter = CQL.toFilter(String.format("DISJOINT(%s, POLYGON((0 0, 0 25, 10 25, 10 0, 0 0)))", geomAttributeName));
final Query query = new Query("type", filter);
final ExtractGeometryFilterVisitorResult result = (ExtractGeometryFilterVisitorResult) query.getFilter().accept(visitorWithDescriptor, null);
// for non-inclusive filters we can't extract query geometry and
// predicate
// assertTrue(Double.isNaN(result.getGeometry().getArea()));
assertTrue(result.getCompareOp() == null);
}
Aggregations