def compare_count(self, spatial_rdd: LineStringRDD, envelope: Envelope,
                      count: int):

        spatial_rdd.analyze()

        assert count == spatial_rdd.approximateTotalCount
        assert envelope == spatial_rdd.boundaryEnvelope
 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
Exemple #3
0
    def test_linestring_rdd(self):
        linestring_rdd = LineStringRDD(
            sparkContext=self.sc,
            InputLocation=linestring_rdd_input_location,
            startOffset=0,
            endOffset=7,
            splitter=FileDataSplitter.CSV,
            carryInputData=True)

        wkt = "LINESTRING (-112.506968 45.98186, -112.506968 45.983586, -112.504872 45.983586, -112.504872 45.98186)"
        collected_linestring_rdd = linestring_rdd.getRawSpatialRDD().collect()

        assert wkt == collected_linestring_rdd[0].geom.wkt
    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
Exemple #5
0
    def readToLineStringRDD(cls, sc: SparkContext,
                            inputPath: str) -> LineStringRDD:
        """

        :param sc:
        :param inputPath:
        :return:
        """
        ShapefileReader.validate_imports()
        jvm = sc._jvm
        jsc = sc._jsc
        srdd = jvm.ShapefileReader.readToLineStringRDD(jsc, inputPath)
        spatial_rdd = LineStringRDD()
        spatial_rdd.set_srdd(srdd)
        return spatial_rdd
    def test_mbr(self):
        linestring_rdd = LineStringRDD(sparkContext=self.sc,
                                       InputLocation=input_location,
                                       splitter=splitter,
                                       carryInputData=True,
                                       partitions=num_partitions,
                                       newLevel=StorageLevel.MEMORY_ONLY)

        rectangle_rdd = linestring_rdd.MinimumBoundingRectangle()
        result = rectangle_rdd.rawSpatialRDD.collect()

        for el in result:
            print(el)

        assert result.__len__() > -1
    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_overlapped_linestring_join_correctness(self):
        window_rdd = PolygonRDD(
            self.sc.parallelize(self.test_polygon_window_set),
            StorageLevel.MEMORY_ONLY)
        object_rdd = LineStringRDD(
            self.sc.parallelize(self.test_overlapped_linestring_set),
            StorageLevel.MEMORY_ONLY)
        self.prepare_rdd(object_rdd, window_rdd, GridType.QUADTREE)

        result = JoinQuery.SpatialJoinQuery(object_rdd, window_rdd, True,
                                            True).collect()
        self.verify_join_result(result)

        result_no_index = JoinQuery.SpatialJoinQuery(object_rdd, window_rdd,
                                                     False, True).collect()
        self.verify_join_result(result_no_index)
    def test_outside_line_string_join_correctness(self):
        window_rdd = PolygonRDD(
            self.sc.parallelize(self.test_polygon_window_set),
            StorageLevel.MEMORY_ONLY)
        object_rdd = LineStringRDD(
            self.sc.parallelize(self.test_outside_linestring_set),
            StorageLevel.MEMORY_ONLY)
        self.prepare_rdd(object_rdd, window_rdd, GridType.QUADTREE)

        result = JoinQuery.SpatialJoinQuery(object_rdd, window_rdd, True,
                                            False).collect()
        assert 0 == result.__len__()

        result_no_index = JoinQuery.SpatialJoinQuery(object_rdd, window_rdd,
                                                     False, False).collect()
        assert 0 == result_no_index.__len__()
    def test_voronoi_spatial_partitioning(self):
        spatial_rdd = LineStringRDD(sparkContext=self.sc,
                                    InputLocation=input_location,
                                    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)
