Esempio n. 1
0
def main():
    # Check if there is no arguments, then print help
    if len(sys.argv[1:]) == 0:
        print_help_fun()
        argparser.exit()

    args = vars(argparser.parse_args())
    logger.debug('Extracting from inputs %s', args['input='])

    if (args['help']):
        print_help_fun()
    elif (args['formats']):
        print_supported_formats()
    else:
        # Check if file is exists happens in parser validation, see readable_file_or_dir
        if os.path.isfile(os.path.join(os.getcwd(), args['input='])):
            output = extent.fromFile(args['input='],
                                     bbox=args['bounding_box'],
                                     tbox=args['time_box'])
        if os.path.isdir(os.path.join(os.getcwd(), args['input='])):
            output = extent.fromDirectory(args['input='],
                                          bbox=args['bounding_box'],
                                          tbox=args['time_box'])

        if output is None:
            raise Exception("This file format is not supported")

        # print output
        if type(output) == list or type(output) == dict:
            print(str(output))
        else:
            print(output)
Esempio n. 2
0
def test_zipfile_one_file():
    folder_name = "tests/testdata/folders/folder_one_file"
    with tempfile.TemporaryDirectory() as tmp:
        zip_path = os.path.join(tmp, "zipfile.zip")
        create_zip(folder_name, zip_path)
        result = geoextent.fromDirectory(zip_path, bbox=True, tbox=True)
        assert result["bbox"] == pytest.approx(
            [7.601680, 51.948814, 7.647256, 51.974624], abs=tolerance)
        assert result["crs"] == "4326"
        assert result["tbox"] == ['2018-11-14', '2018-11-14']
Esempio n. 3
0
def test_zipfile_nested_folders():
    folder_name = "tests/testdata/folders/nested_folder"
    with tempfile.TemporaryDirectory() as tmp:
        zip_path = os.path.join(tmp, "zipfile.zip")
        create_zip(folder_name, zip_path)
        result = geoextent.fromDirectory(zip_path, bbox=True, tbox=True)
    assert result["bbox"] == pytest.approx([7.601680, 34.7, 142.0, 51.974624],
                                           abs=tolerance)
    assert result["crs"] == "4326"
    assert result["tbox"] == ['2017-04-08', '2020-02-06']
Esempio n. 4
0
def test_folder_nested_files():
    result = geoextent.fromDirectory('tests/testdata/folders/nested_folder',
                                     bbox=True,
                                     tbox=True)
    assert "bbox" in result
    assert "tbox" in result
    assert "crs" in result
    assert result["bbox"] == pytest.approx([7.601680, 34.7, 142.0, 51.974624],
                                           abs=tolerance)
    assert result["crs"] == "4326"
    assert result["tbox"] == ['2017-04-08', '2020-02-06']
Esempio n. 5
0
def test_zipfile_unsupported_file():
    with tempfile.TemporaryDirectory() as tmp:
        filepath = os.path.join(tmp, "unsupported_file.txt")
        f = open(filepath, "a")
        f.write("No geographical data")
        f.close()
        zip_path = os.path.join(tmp, "zipfile.zip")
        create_zip(tmp, zip_path)
        result = geoextent.fromDirectory(zip_path, bbox=True, tbox=True)
        assert "bbox" not in result
        assert "tbox" not in result
Esempio n. 6
0
def test_folder_multiple_files():
    result = geoextent.fromDirectory('tests/testdata/folders/folder_two_files',
                                     bbox=True,
                                     tbox=True)
    assert "bbox" in result
    assert "tbox" in result
    assert "crs" in result
    assert result["bbox"] == pytest.approx(
        [2.052333, 41.317038, 7.647256, 51.974624], abs=tolerance)
    assert result["crs"] == "4326"
    assert result["tbox"] == ['2018-11-14', '2019-09-11']
Esempio n. 7
0
def test_folder_one_file():
    result = geoextent.fromDirectory('tests/testdata/folders/folder_one_file',
                                     bbox=True,
                                     tbox=True)
    assert "bbox" in result
    assert "tbox" in result
    assert "crs" in result
    assert result["bbox"] == pytest.approx(
        [7.601680, 51.948814, 7.647256, 51.974624], abs=tolerance)
    assert result["crs"] == "4326"
    assert result["tbox"] == ['2018-11-14', '2018-11-14']
Esempio n. 8
0
def test_folder_one_file_details():
    result = geoextent.fromDirectory('tests/testdata/folders/folder_one_file',
                                     bbox=True,
                                     tbox=True,
                                     details=True)
    assert "bbox" in result
    assert "tbox" in result
    assert "crs" in result
    assert "details" in result
    assert result["bbox"] == pytest.approx(
        [7.601680, 51.948814, 7.647256, 51.974624], abs=tolerance)
    assert result["crs"] == "4326"
    assert result["tbox"] == ['2018-11-14', '2018-11-14']
    details = result['details']
    assert 'muenster_ring_zeit.geojson' in details
Esempio n. 9
0
def test_folder_one_file_no_details():
    result = geoextent.fromDirectory('tests/testdata/folders/folder_one_file',
                                     bbox=True,
                                     tbox=True,
                                     details=False)
    assert "details" not in result
Esempio n. 10
0
def test_empty_folder():
    with tempfile.TemporaryDirectory() as temp:
        result = geoextent.fromDirectory(temp, bbox=True, tbox=True)
        assert "bbox" not in result
        assert "tbox" not in result