예제 #1
0
    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
예제 #2
0
    def MinimumBoundingRectangle(self):
        from sedona.core.SpatialRDD import RectangleRDD
        rectangle_rdd = RectangleRDD()
        srdd = self._srdd.MinimumBoundingRectangle()

        rectangle_rdd.set_srdd(srdd)

        return rectangle_rdd
예제 #3
0
    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
예제 #4
0
    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
예제 #5
0
    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
예제 #6
0
    def test_spatial_knn_using_linestring(self):
        rectangle_rdd = RectangleRDD(self.sc, inputLocation, offset, splitter,
                                     True)

        result_no_index = KNNQuery.SpatialKnnQuery(rectangle_rdd,
                                                   self.query_line, self.top_k,
                                                   False)

        print(result_no_index)
예제 #7
0
    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()
예제 #8
0
    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)
예제 #9
0
 def getCenterRectangleRDDAsSpatialRDD(self) -> 'RectangleRDD':
     from sedona.core.SpatialRDD import RectangleRDD
     srdd = self._srdd.getCenterLineStringRDDAsSpatialRDD()
     rectangle_rdd = RectangleRDD()
     rectangle_rdd.set_srdd(srdd)
     return rectangle_rdd
예제 #10
0
 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)
예제 #11
0
    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.rawJvmSpatialRDD = spatial_rdd.rawJvmSpatialRDD
        spatial_rdd_copy.analyze()