def test_spatial_knn_query_using_index(self):
     line_string_rdd = LineStringRDD(self.sc, input_location, splitter,
                                     True)
     line_string_rdd.buildIndex(IndexType.RTREE, False)
     for i in range(self.loop_times):
         result = KNNQuery.SpatialKnnQuery(line_string_rdd,
                                           self.query_point, 5, False)
         assert result.__len__() > -1
         assert result[0].getUserData() is not None
    def test_build_index_without_set_grid(self):
        spatial_rdd = LineStringRDD(sparkContext=self.sc,
                                    InputLocation=input_location,
                                    splitter=splitter,
                                    carryInputData=True,
                                    partitions=num_partitions,
                                    newLevel=StorageLevel.MEMORY_ONLY)

        spatial_rdd.analyze()
        spatial_rdd.buildIndex(IndexType.RTREE, False)
    def test_empty_constructor(self):
        spatial_rdd = LineStringRDD(sparkContext=self.sc,
                                    InputLocation=input_location,
                                    splitter=splitter,
                                    carryInputData=True,
                                    partitions=num_partitions,
                                    newLevel=StorageLevel.MEMORY_ONLY)

        spatial_rdd.analyze()
        spatial_rdd.spatialPartitioning(grid_type)
        spatial_rdd.buildIndex(IndexType.RTREE, True)
        spatial_rdd_copy = LineStringRDD()
        spatial_rdd_copy.rawJvmSpatialRDD = spatial_rdd.rawJvmSpatialRDD
        spatial_rdd_copy.analyze()
    def test_spatial_range_query_using_index(self):
        spatial_rdd = LineStringRDD(self.sc, input_location, 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, False).count()
            assert result_size == 999

        assert RangeQuery.SpatialRangeQuery(
            spatial_rdd, self.query_envelope, False,
            False).take(10)[1].getUserData() is not None