Skip to content

Commit

Permalink
Add plugin instructions to CLI main.py
Browse files Browse the repository at this point in the history
Also change affine module usage to future proof Rasterio.
  • Loading branch information
Sean Gillies committed May 19, 2016
1 parent f97316a commit 8ae2f91
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ information on how to build these plugins in general.
To use these plugins with rio, add the commands to the
``rasterio.rio_plugins'`` entry point in your ``setup.py`` file, as described
`here <https://github.com/click-contrib/click-plugins#developing-plugins>`__
and in ``rasterio/rio/main.py``.

See the
`plugin registry <https://github.com/mapbox/rasterio/wiki/Rio-plugin-registry>`__
Expand Down
4 changes: 2 additions & 2 deletions rasterio/_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ cdef class DatasetReader(object):
def window_bounds(self, window):
"""Returns the bounds of a window as x_min, y_min, x_max, y_max."""
((row_min, row_max), (col_min, col_max)) = window
x_min, y_min = (col_min, row_max) * self.affine
x_max, y_max = (col_max, row_min) * self.affine
x_min, y_min = self.affine * (col_min, row_max)
x_max, y_max = self.affine * (col_max, row_min)
return x_min, y_min, x_max, y_max

@property
Expand Down
41 changes: 35 additions & 6 deletions rasterio/rio/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
"""
Main command group for Rasterio's CLI.
Subcommands developed as a part of the Rasterio package have their own
modules under ``rasterio.rio`` (like ``rasterio/rio/info.py``) and are
registered in the 'rasterio.rio_commands' entry point group in
Rasterio's ``setup.py``:
entry_points='''
[console_scripts]
rio=rasterio.rio.main:main_group
[rasterio.rio_commands]
bounds=rasterio.rio.bounds:bounds
calc=rasterio.rio.calc:calc
...
Users may create their own ``rio`` subcommands by writing modules that
register entry points in Rasterio's 'rasterio.rio_plugins' group. See
for example https://github.com/sgillies/rio-plugin-example, which has
been published to PyPI as ``rio-metasay``.
There's no advantage to making a ``rio`` subcommand which doesn't
import rasterio. But if you are using rasterio, you may profit from
Rasterio's CLI infrastructure and the network of existing commands.
Please add yours to the registry
https://github.com/mapbox/rasterio/wiki/Rio-plugin-registry
so that other ``rio`` users may find it.
"""


Expand Down Expand Up @@ -32,17 +60,18 @@ def gdal_version_cb(ctx, param, value):
@click.group()
@cligj.verbose_opt
@cligj.quiet_opt
@click.option('--aws-profile', help="Use a specific profile from your shared AWS credentials file")
@click.option(
'--aws-profile',
help="Use a specific profile from your shared AWS credentials file")
@click.version_option(version=rasterio.__version__, message='%(version)s')
@click.option('--gdal-version', is_eager=True, is_flag=True, callback=gdal_version_cb)
@click.option(
'--gdal-version', is_eager=True, is_flag=True, callback=gdal_version_cb)
@click.pass_context
def main_group(ctx, verbose, quiet, aws_profile, gdal_version):

"""Rasterio command line interface.
"""
Rasterio command line interface.
"""

verbosity = verbose - quiet
configure_logging(verbosity)
ctx.obj = {}
ctx.obj['verbosity'] = verbosity
ctx.obj['aws_profile'] = aws_profile

0 comments on commit 8ae2f91

Please sign in to comment.