{"action":"created","comment":{"url":"https://api.github.com/repos/hotosm/oam-server-tiler/pulls/comments/49397710","id":49397710,"diff_hunk":"@@ -101,65 +146,74 @@ def write_bytes_to_target(target_uri, contents):\n         with open(output_path, \"w\") as f:\n             f.write(contents)\n \n-def create_uri_sets(images, workspace_uri):\n-    result = []\n-    workspace_keys = []\n-    for (order, uri) in enumerate(images):\n-        source_uri = vsi_curlify(uri)\n-\n-        # Get the workspace \n-        workspace_key = get_filename(uri)\n-        i = 1\n-        while workspace_key in workspace_keys:\n-            if i > 2:\n-                workspace_key = workspace_key[:-2] + \"-\" + str(i)\n-            else:\n-                workspace_key = workspace_key + \"-\" + str(i)\n-            i + 1\n-        workspace_keys.append(workspace_key)\n-        \n-        workspace_target = os.path.join(workspace_uri, workspace_key + \"-workingcopy.tif\")\n-        workspace_source_uri = vsi_curlify(workspace_target)\n-\n-        image_folder = os.path.join(workspace_uri, workspace_key)\n-        \n-        uri_set = UriSet(source_uri = source_uri,\n-                         workspace_target = workspace_target,\n-                         workspace_source_uri = workspace_source_uri,\n-                         image_folder = image_folder,\n-                         order = order)\n-                         \n-        result.append(uri_set)\n-\n-    return result\n-\n-def copy_to_workspace(source_uri, dest_uri):\n-    \"\"\"\n-    Translates an image from a URI to a compressed, tiled GeoTIFF version in the workspace\n-    \"\"\"\n-\n-    creation_options = {\n-        \"driver\": \"GTiff\",\n-        \"tiled\": True,\n-        \"compress\": \"lzw\",\n-        \"predictor\":   2,\n-        \"sparse_ok\": True,\n-        \"blockxsize\": 512, \n-        \"blockysize\": 512\n-    }\n-\n-    with rasterio.open(source_uri, \"r\") as src:\n-        meta = src.meta.copy()\n-        meta.update(creation_options)\n-\n-        tmp_path = \"/vsimem/\" + get_filename(dest_uri)\n-\n-        with rasterio.open(tmp_path, \"w\", **meta) as tmp:\n-            tmp.write(src.read())\n-\n-    contents = bytearray(virtual_file_to_buffer(tmp_path))\n-\n-    write_bytes_to_target(dest_uri, contents)\n+def copy_tiles_to_workspace(source_uri, order, workspace_uri):\n+    # Download the file and retile\n+    results = []\n+    workspace_prefix = get_filename(source_uri)\n+    \n+    local_dir = create_tmp_directory(workspace_prefix)\n+    try :\n+        MAX_HEIGHT = 1024 * 2\n+        MAX_WIDTH = 1024 * 2\n+\n+        local_path = get_local_copy(source_uri, local_dir)\n+\n+        gdal_options = [\"-of\", \"GTiff\",\n+                        \"-co\", \"compress=lzw\",\n+                        \"-co\", \"predictor=2\",\n+                        \"-co\", \"tiled=yes\",\n+                        \"-co\", \"blockxsize=512\",\n+                        \"-co\", \"blockysize=512\"]\n+\n+        # reproject\n+        reprojected_path = local_path + \"-reprojected.tif\"\n+        cmd = [\"gdalwarp\"] + gdal_options + [\"-t_srs\", \"EPSG:3857\",\n+                                             \"-co\", \"BIGTIFF=YES\", # Handle giant TIFFs.\n+                                             local_path,\n+                                             reprojected_path]\n+        call(cmd)","path":"chunk/chunk.py","position":163,"original_position":163,"commit_id":"723fb4ff070a95a9f9fbe7db08086ca86c8aaac3","original_commit_id":"723fb4ff070a95a9f9fbe7db08086ca86c8aaac3","user":{"login":"mojodna","id":45,"avatar_url":"https://avatars.githubusercontent.com/u/45?v=3","gravatar_id":"","url":"https://api.github.com/users/mojodna","html_url":"https://github.com/mojodna","followers_url":"https://api.github.com/users/mojodna/followers","following_url":"https://api.github.com/users/mojodna/following{/other_user}","gists_url":"https://api.github.com/users/mojodna/gists{/gist_id}","starred_url":"https://api.github.com/users/mojodna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mojodna/subscriptions","organizations_url":"https://api.github.com/users/mojodna/orgs","repos_url":"https://api.github.com/users/mojodna/repos","events_url":"https://api.github.com/users/mojodna/events{/privacy}","received_events_url":"https://api.github.com/users/mojodna/received_events","type":"User","site_admin":false},"body":"Why shell out here?  (No objection, mainly curious.)","created_at":"2016-01-11T23:52:51Z","updated_at":"2016-01-11T23:52:51Z","html_url":"https://github.com/hotosm/oam-server-tiler/pull/4#discussion_r49397710","pull_request_url":"https://api.github.com/repos/hotosm/oam-server-tiler/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/hotosm/oam-server-tiler/pulls/comments/49397710"},"html":{"href":"https://github.com/hotosm/oam-server-tiler/pull/4#discussion_r49397710"},"pull_request":{"href":"https://api.github.com/repos/hotosm/oam-server-tiler/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/hotosm/oam-server-tiler/pulls/4","id":55553814,"html_url":"https://github.com/hotosm/oam-server-tiler/pull/4","diff_url":"https://github.com/hotosm/oam-server-tiler/pull/4.diff","patch_url":"https://github.com/hotosm/oam-server-tiler/pull/4.patch","issue_url":"https://api.github.com/repos/hotosm/oam-server-tiler/issues/4","number":4,"state":"open","locked":false,"title":"Removed initial rasterio workspace copy in favor of GDAL command line.","user":{"login":"lossyrob","id":2320142,"avatar_url":"https://avatars.githubusercontent.com/u/2320142?v=3","gravatar_id":"","url":"https://api.github.com/users/lossyrob","html_url":"https://github.com/lossyrob","followers_url":"https://api.github.com/users/lossyrob/followers","following_url":"https://api.github.com/users/lossyrob/following{/other_user}","gists_url":"https://api.github.com/users/lossyrob/gists{/gist_id}","starred_url":"https://api.github.com/users/lossyrob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lossyrob/subscriptions","organizations_url":"https://api.github.com/users/lossyrob/orgs","repos_url":"https://api.github.com/users/lossyrob/repos","events_url":"https://api.github.com/users/lossyrob/events{/privacy}","received_events_url":"https://api.github.com/users/lossyrob/received_events","type":"User","site_admin":false},"body":"This PR removes some of the initial rasterio steps in `chunk.py`, because it was getting seg faults for very large images. The initial steps are now to download the image from S3 onto temporary storage, reproject to web mercator, tile it out into large chunks if the image is huge, then upload it to the workspace. The rest is basically the same.\r\n\r\nAlso, pin down the rasterio version, since they dropped support for `/vsicurl/` after 0.19 (see https://github.com/mapbox/rasterio/pull/472#issuecomment-169817208)","created_at":"2016-01-09T23:38:51Z","updated_at":"2016-01-11T23:52:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"894b2c5230d67a44a78f694c4b71302f26ece60f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/hotosm/oam-server-tiler/pulls/4/commits","review_comments_url":"https://api.github.com/repos/hotosm/oam-server-tiler/pulls/4/comments","review_comment_url":"https://api.github.com/repos/hotosm/oam-server-tiler/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hotosm/oam-server-tiler/issues/4/comments","statuses_url":"https://api.github.com/repos/hotosm/oam-server-tiler/statuses/723fb4ff070a95a9f9fbe7db08086ca86c8aaac3","head":{"label":"lossyrob:master","ref":"master","sha":"723fb4ff070a95a9f9fbe7db08086ca86c8aaac3","user":{"login":"lossyrob","id":2320142,"avatar_url":"https://avatars.githubusercontent.com/u/2320142?v=3","gravatar_id":"","url":"https://api.github.com/users/lossyrob","html_url":"https://github.com/lossyrob","followers_url":"https://api.github.com/users/lossyrob/followers","following_url":"https://api.github.com/users/lossyrob/following{/other_user}","gists_url":"https://api.github.com/users/lossyrob/gists{/gist_id}","starred_url":"https://api.github.com/users/lossyrob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lossyrob/subscriptions","organizations_url":"https://api.github.com/users/lossyrob/orgs","repos_url":"https://api.github.com/users/lossyrob/repos","events_url":"https://api.github.com/users/lossyrob/events{/privacy}","received_events_url":"https://api.github.com/users/lossyrob/received_events","type":"User","site_admin":false},"repo":{"id":49345989,"name":"oam-server-tiler","full_name":"lossyrob/oam-server-tiler","owner":{"login":"lossyrob","id":2320142,"avatar_url":"https://avatars.githubusercontent.com/u/2320142?v=3","gravatar_id":"","url":"https://api.github.com/users/lossyrob","html_url":"https://github.com/lossyrob","followers_url":"https://api.github.com/users/lossyrob/followers","following_url":"https://api.github.com/users/lossyrob/following{/other_user}","gists_url":"https://api.github.com/users/lossyrob/gists{/gist_id}","starred_url":"https://api.github.com/users/lossyrob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lossyrob/subscriptions","organizations_url":"https://api.github.com/users/lossyrob/orgs","repos_url":"https://api.github.com/users/lossyrob/repos","events_url":"https://api.github.com/users/lossyrob/events{/privacy}","received_events_url":"https://api.github.com/users/lossyrob/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lossyrob/oam-server-tiler","description":"OAM Server Tiler","fork":true,"url":"https://api.github.com/repos/lossyrob/oam-server-tiler","forks_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/forks","keys_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/teams","hooks_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/hooks","issue_events_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/issues/events{/number}","events_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/events","assignees_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/assignees{/user}","branches_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/branches{/branch}","tags_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/tags","blobs_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/git/refs{/sha}","trees_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/statuses/{sha}","languages_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/languages","stargazers_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/stargazers","contributors_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/contributors","subscribers_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/subscribers","subscription_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/subscription","commits_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/commits{/sha}","git_commits_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/git/commits{/sha}","comments_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/comments{/number}","issue_comment_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/issues/comments{/number}","contents_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/contents/{+path}","compare_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/merges","archive_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/downloads","issues_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/issues{/number}","pulls_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/pulls{/number}","milestones_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/milestones{/number}","notifications_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/labels{/name}","releases_url":"https://api.github.com/repos/lossyrob/oam-server-tiler/releases{/id}","created_at":"2016-01-09T23:36:30Z","updated_at":"2016-01-09T23:36:30Z","pushed_at":"2016-01-09T23:36:40Z","git_url":"git://github.com/lossyrob/oam-server-tiler.git","ssh_url":"git@github.com:lossyrob/oam-server-tiler.git","clone_url":"https://github.com/lossyrob/oam-server-tiler.git","svn_url":"https://github.com/lossyrob/oam-server-tiler","homepage":null,"size":71,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"hotosm:master","ref":"master","sha":"4e965fbc8d6d9f614c83a75242c0d525948f71ce","user":{"login":"hotosm","id":458752,"avatar_url":"https://avatars.githubusercontent.com/u/458752?v=3","gravatar_id":"","url":"https://api.github.com/users/hotosm","html_url":"https://github.com/hotosm","followers_url":"https://api.github.com/users/hotosm/followers","following_url":"https://api.github.com/users/hotosm/following{/other_user}","gists_url":"https://api.github.com/users/hotosm/gists{/gist_id}","starred_url":"https://api.github.com/users/hotosm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hotosm/subscriptions","organizations_url":"https://api.github.com/users/hotosm/orgs","repos_url":"https://api.github.com/users/hotosm/repos","events_url":"https://api.github.com/users/hotosm/events{/privacy}","received_events_url":"https://api.github.com/users/hotosm/received_events","type":"Organization","site_admin":false},"repo":{"id":42564297,"name":"oam-server-tiler","full_name":"hotosm/oam-server-tiler","owner":{"login":"hotosm","id":458752,"avatar_url":"https://avatars.githubusercontent.com/u/458752?v=3","gravatar_id":"","url":"https://api.github.com/users/hotosm","html_url":"https://github.com/hotosm","followers_url":"https://api.github.com/users/hotosm/followers","following_url":"https://api.github.com/users/hotosm/following{/other_user}","gists_url":"https://api.github.com/users/hotosm/gists{/gist_id}","starred_url":"https://api.github.com/users/hotosm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hotosm/subscriptions","organizations_url":"https://api.github.com/users/hotosm/orgs","repos_url":"https://api.github.com/users/hotosm/repos","events_url":"https://api.github.com/users/hotosm/events{/privacy}","received_events_url":"https://api.github.com/users/hotosm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hotosm/oam-server-tiler","description":"OAM Server Tiler","fork":false,"url":"https://api.github.com/repos/hotosm/oam-server-tiler","forks_url":"https://api.github.com/repos/hotosm/oam-server-tiler/forks","keys_url":"https://api.github.com/repos/hotosm/oam-server-tiler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hotosm/oam-server-tiler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hotosm/oam-server-tiler/teams","hooks_url":"https://api.github.com/repos/hotosm/oam-server-tiler/hooks","issue_events_url":"https://api.github.com/repos/hotosm/oam-server-tiler/issues/events{/number}","events_url":"https://api.github.com/repos/hotosm/oam-server-tiler/events","assignees_url":"https://api.github.com/repos/hotosm/oam-server-tiler/assignees{/user}","branches_url":"https://api.github.com/repos/hotosm/oam-server-tiler/branches{/branch}","tags_url":"https://api.github.com/repos/hotosm/oam-server-tiler/tags","blobs_url":"https://api.github.com/repos/hotosm/oam-server-tiler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hotosm/oam-server-tiler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hotosm/oam-server-tiler/git/refs{/sha}","trees_url":"https://api.github.com/repos/hotosm/oam-server-tiler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hotosm/oam-server-tiler/statuses/{sha}","languages_url":"https://api.github.com/repos/hotosm/oam-server-tiler/languages","stargazers_url":"https://api.github.com/repos/hotosm/oam-server-tiler/stargazers","contributors_url":"https://api.github.com/repos/hotosm/oam-server-tiler/contributors","subscribers_url":"https://api.github.com/repos/hotosm/oam-server-tiler/subscribers","subscription_url":"https://api.github.com/repos/hotosm/oam-server-tiler/subscription","commits_url":"https://api.github.com/repos/hotosm/oam-server-tiler/commits{/sha}","git_commits_url":"https://api.github.com/repos/hotosm/oam-server-tiler/git/commits{/sha}","comments_url":"https://api.github.com/repos/hotosm/oam-server-tiler/comments{/number}","issue_comment_url":"https://api.github.com/repos/hotosm/oam-server-tiler/issues/comments{/number}","contents_url":"https://api.github.com/repos/hotosm/oam-server-tiler/contents/{+path}","compare_url":"https://api.github.com/repos/hotosm/oam-server-tiler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hotosm/oam-server-tiler/merges","archive_url":"https://api.github.com/repos/hotosm/oam-server-tiler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hotosm/oam-server-tiler/downloads","issues_url":"https://api.github.com/repos/hotosm/oam-server-tiler/issues{/number}","pulls_url":"https://api.github.com/repos/hotosm/oam-server-tiler/pulls{/number}","milestones_url":"https://api.github.com/repos/hotosm/oam-server-tiler/milestones{/number}","notifications_url":"https://api.github.com/repos/hotosm/oam-server-tiler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hotosm/oam-server-tiler/labels{/name}","releases_url":"https://api.github.com/repos/hotosm/oam-server-tiler/releases{/id}","created_at":"2015-09-16T04:21:53Z","updated_at":"2015-11-23T21:17:15Z","pushed_at":"2016-01-09T23:38:51Z","git_url":"git://github.com/hotosm/oam-server-tiler.git","ssh_url":"git@github.com:hotosm/oam-server-tiler.git","clone_url":"https://github.com/hotosm/oam-server-tiler.git","svn_url":"https://github.com/hotosm/oam-server-tiler","homepage":null,"size":197,"stargazers_count":2,"watchers_count":2,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":2,"forks":4,"open_issues":2,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hotosm/oam-server-tiler/pulls/4"},"html":{"href":"https://github.com/hotosm/oam-server-tiler/pull/4"},"issue":{"href":"https://api.github.com/repos/hotosm/oam-server-tiler/issues/4"},"comments":{"href":"https://api.github.com/repos/hotosm/oam-server-tiler/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/hotosm/oam-server-tiler/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/hotosm/oam-server-tiler/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hotosm/oam-server-tiler/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/hotosm/oam-server-tiler/statuses/723fb4ff070a95a9f9fbe7db08086ca86c8aaac3"}}}}