T
-
public class SpatialJavaDStream<T>
extends <any>
This class represents a spatially enabled DStream. A SpatialJavaDStream encapsulates an existing DStream and adds spatial transformations and functions.
Spatial information is extracted from the source DStream using an implementation of SparkRecordInfoProvider
provided by the user just like it is done with SpatialJavaRDD. The SparkRecordInfoProvider is expected to return the geometry of spatial records.
The following example shows how to create a SpatialJavaDStream from a text DStream, using a SparkRecordInfo which extracts the spatial information from text records
JavaDStream<String> textStream = ssc.socketTextStream(host, port)
SparkRecordInfoProvider recordInfoProvider = new CSVRecordInfoProvider();
SpatialJavaDStream<String> spatialStream = SpatialJavaDStream.fromJavaDStream(textStream, recordInfoProvider, String.class);
The previous example creates a SpatialJavaDStream which records are of type String as the source DStream. Every time a spatial operation is performed, the provided SparkRecordInfoProvider instance will be used to extract the spatial information. For some data set formats, like JSON, extracting spatial information may require parsing each record every time the spatial information is needed for a spatial operation and it may be executed several times if multiple spatial transformations are applied.
A way to ensure records will be parsed only once by the SparkRecordInfoProvider is to create a SpatialJavaDStream which records are of type SparkRecordInfo
. A SparkRecordInfo holds spatial information and any desired additional data from the source stream records. The SpatialJavaDStream static method SpatialJavaRDD#fromJavaDStream(JavaDStream, SparkRecordInfoProvider)
can be used to create JavaSpatialDStream of type SparkRecordInfo.
Spatial versions of existing transformations are provided. Spatial transformations take the following parameters:
SpatialOperationConfig
which contains the information of the spatial operation to be performed to filter records.Modifier and Type | Method and Description |
---|---|
SpatialTransformationContext<T> |
createSpatialTransformationContext()
Creates an instance of
SpatialTransformationContext |
SpatialTransformationContext<T> |
createSpatialTransformationContext(SpatialOperationConfig spatialOperationConf)
Creates an instance of
SpatialTransformationContext associated to the given SpatialOperationConfig . |
<R> <any> |
enrich(<any> f, GeoEnricher enricher)
Finds features related to the geometries of the stream´s records and uses a user-provided lambda to transform the enriched records
|
SpatialJavaDStream<T> |
filter(<any> f, SpatialOperationConfig spatialOpConf)
Performs a filter transformation.
|
<U> <any> |
flatMap(<any> f, SpatialOperationConfig spatialOpConf)
Returns a new DStream by first spatially filtering the stream elements using the spatial operation given by spatialOpConf, then a flattening function is applied to all the remaining elements.
|
static <T> SpatialJavaDStream<T> |
fromDStream(<any> src, SparkRecordInfoProvider<T> recordInfoProvider)
Creates a spatial JavaDStream from an existing DStream
|
static <T> SpatialJavaDStream<SparkRecordInfo> |
fromJavaDStream(<any> src, SparkRecordInfoProvider<T> recordInfoProvider)
Creates a spatial JavaDStream which records are of type
SparkRecordInfo |
static <T> SpatialJavaDStream<T> |
fromJavaDStream(<any> src, SparkRecordInfoProvider<T> recordInfoProvider, java.lang.Class<T> type)
Creates a spatial JavaDStream from an existing JavaDStream
|
SparkRecordInfoProvider<T> |
getRecordInfoProvider()
Returns the current stream's
SparkRecordInfoProvider instance |
java.lang.Class<T> |
getType()
Returns the type of the records in this stream
|
<any> |
nearestNeighbors(<any> f, int k, SpatialOperationConfig spatialOpConf)
Returns a DStream containing one single element with the k elements which are closest to the given query window
|
StreamingContext |
ssc()
Returns the underlying StreamingContext
|
public SpatialTransformationContext<T> createSpatialTransformationContext()
SpatialTransformationContext
SpatialTransformationContext
public SpatialTransformationContext<T> createSpatialTransformationContext(SpatialOperationConfig spatialOperationConf)
SpatialTransformationContext
associated to the given SpatialOperationConfig
.spatialOperationConf
- a spatial operation used to filter recordsSpatialTransformationContext
public <R> <any> enrich(<any> f, GeoEnricher enricher)
f
- a lambda which receives stream's records with their associated featuresenricher
- a component used to associate a geometry from the stream's records to features from different spatial data layersssc
- the spark streaming contextpublic SpatialJavaDStream<T> filter(<any> f, SpatialOperationConfig spatialOpConf)
SpatialOperationConfig
.f
- lambda function to further filtering recordsspatialOpConf
- spatial criteria used for spatial filteringpublic <U> <any> flatMap(<any> f, SpatialOperationConfig spatialOpConf)
m
- a function to apply to each elementspatialOpConf
- a spatial operation used to filter recordspublic static <T> SpatialJavaDStream<T> fromDStream(<any> src, SparkRecordInfoProvider<T> recordInfoProvider)
src
- the source streamrecordInfoProvider
- an instance of SparkRecordInfoProvider
used to extract spatial information from the stream´s recordspublic static <T> SpatialJavaDStream<SparkRecordInfo> fromJavaDStream(<any> src, SparkRecordInfoProvider<T> recordInfoProvider)
SparkRecordInfo
src
- the source streamrecordInfoProvider
- an instance of SparkRecordInfoProvider
used to extract spatial information from the stream´s recordsSparkRecordInfo
public static <T> SpatialJavaDStream<T> fromJavaDStream(<any> src, SparkRecordInfoProvider<T> recordInfoProvider, java.lang.Class<T> type)
src
- the source streamrecordInfoProvider
- an instance of SparkRecordInfoProvider
used to extract spatial information from the stream´s recordstype
- the type of the spatial stream´s recordspublic SparkRecordInfoProvider<T> getRecordInfoProvider()
SparkRecordInfoProvider
instancepublic java.lang.Class<T> getType()
public <any> nearestNeighbors(<any> f, int k, SpatialOperationConfig spatialOpConf)
qryWindow
- a geometry from where the nearest neighbors will be calculatedk
- the number of neighborstol
- the tolerance usedpublic StreamingContext ssc()
Copyright © 2017 Oracle and/or its affiliates. All Rights Reserved.