# How to use the fiona.bounds function in fiona

## To help you get started, we’ve selected a few fiona examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

Toblerity / Fiona / tests / test_bounds.py View on Github
``````def test_bounds_point():
g = {'type': 'Point', 'coordinates': [10, 10]}
assert fiona.bounds(g) == (10, 10, 10, 10)``````
Toblerity / Fiona / tests / test_bounds.py View on Github
``````def test_bounds_line():
g = {'type': 'LineString', 'coordinates': [[0, 0], [10, 10]]}
assert fiona.bounds(g) == (0, 0, 10, 10)``````
Toblerity / Fiona / tests / test_bounds.py View on Github
``````def test_bounds_z():
g = {'type': 'Point', 'coordinates': [10,10,10]}
assert fiona.bounds(g) == (10, 10, 10, 10)``````
Toblerity / Fiona / fiona / fio / cat.py View on Github
``````if bbox:
try:
bbox = tuple(map(float, bbox.split(',')))
except ValueError:
for i, path in enumerate(files, 1):
for lyr in layer[str(i)]:
with fiona.open(path, layer=lyr) as src:
for i, feat in src.items(bbox=bbox):
if dst_crs or precision >= 0:
g = transform_geom(
src.crs, dst_crs, feat['geometry'],
antimeridian_cutting=True,
precision=precision)
feat['geometry'] = g
feat['bbox'] = fiona.bounds(g)
if use_rs:
click.echo(u'\u001e', nl=False)
click.echo(json.dumps(feat, **dump_kwds))

except Exception:
logger.exception("Exception caught during processing")
raise click.Abort()``````
OpenGeoscience / geonotebook / geonotebook / shapes / base.py View on Github
``````def feature_window(cls, raster, feature):
"""Generate a window from the bounds of a geojson-like feature."""
bounds = fiona.bounds(feature)
return cls.bounds_window(raster, bounds)``````
Toblerity / Fiona / fiona / fio / bounds.py View on Github
``````To print the input objects themselves along with their bounds
as GeoJSON object, use --with-obj. This has the effect of updating
input objects with {id: identifier, bbox: bounds}.
"""
logger = logging.getLogger(__name__)
stdin = click.get_text_stream('stdin')
try:
source = obj_gen(stdin)
for i, obj in enumerate(source):
obj_id = obj.get('id', 'collection:' + str(i))
xs = []
ys = []
features = obj.get('features') or [obj]
for j, feat in enumerate(features):
feat_id = feat.get('id', 'feature:' + str(i))
w, s, e, n = fiona.bounds(feat)
if precision > 0:
w, s, e, n = (round(v, precision)
for v in (w, s, e, n))
if explode:
if with_id:
rec = {
'parent': obj_id,
'id': feat_id,
'bbox': (w, s, e, n)}
elif with_obj:
feat.update(parent=obj_id, bbox=(w, s, e, n))
rec = feat
else:
rec = (w, s, e, n)
if use_rs:
click.echo(u'\u001e', nl=False)``````
OpenGeoscience / geonotebook / geonotebook / shapes.py View on Github
``````def feature_window(raster, feature):
"""Generate a window from the bounds of a geojson-like feature."""
bounds = fiona.bounds(feature)
return bounds_window(raster, bounds)``````

## fiona

Fiona reads and writes spatial data files

BSD-3-Clause