def test_spatial_knn_query_correctness(self): rectangle_rdd = RectangleRDD(self.sc, inputLocation, offset, splitter, True) result_no_index = KNNQuery.SpatialKnnQuery(rectangle_rdd, self.query_point, self.top_k, False) rectangle_rdd.buildIndex(IndexType.RTREE, False) result_with_index = KNNQuery.SpatialKnnQuery(rectangle_rdd, self.query_point, self.top_k, True) sorted_result_no_index = sorted( result_no_index, key=lambda geo_data: distance_sorting_functions( geo_data, self.query_point)) sorted_result_with_index = sorted( result_with_index, key=lambda geo_data: distance_sorting_functions( geo_data, self.query_point)) difference = 0 for x in range(self.top_k): difference += sorted_result_no_index[x].geom.distance( sorted_result_with_index[x].geom) assert difference == 0
def MinimumBoundingRectangle(self): from geo_pyspark.core.SpatialRDD import RectangleRDD rectangle_rdd = RectangleRDD() srdd = self._srdd.MinimumBoundingRectangle() rectangle_rdd.set_srdd(srdd) return rectangle_rdd
def test_spatial_knn_query_using_index(self): rectangle_rdd = RectangleRDD(self.sc, inputLocation, offset, splitter, True) rectangle_rdd.buildIndex(IndexType.RTREE, False) for i in range(self.loop_times): result = KNNQuery.SpatialKnnQuery(rectangle_rdd, self.query_point, self.top_k, False) assert result.__len__() > -1 assert result[0].getUserData() is not None
def test_spatial_range_query_using_index(self): spatial_rdd = RectangleRDD(self.sc, inputLocation, offset, splitter, True, StorageLevel.MEMORY_ONLY) spatial_rdd.buildIndex(IndexType.RTREE, False) for i in range(self.loop_times): result_size = RangeQuery.SpatialRangeQuery(spatial_rdd, self.query_envelope, False, True).count() assert result_size == 193 assert RangeQuery.SpatialRangeQuery(spatial_rdd, self.query_envelope, False, True).take(10)[1].getUserData()\ is not None
def test_voronoi_spatial_partitioning(self): spatial_rdd = RectangleRDD(sparkContext=self.sc, InputLocation=inputLocation, Offset=offset, splitter=splitter, carryInputData=True, partitions=10, newLevel=StorageLevel.MEMORY_ONLY) spatial_rdd.analyze() spatial_rdd.spatialPartitioning(GridType.VORONOI) for envelope in spatial_rdd.grids: print(envelope) assert spatial_rdd.countWithoutDuplicates( ) == spatial_rdd.countWithoutDuplicatesSPRDD()
def test_build_index_without_set_grid(self): spatial_rdd = RectangleRDD(sparkContext=self.sc, InputLocation=inputLocation, Offset=offset, splitter=splitter, carryInputData=True, partitions=numPartitions) spatial_rdd.analyze() spatial_rdd.buildIndex(IndexType.RTREE, False)
def test_constructor(self): spatial_rdd = RectangleRDD(sparkContext=self.sc, InputLocation=inputLocation, Offset=offset, splitter=splitter, carryInputData=True, partitions=numPartitions, newLevel=StorageLevel.MEMORY_ONLY) spatial_rdd.analyze() assert inputCount == spatial_rdd.approximateTotalCount assert inputBoundary == spatial_rdd.boundaryEnvelope spatial_rdd = RectangleRDD(self.sc, inputLocation, offset, splitter, True, numPartitions, StorageLevel.MEMORY_ONLY) spatial_rdd.analyze() assert inputCount == spatial_rdd.approximateTotalCount assert inputBoundary == spatial_rdd.boundaryEnvelope
def create_rectangle_rdd(self, location, splitter, num_partitions): rdd = RectangleRDD( self.sc, location, splitter, True, num_partitions) return RectangleRDD( rdd.rawJvmSpatialRDD, StorageLevel.MEMORY_ONLY )
def test_empty_constructor(self): spatial_rdd = RectangleRDD(sparkContext=self.sc, InputLocation=inputLocation, Offset=offset, splitter=splitter, carryInputData=True, partitions=numPartitions, newLevel=StorageLevel.MEMORY_ONLY) spatial_rdd.analyze() spatial_rdd.buildIndex(IndexType.RTREE, False) spatial_rdd_copy = RectangleRDD() spatial_rdd_copy.rawSpatialRDD = spatial_rdd spatial_rdd_copy.analyze()
def getCenterRectangleRDDAsSpatialRDD(self) -> 'RectangleRDD': from geo_pyspark.core.SpatialRDD import RectangleRDD srdd = self._srdd.getCenterLineStringRDDAsSpatialRDD() rectangle_rdd = RectangleRDD() rectangle_rdd.set_srdd(srdd) return rectangle_rdd