示例#1
0
def test_filter_features_multi_linstrings():
    """MultiLineStrings should be turned into multiple LineStrings"""
    features = [{
        "type": "Feature",
        "geometry": {
            "type":
            "MultiLineString",
            "coordinates": [
                [[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]],
                [[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]],
            ],
        },
    }]
    expected = [
        {
            "type": "Feature",
            "geometry": {
                "type": "LineString",
                "coordinates": [[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]],
            },
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "LineString",
                "coordinates": [[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]],
            },
        },
    ]
    assert list(sutils.filter_features(features)) == expected
示例#2
0
def test_filter_features_multi_point():
    """MultiPoints should be turned into multiple Points"""
    features = [{
        "type": "Feature",
        "geometry": {
            "type": "MultiPoint",
            "coordinates": [[0, 0], [1, 0]]
        },
    }]
    expected = [
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [0, 0]
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [1, 0]
            }
        },
    ]
    assert list(sutils.filter_features(features)) == expected
示例#3
0
def test_filter_features_multi_polygon():
    """MultiPolygons should be turned into multiple Polygons"""
    features = [{
        "type": "Feature",
        "geometry": {
            "type":
            "MultiPolygon",
            "coordinates": [
                [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]]],
                [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]]],
            ],
        },
    }]
    expected = [
        {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]]],
            },
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]]],
            },
        },
    ]
    assert list(sutils.filter_features(features)) == expected
示例#4
0
def burn(features, sequence, zoom):
    """
    Burn a stream of GeoJSONs into a output stream of the tiles they intersect for a given zoom.
    """
    features = [f for f in super_utils.filter_features(features)]

    tiles = burntiles.burn(features, zoom)
    for t in tiles:

        click.echo(t.tolist())
示例#5
0
def test_filter_features_point():
    """Points should go through unfiltered"""
    features = [{
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [[0, 0]]
        }
    }]

    assert list(sutils.filter_features(features)) == features
示例#6
0
def test_filter_features_linestring():
    """LineString should go through unfiltered"""
    features = [{
        "type": "Feature",
        "geometry": {
            "type": "LineString",
            "coordinates": [[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]],
        },
    }]

    assert list(sutils.filter_features(features)) == features
示例#7
0
def test_filter_features_polygon():
    """Polygon should go through unfiltered"""
    features = [{
        "type": "Feature",
        "geometry": {
            "type": "Polygon",
            "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]]],
        },
    }]

    assert list(sutils.filter_features(features)) == features
示例#8
0
def estimate_area(features, precision, no_validation=False, force_1cm=False):
    """Estimate area of features with a precision level.

    tilesets estimate-area <features> <precision>

    features must be a list of paths to local files containing GeoJSON feature collections or feature sequences from argument or stdin, or a list of string-encoded coordinate pairs of the form "[lng, lat]", or "lng, lat", or "lng lat".
    """
    area = 0
    if precision == "1cm" and not force_1cm:
        raise errors.TilesetsError(
            "The --force-1cm flag must be present to enable 1cm precision area calculation and may take longer for large feature inputs or data with global extents. 1cm precision for tileset processing is only available upon request after contacting Mapbox support."
        )
    if precision != "1cm" and force_1cm:
        raise errors.TilesetsError(
            "The --force-1cm flag is enabled but the precision is not 1cm."
        )

    # builtins.list because there is a list command in the cli & will thrown an error
    try:
        features = builtins.list(filter_features(features))
    except (ValueError, json.decoder.JSONDecodeError):
        raise errors.TilesetsError(
            "Error with feature parsing. Ensure that feature inputs are valid and formatted correctly. Try 'tilesets estimate-area --help' for help."
        )
    except Exception:
        raise errors.TilesetsError("Error with feature filtering.")

    # expect users to bypass source validation when users rerun command and their features passed validation previously
    if not no_validation:
        for feature in features:
            utils.validate_geojson(feature)

    area = utils.calculate_tiles_area(features, precision)
    area = str(round(area))

    click.echo(
        json.dumps(
            {
                "km2": area,
                "precision": precision,
                "pricing_docs": "For more information, visit https://www.mapbox.com/pricing/#tilesets",
            }
        )
    )