Пример #1
0
    def test_rasterization_with_partitioner(self):
        features = osm_reader.from_orc(file_path("zerns.orc"))

        lines = features.get_way_features_rdd()

        def assign_cellvalues(feature):
            tags = feature.properties.tags.values()

            if 'water' in tags:
                return Feature(feature.geometry, CellValue(4, 4))
            elif "en:Zern's Farmer's Market" in tags:
                return Feature(feature.geometry, CellValue(3, 3))
            else:
                return Feature(feature.geometry, CellValue(1, 1))

        mapped_lines = lines.map(lambda feature: assign_cellvalues(feature))

        result = rasterize_features(
            mapped_lines,
            4326,
            12,
            cell_type=CellType.INT8,
            partition_strategy=SpatialPartitionStrategy())

        self.assertEqual(result.get_min_max(), (1, 4))
        self.assertEqual(result.count(), 1)
    def test_partition_preservation(self):
        partition_states = []
        strategy = SpatialPartitionStrategy(16)

        tiled = self.rdd.tile_to_layout()

        tiled2 = self.rdd.tile_to_layout(partition_strategy=strategy)
        partition_states.append(tiled2.get_partition_strategy())

        added_layer = (tiled + tiled2) * 0.75
        partition_states.append(added_layer.get_partition_strategy())

        local_max_layer = added_layer.local_max(tiled)
        partition_states.append(local_max_layer.get_partition_strategy())

        focal_layer = local_max_layer.focal(Operation.MAX, Square(1))
        partition_states.append(focal_layer.get_partition_strategy())

        reprojected_layer = focal_layer.tile_to_layout(
            layout=LocalLayout(), target_crs=3857, partition_strategy=strategy)
        partition_states.append(reprojected_layer.get_partition_strategy())

        pyramided = reprojected_layer.pyramid()
        partition_states.append(
            pyramided.levels[pyramided.max_zoom].get_partition_strategy())

        self.assertTrue(all(x == partition_states[0]
                            for x in partition_states))
Пример #3
0
    def test_rdd_mask_with_partition_strategy(self):
        rdd = BaseTestClass.pysc.parallelize(self.geoms)

        result = self.raster_rdd.mask(rdd, partition_strategy=SpatialPartitionStrategy()).to_numpy_rdd()
        n = result.map(lambda kv: np.sum(kv[1].cells)).reduce(lambda a, b: a + b)

        self.assertEqual(n, 2.0)
Пример #4
0
    def test_partitionBy(self):
        tiled = self.result.tile_to_layout()

        strategy = SpatialPartitionStrategy(2)
        repartitioned = tiled.partitionBy(strategy)

        self.assertEqual(repartitioned.get_partition_strategy(), strategy)
Пример #5
0
    def test_focal_sum_nesw(self):
        neighborhood = Nesw(extent=1.0)
        self.assertEqual(str(neighborhood), repr(neighborhood))

        result = self.raster_rdd.focal(
            operation=Operation.SUM,
            neighborhood=neighborhood,
            partition_strategy=SpatialPartitionStrategy())

        self.assertTrue(result.to_numpy_rdd().first()[1].cells[0][1][0] >= 4)
Пример #6
0
    def test_whole_area_with_spatial_partitioner(self):
        polygon = Polygon([(0, 11), (11, 11), (11, 0), (0, 0)])

        raster_rdd = rasterize([polygon],
                               "EPSG:3857",
                               11,
                               1,
                               partition_strategy=SpatialPartitionStrategy())

        cells = raster_rdd.to_numpy_rdd().first()[1].cells

        for x in cells.flatten().tolist():
            self.assertTrue(math.isnan(x))
Пример #7
0
    def test_pyraminding_with_partitioner(self):
        arr = np.zeros((1, 16, 16))
        epsg_code = 3857
        extent = Extent(0.0, 0.0, 10.0, 10.0)

        tile = Tile(arr, 'FLOAT', False)
        projected_extent = ProjectedExtent(extent, epsg_code)

        rdd = BaseTestClass.pysc.parallelize([(projected_extent, tile)])
        raster_rdd = RasterLayer.from_numpy_rdd(LayerType.SPATIAL, rdd)
        tile_layout = TileLayout(32, 32, 16, 16)
        new_extent = Extent(-20037508.342789244, -20037508.342789244, 20037508.342789244,
                            20037508.342789244)

        layout_def = LayoutDefinition(new_extent, tile_layout)
        laid_out = raster_rdd.tile_to_layout(GlobalLayout(tile_size=16))

        strategy = SpatialPartitionStrategy(4)

        pyramided = laid_out.pyramid(partition_strategy=strategy)

        self.assertEqual(pyramided.levels[0].get_partition_strategy(), strategy)
Пример #8
0
    def test_to_to_layout_with_partitioner(self):
        strategy = SpatialPartitionStrategy(4)
        tiled = self.layer.tile_to_layout(LocalLayout(5),
                                          partition_strategy=strategy)

        self.assertEqual(tiled.get_partition_strategy(), strategy)