Exemple #11
0
 def create_linestring_rdd(self, location, splitter, num_partitions):
     rdd = LineStringRDD(
         self.sc, location, splitter, True, num_partitions
     )
     return LineStringRDD(rdd.rawJvmSpatialRDD, StorageLevel.MEMORY_ONLY)
    def test_constructor(self):
        spatial_rdd_core = LineStringRDD(sparkContext=self.sc,
                                         InputLocation=input_location,
                                         splitter=splitter,
                                         carryInputData=True,
                                         partitions=num_partitions,
                                         newLevel=StorageLevel.MEMORY_ONLY)

        self.compare_count(spatial_rdd_core, input_boundary, input_count)

        spatial_rdd = LineStringRDD()

        spatial_rdd_core = LineStringRDD(self.sc, input_location, splitter,
                                         True, num_partitions,
                                         StorageLevel.MEMORY_ONLY)
        self.compare_count(spatial_rdd_core, input_boundary, input_count)

        spatial_rdd = LineStringRDD(spatial_rdd_core.rawJvmSpatialRDD)

        self.compare_count(spatial_rdd, input_boundary, input_count)

        spatial_rdd = LineStringRDD(spatial_rdd_core.rawJvmSpatialRDD,
                                    "epsg:4326", "epsg:5070")

        self.compare_count(spatial_rdd, transformed_envelope, input_count)

        spatial_rdd = LineStringRDD(self.sc, input_location, 0, 3, splitter,
                                    True, num_partitions)

        self.compare_count(spatial_rdd, input_boundary_2, input_count)

        spatial_rdd = LineStringRDD(self.sc, input_location, 0, 3, splitter,
                                    True)

        self.compare_count(spatial_rdd, input_boundary_2, input_count)

        spatial_rdd = LineStringRDD(self.sc, input_location, splitter, True,
                                    num_partitions)

        self.compare_count(spatial_rdd, input_boundary, input_count)

        spatial_rdd = LineStringRDD(self.sc, input_location, splitter, True)

        self.compare_count(spatial_rdd, input_boundary, input_count)

        spatial_rdd = LineStringRDD(spatial_rdd_core.rawJvmSpatialRDD,
                                    StorageLevel.MEMORY_ONLY)

        self.compare_count(spatial_rdd, input_boundary, input_count)

        spatial_rdd = LineStringRDD(self.sc, input_location, 0, 3, splitter,
                                    True, num_partitions,
                                    StorageLevel.MEMORY_ONLY)

        self.compare_count(spatial_rdd, input_boundary_2, input_count)

        spatial_rdd = LineStringRDD(self.sc, input_location, 0, 3, splitter,
                                    True, StorageLevel.MEMORY_ONLY)

        self.compare_count(spatial_rdd, input_boundary_2, input_count)

        spatial_rdd = LineStringRDD(self.sc, input_location, splitter, True,
                                    num_partitions, StorageLevel.MEMORY_ONLY)

        self.compare_count(spatial_rdd, input_boundary, input_count)

        spatial_rdd = LineStringRDD(self.sc, input_location, splitter, True,
                                    StorageLevel.MEMORY_ONLY)

        self.compare_count(spatial_rdd, input_boundary, input_count)

        spatial_rdd = LineStringRDD(spatial_rdd_core.rawJvmSpatialRDD,
                                    StorageLevel.MEMORY_ONLY, "epsg:4326",
                                    "epsg:5070")

        self.compare_count(spatial_rdd, transformed_envelope, input_count)

        spatial_rdd = LineStringRDD(self.sc, input_location, 0, 3, splitter,
                                    True, num_partitions,
                                    StorageLevel.MEMORY_ONLY, "epsg:4326",
                                    "epsg:5070")

        self.compare_count(spatial_rdd, transformed_envelope_2, input_count)

        spatial_rdd = LineStringRDD(self.sc, input_location, 0, 3, splitter,
                                    True, StorageLevel.MEMORY_ONLY,
                                    "epsg:4326", "epsg:5070")

        self.compare_count(spatial_rdd, transformed_envelope_2, input_count)

        spatial_rdd = LineStringRDD(self.sc, input_location, splitter, True,
                                    num_partitions, StorageLevel.MEMORY_ONLY,
                                    "epsg:4326", "epsg:5070")

        self.compare_count(spatial_rdd, transformed_envelope, input_count)

        spatial_rdd = LineStringRDD(self.sc, input_location, splitter, True,
                                    StorageLevel.MEMORY_ONLY, "epsg:4326",
                                    "epsg:5070")

        self.compare_count(spatial_rdd, transformed_envelope, input_count)
    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()
Exemple #14
0
 def getCenterLineStringRDDAsSpatialRDD(self) -> 'LineStringRDD':
     from geo_pyspark.core.SpatialRDD import LineStringRDD
     srdd = self._srdd.getCenterPolygonAsSpatialRDD()
     linestring_rdd = LineStringRDD()
     linestring_rdd.set_srdd(srdd)
     return linestring_rdd