コード例 #1
0
def test_bad_args():
    with pytest.raises(Exception):
        pg.PolygonGrid()

    with pytest.raises(Exception):
        pg.PolygonGrid((-180, 180, -90, 90))

    with pytest.raises(Exception):
        pg.PolygonGrid((-180, 90), step_size=(0.5, 0.5), dim_size=(720, 360))

    with pytest.raises(Exception):
        pg.PolygonGrid((-180, 180, -90, 90), step_size=(1, 2, 3))

    with pytest.raises(Exception):
        pg.PolygonGrid((-180, 180, -90, 90),
                       step_size=(0.5, 0.5),
                       dim_size=(360, 180))

    with pytest.raises(Exception):
        pg.PolygonGrid((-180, 180, -90, 90), dim_size=(360.5, 180.5))

    with pytest.raises(Exception):
        pg.PolygonGrid((-180, 180, -90, 90), dim_size=(1, 360, 180))

    with pytest.raises(Exception):
        pg.PolygonGrid((-90, 90, -90, 90), dim_size=(180))
コード例 #2
0
def test_output_to_geojson():
    my_pg = pg.PolygonGrid((-180, 180, -90, 90),
                           step_size=(10, 10),
                           properties=['all'])
    my_pg.build_grid()
    example_path = "tests/test.geojson"
    if os.path.isfile(example_path):
        os.remove(example_path)
    my_pg.output_to_geojson(example_path)
コード例 #3
0
def test_valid_args():
    pg.PolygonGrid((-180, 180, -90, 90),
                   step_size=(0.5, 0.5),
                   properties=['all'])
    pg.PolygonGrid((-180, 180, -90, 90), step_size=(0.5, 0.5))
    pg.PolygonGrid((-180, 180, -90, 90), step_size=(0.5))
    pg.PolygonGrid((-180, 180, -90, 90), step_size=[0.5])
    pg.PolygonGrid((-180, 180, -90, 90), step_size=0.5)
    pg.PolygonGrid((-180, 180, -90, 90), dim_size=(720, 360))
コード例 #4
0
import polygongrid as pg

# desired bounds
bounds = (-180, 180, -90, 90)

# accepts input of either step sizes (resolution) or dimension sizes (number of items in each dimension)
# if both provided, they must agree
step_size = (10, 10)
dim_size = (36, 18)

my_grid = pg.PolygonGrid(bounds,
                         step_size=step_size,
                         dim_size=dim_size,
                         properties="grid")

my_grid.build_grid()

my_grid.output_to_geojson("examples/example.geojson")

# Run time: 0.0295 seconds
コード例 #5
0
def test_build_grid():
    my_pg = pg.PolygonGrid((-180, 180, -90, 90),
                           step_size=(10, 10),
                           properties=['all'])
    my_pg.build_grid()