mirror of
https://github.com/rasterio/rasterio.git
synced 2025-12-08 17:36:12 +00:00
Document experimental json-seq feature.
This commit is contained in:
parent
5ea4e7ec7e
commit
da7d45b030
@ -145,6 +145,14 @@ for use with single-band rasters and reads from the first band.
|
||||
|
||||
The resulting file, uploaded to Mapbox, looks like this: `sgillies.j1ho338j <https://a.tiles.mapbox.com/v4/sgillies.j1ho338j/page.html?access_token=pk.eyJ1Ijoic2dpbGxpZXMiLCJhIjoiWUE2VlZVcyJ9.OITHkb1GHNh9nvzIfUc9QQ#13/39.6079/-106.4822>`__.
|
||||
|
||||
This command supports `JSON text sequences <http://tools.ietf.org/html/draft-ietf-json-text-sequence-04>`__ as an experimental feature.
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ rio shapes rasterio/tests/data/shade.tif --precision 1 --x-json-seq --x-text-sep-lf | head -n 2
|
||||
{"bbox": [-106.5, 39.6, -106.4, 39.6], "type": "FeatureCollection"}
|
||||
{"geometry": {"coordinates": [[[-106.5, 39.6], [-106.5, 39.6], [-106.5, 39.6], [-106.5, 39.6], [-106.5, 39.6]]], "type": "Polygon"}, "id": "255", "properties": {"val": 255}, "type": "Feature"}
|
||||
|
||||
transform
|
||||
---------
|
||||
|
||||
|
||||
21
scripts/rio
21
scripts/rio
@ -188,10 +188,13 @@ def transform_geom(transformer, g, precision=-1):
|
||||
help="Indentation level for JSON output")
|
||||
@click.option('--projected/--geographic', default=False,
|
||||
help="Output in projected coordinates (default is geographic).")
|
||||
@click.option('--json-seq/--json-obj', default=False,
|
||||
help="Write a JSON sequence (default is object).")
|
||||
@click.option('--x-json-seq/--x-json-obj', default=False,
|
||||
help="Write a JSON sequence (default is object). Requires specification of text separator. Experimental.")
|
||||
@click.option('--x-text-sep-lf', 'text_sep', flag_value='\n',
|
||||
help="Use LF as text separator. Experimental.")
|
||||
@click.pass_context
|
||||
def shapes(ctx, src_path, precision, indent, projected, json_seq):
|
||||
def shapes(
|
||||
ctx, src_path, precision, indent, projected, x_json_seq, text_sep=None):
|
||||
verbosity = ctx.obj['verbosity']
|
||||
logger = logging.getLogger('rio')
|
||||
def to_feature(i, geom):
|
||||
@ -228,19 +231,25 @@ def shapes(ctx, src_path, precision, indent, projected, json_seq):
|
||||
feature_gen = (to_feature(i, g) for g, i
|
||||
in rasterio.features.shapes(
|
||||
src.read(1), transform=src.affine))
|
||||
if json_seq:
|
||||
if x_json_seq:
|
||||
if text_sep is None:
|
||||
raise click.BadParameter('Text separator is required')
|
||||
sys.stdout.write(
|
||||
json.dumps(collection, indent=indent, sort_keys=True)
|
||||
+ "\n")
|
||||
+ text_sep)
|
||||
for feature in feature_gen:
|
||||
sys.stdout.write(
|
||||
json.dumps(feature, indent=indent, sort_keys=True)
|
||||
+ "\n")
|
||||
+ text_sep)
|
||||
sys.stdout.flush()
|
||||
else:
|
||||
collection['features'] = list(feature_gen)
|
||||
sys.stdout.write(
|
||||
json.dumps(collection, indent=indent, sort_keys=True))
|
||||
sys.exit(0)
|
||||
except IOError:
|
||||
logger.info("IOError caught")
|
||||
sys.exit(0)
|
||||
except Exception:
|
||||
logger.exception("Failed. Exception caught")
|
||||
sys.exit(1)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user