{"action":"created","comment":{"url":"https://api.github.com/repos/mapbox/rasterio/pulls/comments/69241986","id":69241986,"diff_hunk":"@@ -0,0 +1,169 @@\n+\"\"\"$ rio blocks\"\"\"\n+\n+\n+import json\n+import logging\n+import os.path\n+\n+import click\n+import cligj\n+\n+import rasterio\n+from rasterio.rio import options\n+from rasterio.rio.helpers import write_features\n+from rasterio.warp import transform_bounds\n+\n+\n+logger = logging.getLogger('rio')\n+\n+\n+class _Collection(object):\n+\n+    \"\"\"For use with `rasterio.rio.helpers.write_features()`.\"\"\"\n+\n+    def __init__(self, src, bidx, precision=6, geographic=True):\n+\n+        \"\"\"Export raster dataset windows to GeoJSON polygon features.\n+\n+        Parameters\n+        ----------\n+        src : RasterReader\n+            An open datasource.\n+        bidx : int\n+            Extract windows from this band.\n+        precision : int, optional\n+            Coordinate precision.\n+        geographic : bool, optional\n+            Reproject geometries to ``EPSG:4326`` if ``True``.\n+\n+        Yields\n+        ------\n+        dict\n+            GeoJSON polygon feature.\n+        \"\"\"\n+\n+        self._src = src\n+        self._bidx = bidx\n+        self._precision = precision\n+        self._geographic = geographic\n+\n+    def _normalize_bounds(self, bounds):\n+        if self._geographic:\n+            bounds = transform_bounds(self._src.crs, 'EPSG:4326', *bounds)\n+        if self._precision >= 0:\n+            bounds = (round(v, self._precision) for v in bounds)\n+        return bounds\n+\n+    @property\n+    def bbox(self):\n+        return tuple(self._normalize_bounds(self._src.bounds))\n+\n+    def __call__(self):\n+        gen = self._src.block_windows(bidx=self._bidx)\n+        for idx, (block, window) in enumerate(gen):\n+            bounds = self._normalize_bounds(self._src.window_bounds(window))\n+            xmin, ymin, xmax, ymax = bounds\n+            yield {\n+                'type': 'Feature',\n+                'id': '{0}:{1}'.format(os.path.basename(self._src.name), idx),\n+                'properties': {\n+                    'block': json.dumps(block),\n+                    'window': json.dumps(window)\n+                },\n+                'geometry': {\n+                    'type': 'Polygon',\n+                    'coordinates': [[\n+                        (xmin, ymin),\n+                        (xmin, ymax),\n+                        (xmax, ymax),\n+                        (xmax, ymin)\n+                    ]]\n+                }\n+            }\n+\n+\n+@click.command()\n+@options.file_in_arg\n+@options.output_opt\n+@cligj.precision_opt\n+@cligj.indent_opt\n+@cligj.compact_opt\n+@cligj.projection_geographic_opt\n+@cligj.projection_projected_opt\n+@cligj.sequence_opt\n+@cligj.use_rs_opt\n+@click.option(\n+    '--bidx', type=click.INT, default=0,\n+    help=\"Index of the band that is the source of shapes.\")\n+@click.pass_context\n+def blocks(\n+        ctx, input, output, precision, indent, compact, projection, sequence,\n+        use_rs, bidx):\n+\n+    \"\"\"Write dataset blocks as GeoJSON features.\n+\n+    This command writes features describing a rasters internal tiling scheme,","path":"rasterio/rio/blocks.py","position":105,"original_position":105,"commit_id":"7f2168bd61b15cc4cf955c8eb109ba0b99a42ecb","original_commit_id":"7f2168bd61b15cc4cf955c8eb109ba0b99a42ecb","user":{"login":"brendan-ward","id":3375604,"avatar_url":"https://avatars.githubusercontent.com/u/3375604?v=3","gravatar_id":"","url":"https://api.github.com/users/brendan-ward","html_url":"https://github.com/brendan-ward","followers_url":"https://api.github.com/users/brendan-ward/followers","following_url":"https://api.github.com/users/brendan-ward/following{/other_user}","gists_url":"https://api.github.com/users/brendan-ward/gists{/gist_id}","starred_url":"https://api.github.com/users/brendan-ward/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendan-ward/subscriptions","organizations_url":"https://api.github.com/users/brendan-ward/orgs","repos_url":"https://api.github.com/users/brendan-ward/repos","events_url":"https://api.github.com/users/brendan-ward/events{/privacy}","received_events_url":"https://api.github.com/users/brendan-ward/received_events","type":"User","site_admin":false},"body":"`rasters` -> `raster's`\r\n\r\nUse of 'tiling' and 'tiled' seems unnecessary here; referring to these as blocks - which may happen to be square - may be more consistent throughout. \r\n\r\n```\r\nThis command writes features describing a raster's internal blocks, which are used directly for raster I/O.  These features can be used to visualize how a windowed operation would operate using those blocks.\r\n```","created_at":"2016-07-01T03:03:25Z","updated_at":"2016-07-01T03:03:25Z","html_url":"https://github.com/mapbox/rasterio/pull/804#discussion_r69241986","pull_request_url":"https://api.github.com/repos/mapbox/rasterio/pulls/804","_links":{"self":{"href":"https://api.github.com/repos/mapbox/rasterio/pulls/comments/69241986"},"html":{"href":"https://github.com/mapbox/rasterio/pull/804#discussion_r69241986"},"pull_request":{"href":"https://api.github.com/repos/mapbox/rasterio/pulls/804"}}},"pull_request":{"url":"https://api.github.com/repos/mapbox/rasterio/pulls/804","id":75193762,"html_url":"https://github.com/mapbox/rasterio/pull/804","diff_url":"https://github.com/mapbox/rasterio/pull/804.diff","patch_url":"https://github.com/mapbox/rasterio/pull/804.patch","issue_url":"https://api.github.com/repos/mapbox/rasterio/issues/804","number":804,"state":"open","locked":false,"title":"CLI command for extracting datasource windows","user":{"login":"geowurster","id":2676083,"avatar_url":"https://avatars.githubusercontent.com/u/2676083?v=3","gravatar_id":"","url":"https://api.github.com/users/geowurster","html_url":"https://github.com/geowurster","followers_url":"https://api.github.com/users/geowurster/followers","following_url":"https://api.github.com/users/geowurster/following{/other_user}","gists_url":"https://api.github.com/users/geowurster/gists{/gist_id}","starred_url":"https://api.github.com/users/geowurster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geowurster/subscriptions","organizations_url":"https://api.github.com/users/geowurster/orgs","repos_url":"https://api.github.com/users/geowurster/repos","events_url":"https://api.github.com/users/geowurster/events{/privacy}","received_events_url":"https://api.github.com/users/geowurster/received_events","type":"User","site_admin":false},"body":"I wrote a utility to do this for the Nth time today, and I'm sure others have done the same.  It operates similarly to `$ rio shapes`.\r\n\r\n@perrygeo I found your [`rio-block-features`](https://github.com/mapbox/rio-block-features) utility when checking to see if someone wrote a plugin, but I don't see a reason this shouldn't be an included command.","created_at":"2016-06-25T02:47:13Z","updated_at":"2016-07-01T03:03:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"be70cdc62f428c678d03abb15e6a906fd1b00acc","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/mapbox/rasterio/milestones/8","html_url":"https://github.com/mapbox/rasterio/milestones/1.0","labels_url":"https://api.github.com/repos/mapbox/rasterio/milestones/8/labels","id":686337,"number":8,"title":"1.0","description":null,"creator":{"login":"sgillies","id":33697,"avatar_url":"https://avatars.githubusercontent.com/u/33697?v=3","gravatar_id":"","url":"https://api.github.com/users/sgillies","html_url":"https://github.com/sgillies","followers_url":"https://api.github.com/users/sgillies/followers","following_url":"https://api.github.com/users/sgillies/following{/other_user}","gists_url":"https://api.github.com/users/sgillies/gists{/gist_id}","starred_url":"https://api.github.com/users/sgillies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgillies/subscriptions","organizations_url":"https://api.github.com/users/sgillies/orgs","repos_url":"https://api.github.com/users/sgillies/repos","events_url":"https://api.github.com/users/sgillies/events{/privacy}","received_events_url":"https://api.github.com/users/sgillies/received_events","type":"User","site_admin":false},"open_issues":24,"closed_issues":72,"state":"open","created_at":"2014-06-10T00:10:13Z","updated_at":"2016-06-30T17:31:15Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/mapbox/rasterio/pulls/804/commits","review_comments_url":"https://api.github.com/repos/mapbox/rasterio/pulls/804/comments","review_comment_url":"https://api.github.com/repos/mapbox/rasterio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mapbox/rasterio/issues/804/comments","statuses_url":"https://api.github.com/repos/mapbox/rasterio/statuses/7f2168bd61b15cc4cf955c8eb109ba0b99a42ecb","head":{"label":"mapbox:rio-windows","ref":"rio-windows","sha":"7f2168bd61b15cc4cf955c8eb109ba0b99a42ecb","user":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"repo":{"id":14116604,"name":"rasterio","full_name":"mapbox/rasterio","owner":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapbox/rasterio","description":"Rasterio reads and writes geospatial raster datasets","fork":false,"url":"https://api.github.com/repos/mapbox/rasterio","forks_url":"https://api.github.com/repos/mapbox/rasterio/forks","keys_url":"https://api.github.com/repos/mapbox/rasterio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapbox/rasterio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapbox/rasterio/teams","hooks_url":"https://api.github.com/repos/mapbox/rasterio/hooks","issue_events_url":"https://api.github.com/repos/mapbox/rasterio/issues/events{/number}","events_url":"https://api.github.com/repos/mapbox/rasterio/events","assignees_url":"https://api.github.com/repos/mapbox/rasterio/assignees{/user}","branches_url":"https://api.github.com/repos/mapbox/rasterio/branches{/branch}","tags_url":"https://api.github.com/repos/mapbox/rasterio/tags","blobs_url":"https://api.github.com/repos/mapbox/rasterio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapbox/rasterio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapbox/rasterio/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapbox/rasterio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapbox/rasterio/statuses/{sha}","languages_url":"https://api.github.com/repos/mapbox/rasterio/languages","stargazers_url":"https://api.github.com/repos/mapbox/rasterio/stargazers","contributors_url":"https://api.github.com/repos/mapbox/rasterio/contributors","subscribers_url":"https://api.github.com/repos/mapbox/rasterio/subscribers","subscription_url":"https://api.github.com/repos/mapbox/rasterio/subscription","commits_url":"https://api.github.com/repos/mapbox/rasterio/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapbox/rasterio/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapbox/rasterio/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapbox/rasterio/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapbox/rasterio/contents/{+path}","compare_url":"https://api.github.com/repos/mapbox/rasterio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapbox/rasterio/merges","archive_url":"https://api.github.com/repos/mapbox/rasterio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapbox/rasterio/downloads","issues_url":"https://api.github.com/repos/mapbox/rasterio/issues{/number}","pulls_url":"https://api.github.com/repos/mapbox/rasterio/pulls{/number}","milestones_url":"https://api.github.com/repos/mapbox/rasterio/milestones{/number}","notifications_url":"https://api.github.com/repos/mapbox/rasterio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapbox/rasterio/labels{/name}","releases_url":"https://api.github.com/repos/mapbox/rasterio/releases{/id}","deployments_url":"https://api.github.com/repos/mapbox/rasterio/deployments","created_at":"2013-11-04T16:36:27Z","updated_at":"2016-06-30T12:28:24Z","pushed_at":"2016-06-30T23:51:05Z","git_url":"git://github.com/mapbox/rasterio.git","ssh_url":"git@github.com:mapbox/rasterio.git","clone_url":"https://github.com/mapbox/rasterio.git","svn_url":"https://github.com/mapbox/rasterio","homepage":"","size":14981,"stargazers_count":421,"watchers_count":421,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":94,"mirror_url":null,"open_issues_count":87,"forks":94,"open_issues":87,"watchers":421,"default_branch":"master"}},"base":{"label":"mapbox:master","ref":"master","sha":"2b24ac035c1c2971c3ac6d63f468826a70f2a5ef","user":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"repo":{"id":14116604,"name":"rasterio","full_name":"mapbox/rasterio","owner":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapbox/rasterio","description":"Rasterio reads and writes geospatial raster datasets","fork":false,"url":"https://api.github.com/repos/mapbox/rasterio","forks_url":"https://api.github.com/repos/mapbox/rasterio/forks","keys_url":"https://api.github.com/repos/mapbox/rasterio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapbox/rasterio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapbox/rasterio/teams","hooks_url":"https://api.github.com/repos/mapbox/rasterio/hooks","issue_events_url":"https://api.github.com/repos/mapbox/rasterio/issues/events{/number}","events_url":"https://api.github.com/repos/mapbox/rasterio/events","assignees_url":"https://api.github.com/repos/mapbox/rasterio/assignees{/user}","branches_url":"https://api.github.com/repos/mapbox/rasterio/branches{/branch}","tags_url":"https://api.github.com/repos/mapbox/rasterio/tags","blobs_url":"https://api.github.com/repos/mapbox/rasterio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapbox/rasterio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapbox/rasterio/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapbox/rasterio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapbox/rasterio/statuses/{sha}","languages_url":"https://api.github.com/repos/mapbox/rasterio/languages","stargazers_url":"https://api.github.com/repos/mapbox/rasterio/stargazers","contributors_url":"https://api.github.com/repos/mapbox/rasterio/contributors","subscribers_url":"https://api.github.com/repos/mapbox/rasterio/subscribers","subscription_url":"https://api.github.com/repos/mapbox/rasterio/subscription","commits_url":"https://api.github.com/repos/mapbox/rasterio/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapbox/rasterio/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapbox/rasterio/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapbox/rasterio/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapbox/rasterio/contents/{+path}","compare_url":"https://api.github.com/repos/mapbox/rasterio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapbox/rasterio/merges","archive_url":"https://api.github.com/repos/mapbox/rasterio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapbox/rasterio/downloads","issues_url":"https://api.github.com/repos/mapbox/rasterio/issues{/number}","pulls_url":"https://api.github.com/repos/mapbox/rasterio/pulls{/number}","milestones_url":"https://api.github.com/repos/mapbox/rasterio/milestones{/number}","notifications_url":"https://api.github.com/repos/mapbox/rasterio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapbox/rasterio/labels{/name}","releases_url":"https://api.github.com/repos/mapbox/rasterio/releases{/id}","deployments_url":"https://api.github.com/repos/mapbox/rasterio/deployments","created_at":"2013-11-04T16:36:27Z","updated_at":"2016-06-30T12:28:24Z","pushed_at":"2016-06-30T23:51:05Z","git_url":"git://github.com/mapbox/rasterio.git","ssh_url":"git@github.com:mapbox/rasterio.git","clone_url":"https://github.com/mapbox/rasterio.git","svn_url":"https://github.com/mapbox/rasterio","homepage":"","size":14981,"stargazers_count":421,"watchers_count":421,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":94,"mirror_url":null,"open_issues_count":87,"forks":94,"open_issues":87,"watchers":421,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mapbox/rasterio/pulls/804"},"html":{"href":"https://github.com/mapbox/rasterio/pull/804"},"issue":{"href":"https://api.github.com/repos/mapbox/rasterio/issues/804"},"comments":{"href":"https://api.github.com/repos/mapbox/rasterio/issues/804/comments"},"review_comments":{"href":"https://api.github.com/repos/mapbox/rasterio/pulls/804/comments"},"review_comment":{"href":"https://api.github.com/repos/mapbox/rasterio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mapbox/rasterio/pulls/804/commits"},"statuses":{"href":"https://api.github.com/repos/mapbox/rasterio/statuses/7f2168bd61b15cc4cf955c8eb109ba0b99a42ecb"}}}}
{"actor":{"display_login":"brendan-ward"}}