def test_find_stacks(self):
        default_scene = {
            "geometry": {
                "coordinates": [[[35.369952624579206, 31.216789643457062],
                                 [35.420750988391234, 31.175389359348845],
                                 [35.477637108131596, 31.226907952923735],
                                 [35.42695322789718, 31.268358180524043],
                                 [35.369952624579206, 31.216789643457062]]]
            }
        }

        northern_scene = {
            "geometry": {
                "coordinates": [[[128.19634502233615, -1.04336292997073],
                                 [128.23352242360906, -1.0897399380061228],
                                 [128.28783572166822, -1.0455725768717137],
                                 [128.25071101409458, -0.999258432155743],
                                 [128.19634502233615, -1.04336292997073]]]
            }
        }

        # Basically just 2 northern scenes and 4 default scenes.
        # I'd expect the clustering algo to separate this into two stacks,
        # one of just default scenes and one of just northern scenes
        scenes = [
            default_scene.copy(),
            northern_scene.copy(),
            default_scene.copy(),
            northern_scene.copy(),
            default_scene.copy(),
            default_scene.copy()
        ]

        stacks, stack_centers = findstacks(scenes)

        # There should just be two stacks, the default scenes in one stack
        # and the northern scenes in another stack
        self.assertEqual(len(stacks), 2)

        # We passed in 4 default scenes
        self.assertEqual(len(stacks[0]), 4)

        # We passed in 2 northern scenes
        self.assertEqual(len(stacks[1]), 2)
Exemplo n.º 2
0
def find_stacks(ctx, metadata, index):
    """
    Input is a list of geojson dictionaries.

    Each dictionary in the list must have keys ['geometry']['coordinates'] or
    ['coordinates']

    e.g. find the deepest stack in a set of planet labs images
    cat path/to/file.geojson | planet search | find-stacks
    """
    if metadata == '-':
        src = click.open_file('-')

        if not src.isatty():
            data = src.read()
        else:
            click.echo(ctx.get_usage())
            ctx.exit(1)
    else:
        with open(metadata, 'r') as src:
            data = src.read()

    geojson = json.loads(data)

    scenes_md = []
    for i in geojson['features']:
        scenes_md.append(i)

    stacks, stack_centers = findstacks(scenes_md, min_depth=2, max_sep_km=2)

    if len(stacks) < index+1:
        click.echo("No Stack of that index")
        exit()

    # create a feature collection from the stacks
    FC = {
        "type": "FeatureCollection",
        "features": stacks[index]
    }

    click.echo(json.dumps(FC))
Exemplo n.º 3
0
def find_stacks(ctx, metadata, index):
    """
    Input is a list of geojson dictionaries.

    Each dictionary in the list must have keys ['geometry']['coordinates'] or
    ['coordinates']

    e.g. find the deepest stack in a set of planet labs images
    cat path/to/file.geojson | planet search | find-stacks
    """
    if metadata == '-':
        src = click.open_file('-')

        if not src.isatty():
            data = src.read()
        else:
            click.echo(ctx.get_usage())
            ctx.exit(1)
    else:
        with open(metadata, 'r') as src:
            data = src.read()

    geojson = json.loads(data)

    scenes_md = []
    for i in geojson['features']:
        scenes_md.append(i)

    stacks, stack_centers = findstacks(scenes_md, min_depth=2, max_sep_km=2)

    if len(stacks) < index + 1:
        click.echo("No Stack of that index")
        exit()

    # create a feature collection from the stacks
    FC = {"type": "FeatureCollection", "features": stacks[index]}

    click.echo(json.dumps(FC))
    def test_find_stacks(self):
        default_scene = {
            "geometry": {
                "coordinates": [[
                    [
                        35.369952624579206,
                        31.216789643457062
                    ],
                    [
                        35.420750988391234,
                        31.175389359348845
                    ],
                    [
                        35.477637108131596,
                        31.226907952923735
                    ],
                    [
                        35.42695322789718,
                        31.268358180524043
                    ],
                    [
                        35.369952624579206,
                        31.216789643457062
                    ]
                ]]
            }
        }

        northern_scene = {
            "geometry": {
                "coordinates": [[
                    [
                        128.19634502233615,
                        -1.04336292997073
                    ],
                    [
                        128.23352242360906,
                        -1.0897399380061228
                    ],
                    [
                        128.28783572166822,
                        -1.0455725768717137
                    ],
                    [
                        128.25071101409458,
                        -0.999258432155743
                    ],
                    [
                        128.19634502233615,
                        -1.04336292997073
                    ]
                ]]
            }
        }

        # Basically just 2 northern scenes and 4 default scenes.
        # I'd expect the clustering algo to separate this into two stacks,
        # one of just default scenes and one of just northern scenes
        scenes = [
            default_scene.copy(),
            northern_scene.copy(),
            default_scene.copy(),
            northern_scene.copy(),
            default_scene.copy(),
            default_scene.copy()]

        stacks, stack_centers = findstacks(scenes)

        # There should just be two stacks, the default scenes in one stack
        # and the northern scenes in another stack
        self.assertEqual(len(stacks), 2)

        # We passed in 4 default scenes
        self.assertEqual(len(stacks[0]), 4)

        # We passed in 2 northern scenes
        self.assertEqual(len(stacks[1]), 2)