{"action":"created","comment":{"url":"https://api.github.com/repos/locationtech/geomesa/pulls/comments/32253804","id":32253804,"diff_hunk":"@@ -0,0 +1,174 @@\n+/*\n+ * Copyright 2014 Commonwealth Computer Research, Inc.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package org.locationtech.geomesa.tools.ingest\n+\n+import java.io.File\n+import java.util.UUID\n+\n+import com.typesafe.scalalogging.slf4j.Logging\n+import org.geotools.coverage.grid.GridCoverage2D\n+import org.locationtech.geomesa.raster.util.RasterUtils.IngestRasterParams\n+import org.locationtech.geomesa.utils.geohash.{BoundingBox, GeoHash, GeohashUtils}\n+\n+import scala.collection.parallel.ForkJoinTaskSupport\n+import scala.math.ceil\n+import scala.sys.process._\n+import scala.util.Try\n+\n+class RasterChunking(config: Map[String, Option[String]]) extends RasterIngest {\n+  lazy val path = config(IngestRasterParams.FILE_PATH).get\n+  lazy val fileType = config(IngestRasterParams.FORMAT).get\n+  lazy val parLevel = config(IngestRasterParams.PARLEVEL).get.toInt\n+  lazy val chunkSize = config(IngestRasterParams.CHUNKSIZE).get.toInt\n+\n+  def runChunkTask() = Try {\n+    val outDir = s\"/tmp/raster_ingest_${UUID.randomUUID.toString}\"\n+    chunkRasterLocal(path, fileType, outDir, chunkSize)\n+    outDir\n+  }\n+\n+  /**\n+   * Cut image into chunks so that the size of each chunk is about the given size in bytes,\n+   * and save chunks into local geotiff files.\n+   *\n+   * @param file Raster file to be divided\n+   * @param fileType Raster file type\n+   * @param outDir Directory to put chunk files in\n+   * @param size  Desired size limit in bytes\n+   */\n+  def chunkRasterLocal(file: String, fileType: String, outDir: String, size: Double) {\n+    val rasterReader = getReader(new File(file), fileType)\n+    val rasterGrid: GridCoverage2D = rasterReader.read(null)\n+    val envelope = rasterGrid.getEnvelope2D\n+    val (minX, minY, maxX, maxY) =\n+      RasterChunking.checkAndModifyBounds(envelope.getMinX, envelope.getMinY, envelope.getMaxX, envelope.getMaxY)\n+    val bbox = BoundingBox(minX, maxX, minY, maxY)\n+    val (gridStepX, gridStepY) = RasterChunking.getSteps(rasterGrid)\n+    val chunkPrec = RasterChunking.GetGeoHashPrecisionBySize(rasterGrid, size)\n+    val llGh = GeoHash(minX, minY, chunkPrec)\n+    val urGh = GeoHash(maxX, maxY, chunkPrec)\n+    val (llX, llY, urX, urY) = (llGh.getPoint.getX, llGh.getPoint.getY, urGh.getPoint.getX, urGh.getPoint.getY)\n+    val (deltaX, deltaY) = (llGh.bbox.ur.getX - llGh.bbox.ll.getX, llGh.bbox.ur.getY - llGh.bbox.ll.getY)\n+    val (stepsX, stepsY) = (ceil((urX - llX) / deltaX).toInt, ceil((urY - llY) / deltaY).toInt)\n+\n+    new File(outDir).mkdir\n+\n+    val indexes =\n+      (for {\n+        i <- 0 to stepsX\n+        j <- 0 to stepsY\n+      } yield (i, j)).par\n+    indexes.tasksupport = new ForkJoinTaskSupport(new scala.concurrent.forkjoin.ForkJoinPool(parLevel))\n+\n+    indexes.foreach { case (i, j) =>\n+      val geoHash = GeoHash(llX + deltaX * i, llY + deltaY * j, chunkPrec)\n+      getChunkBounds(geoHash, bbox, gridStepX, gridStepY).foreach { case (minX, maxX, minY, maxY) =>\n+        if (maxX > minX && maxY > minY) {\n+          val cmd = Seq(\"gdal_translate\", \"-q\", \"-of\", \"GTIFF\", \"-projwin\", s\"${minX}\", s\"${maxY}\",\n+            s\"${maxX}\", s\"${minY}\", file, s\"${outDir}/gh_${geoHash.hash}.tif\")\n+          cmd.!!\n+        }\n+      }\n+    }\n+  }\n+\n+  //Get bounds from given GeoHash that are used to crop raster\n+  def getChunkBounds(gh: GeoHash,\n+                     bbox: BoundingBox,\n+                     stepX: Double,\n+                     stepY: Double): Option[(Double, Double, Double, Double)] = {\n+    BoundingBox.intersects(bbox, gh.bbox) match {\n+      case false => None\n+      case _ =>\n+        val (ghMinX, ghMinY, ghMaxX, ghMaxY) = (gh.bbox.ll.getX, gh.bbox.ll.getY, gh.bbox.ur.getX, gh.bbox.ur.getY)\n+        val (rMinX, rMinY, rMaxX, rMaxY) = (bbox.ll.getX, bbox.ll.getY, bbox.ur.getX, bbox.ur.getY)\n+        Some(getCropLocation(ghMinX, rMinX, rMaxX, stepX, false),\n+             getCropLocation(ghMaxX, rMinX, rMaxX, stepX, true),\n+             getCropLocation(ghMinY, rMinY, rMaxY, stepY, false),\n+             getCropLocation(ghMaxY, rMinY, rMaxY, stepY, true))\n+    }\n+  }\n+\n+  //Get location on raster grid for cropping operation\n+  def getCropLocation(coor: Double,\n+                      minCoor: Double,\n+                      maxCoor: Double,\n+                      step: Double,\n+                      isMax: Boolean): Double = {\n+    val steps = ((coor - minCoor) / step).toInt\n+    val calCoor = {\n+      val tmpCoor = minCoor + step * steps.toDouble\n+      //NO DUPLICATION: With the following line, adjacent chunks have no overlapped edge.\n+      if (coor - tmpCoor > 0.5D * step) tmpCoor + step\n+      //DUPLICATION POSSIBLE: With the following line, adjacent chunks may have one edge\n+      //(width = 1) overlapped.","path":"geomesa-tools/src/main/scala/org/locationtech/geomesa/tools/ingest/RasterChunking.scala","position":117,"original_position":117,"commit_id":"e815040b22f87d7a3f178ce29a89b136b95d14ea","original_commit_id":"e815040b22f87d7a3f178ce29a89b136b95d14ea","user":{"login":"ronq","id":5257756,"avatar_url":"https://avatars.githubusercontent.com/u/5257756?v=3","gravatar_id":"","url":"https://api.github.com/users/ronq","html_url":"https://github.com/ronq","followers_url":"https://api.github.com/users/ronq/followers","following_url":"https://api.github.com/users/ronq/following{/other_user}","gists_url":"https://api.github.com/users/ronq/gists{/gist_id}","starred_url":"https://api.github.com/users/ronq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ronq/subscriptions","organizations_url":"https://api.github.com/users/ronq/orgs","repos_url":"https://api.github.com/users/ronq/repos","events_url":"https://api.github.com/users/ronq/events{/privacy}","received_events_url":"https://api.github.com/users/ronq/received_events","type":"User","site_admin":false},"body":"Remove disabled lines","created_at":"2015-06-11T18:42:29Z","updated_at":"2015-06-11T18:42:29Z","html_url":"https://github.com/locationtech/geomesa/pull/598#discussion_r32253804","pull_request_url":"https://api.github.com/repos/locationtech/geomesa/pulls/598","_links":{"self":{"href":"https://api.github.com/repos/locationtech/geomesa/pulls/comments/32253804"},"html":{"href":"https://github.com/locationtech/geomesa/pull/598#discussion_r32253804"},"pull_request":{"href":"https://api.github.com/repos/locationtech/geomesa/pulls/598"}}},"pull_request":{"url":"https://api.github.com/repos/locationtech/geomesa/pulls/598","id":36857001,"html_url":"https://github.com/locationtech/geomesa/pull/598","diff_url":"https://github.com/locationtech/geomesa/pull/598.diff","patch_url":"https://github.com/locationtech/geomesa/pull/598.patch","issue_url":"https://api.github.com/repos/locationtech/geomesa/issues/598","number":598,"state":"open","locked":false,"title":"Added Raster Module","user":{"login":"AndrewAnnex","id":2126916,"avatar_url":"https://avatars.githubusercontent.com/u/2126916?v=3","gravatar_id":"","url":"https://api.github.com/users/AndrewAnnex","html_url":"https://github.com/AndrewAnnex","followers_url":"https://api.github.com/users/AndrewAnnex/followers","following_url":"https://api.github.com/users/AndrewAnnex/following{/other_user}","gists_url":"https://api.github.com/users/AndrewAnnex/gists{/gist_id}","starred_url":"https://api.github.com/users/AndrewAnnex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndrewAnnex/subscriptions","organizations_url":"https://api.github.com/users/AndrewAnnex/orgs","repos_url":"https://api.github.com/users/AndrewAnnex/repos","events_url":"https://api.github.com/users/AndrewAnnex/events{/privacy}","received_events_url":"https://api.github.com/users/AndrewAnnex/received_events","type":"User","site_admin":false},"body":"* refactored raster metadata to now be a KryoSimpleFeature\r\n* removed leading tilda in rows\r\n* added readme to raster module\r\n* removed AccumuloCoverageStore, geoserver ingest bits\r\n* deleteraster command added\r\n\r\nSigned-off-by: Andrew Annex <aannex@ccri.com>","created_at":"2015-06-03T17:29:37Z","updated_at":"2015-06-11T18:42:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dc92ab86109c8ffdf8662665ad7815f4084d7a90","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/locationtech/geomesa/pulls/598/commits","review_comments_url":"https://api.github.com/repos/locationtech/geomesa/pulls/598/comments","review_comment_url":"https://api.github.com/repos/locationtech/geomesa/pulls/comments{/number}","comments_url":"https://api.github.com/repos/locationtech/geomesa/issues/598/comments","statuses_url":"https://api.github.com/repos/locationtech/geomesa/statuses/e815040b22f87d7a3f178ce29a89b136b95d14ea","head":{"label":"AndrewAnnex:fcr_add_raster_module_to_master","ref":"fcr_add_raster_module_to_master","sha":"e815040b22f87d7a3f178ce29a89b136b95d14ea","user":{"login":"AndrewAnnex","id":2126916,"avatar_url":"https://avatars.githubusercontent.com/u/2126916?v=3","gravatar_id":"","url":"https://api.github.com/users/AndrewAnnex","html_url":"https://github.com/AndrewAnnex","followers_url":"https://api.github.com/users/AndrewAnnex/followers","following_url":"https://api.github.com/users/AndrewAnnex/following{/other_user}","gists_url":"https://api.github.com/users/AndrewAnnex/gists{/gist_id}","starred_url":"https://api.github.com/users/AndrewAnnex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndrewAnnex/subscriptions","organizations_url":"https://api.github.com/users/AndrewAnnex/orgs","repos_url":"https://api.github.com/users/AndrewAnnex/repos","events_url":"https://api.github.com/users/AndrewAnnex/events{/privacy}","received_events_url":"https://api.github.com/users/AndrewAnnex/received_events","type":"User","site_admin":false},"repo":{"id":21002360,"name":"geomesa","full_name":"AndrewAnnex/geomesa","owner":{"login":"AndrewAnnex","id":2126916,"avatar_url":"https://avatars.githubusercontent.com/u/2126916?v=3","gravatar_id":"","url":"https://api.github.com/users/AndrewAnnex","html_url":"https://github.com/AndrewAnnex","followers_url":"https://api.github.com/users/AndrewAnnex/followers","following_url":"https://api.github.com/users/AndrewAnnex/following{/other_user}","gists_url":"https://api.github.com/users/AndrewAnnex/gists{/gist_id}","starred_url":"https://api.github.com/users/AndrewAnnex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndrewAnnex/subscriptions","organizations_url":"https://api.github.com/users/AndrewAnnex/orgs","repos_url":"https://api.github.com/users/AndrewAnnex/repos","events_url":"https://api.github.com/users/AndrewAnnex/events{/privacy}","received_events_url":"https://api.github.com/users/AndrewAnnex/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/AndrewAnnex/geomesa","description":"core","fork":true,"url":"https://api.github.com/repos/AndrewAnnex/geomesa","forks_url":"https://api.github.com/repos/AndrewAnnex/geomesa/forks","keys_url":"https://api.github.com/repos/AndrewAnnex/geomesa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AndrewAnnex/geomesa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AndrewAnnex/geomesa/teams","hooks_url":"https://api.github.com/repos/AndrewAnnex/geomesa/hooks","issue_events_url":"https://api.github.com/repos/AndrewAnnex/geomesa/issues/events{/number}","events_url":"https://api.github.com/repos/AndrewAnnex/geomesa/events","assignees_url":"https://api.github.com/repos/AndrewAnnex/geomesa/assignees{/user}","branches_url":"https://api.github.com/repos/AndrewAnnex/geomesa/branches{/branch}","tags_url":"https://api.github.com/repos/AndrewAnnex/geomesa/tags","blobs_url":"https://api.github.com/repos/AndrewAnnex/geomesa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AndrewAnnex/geomesa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AndrewAnnex/geomesa/git/refs{/sha}","trees_url":"https://api.github.com/repos/AndrewAnnex/geomesa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AndrewAnnex/geomesa/statuses/{sha}","languages_url":"https://api.github.com/repos/AndrewAnnex/geomesa/languages","stargazers_url":"https://api.github.com/repos/AndrewAnnex/geomesa/stargazers","contributors_url":"https://api.github.com/repos/AndrewAnnex/geomesa/contributors","subscribers_url":"https://api.github.com/repos/AndrewAnnex/geomesa/subscribers","subscription_url":"https://api.github.com/repos/AndrewAnnex/geomesa/subscription","commits_url":"https://api.github.com/repos/AndrewAnnex/geomesa/commits{/sha}","git_commits_url":"https://api.github.com/repos/AndrewAnnex/geomesa/git/commits{/sha}","comments_url":"https://api.github.com/repos/AndrewAnnex/geomesa/comments{/number}","issue_comment_url":"https://api.github.com/repos/AndrewAnnex/geomesa/issues/comments{/number}","contents_url":"https://api.github.com/repos/AndrewAnnex/geomesa/contents/{+path}","compare_url":"https://api.github.com/repos/AndrewAnnex/geomesa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AndrewAnnex/geomesa/merges","archive_url":"https://api.github.com/repos/AndrewAnnex/geomesa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AndrewAnnex/geomesa/downloads","issues_url":"https://api.github.com/repos/AndrewAnnex/geomesa/issues{/number}","pulls_url":"https://api.github.com/repos/AndrewAnnex/geomesa/pulls{/number}","milestones_url":"https://api.github.com/repos/AndrewAnnex/geomesa/milestones{/number}","notifications_url":"https://api.github.com/repos/AndrewAnnex/geomesa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AndrewAnnex/geomesa/labels{/name}","releases_url":"https://api.github.com/repos/AndrewAnnex/geomesa/releases{/id}","created_at":"2014-06-19T14:03:14Z","updated_at":"2015-04-14T19:53:04Z","pushed_at":"2015-06-11T16:32:09Z","git_url":"git://github.com/AndrewAnnex/geomesa.git","ssh_url":"git@github.com:AndrewAnnex/geomesa.git","clone_url":"https://github.com/AndrewAnnex/geomesa.git","svn_url":"https://github.com/AndrewAnnex/geomesa","homepage":"","size":8384,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"accumulo1.5.x/1.x"}},"base":{"label":"locationtech:master","ref":"master","sha":"5595bdaeac207ddfb7903246f3a97bc45b6e0c88","user":{"login":"locationtech","id":1991411,"avatar_url":"https://avatars.githubusercontent.com/u/1991411?v=3","gravatar_id":"","url":"https://api.github.com/users/locationtech","html_url":"https://github.com/locationtech","followers_url":"https://api.github.com/users/locationtech/followers","following_url":"https://api.github.com/users/locationtech/following{/other_user}","gists_url":"https://api.github.com/users/locationtech/gists{/gist_id}","starred_url":"https://api.github.com/users/locationtech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/locationtech/subscriptions","organizations_url":"https://api.github.com/users/locationtech/orgs","repos_url":"https://api.github.com/users/locationtech/repos","events_url":"https://api.github.com/users/locationtech/events{/privacy}","received_events_url":"https://api.github.com/users/locationtech/received_events","type":"Organization","site_admin":false},"repo":{"id":13226069,"name":"geomesa","full_name":"locationtech/geomesa","owner":{"login":"locationtech","id":1991411,"avatar_url":"https://avatars.githubusercontent.com/u/1991411?v=3","gravatar_id":"","url":"https://api.github.com/users/locationtech","html_url":"https://github.com/locationtech","followers_url":"https://api.github.com/users/locationtech/followers","following_url":"https://api.github.com/users/locationtech/following{/other_user}","gists_url":"https://api.github.com/users/locationtech/gists{/gist_id}","starred_url":"https://api.github.com/users/locationtech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/locationtech/subscriptions","organizations_url":"https://api.github.com/users/locationtech/orgs","repos_url":"https://api.github.com/users/locationtech/repos","events_url":"https://api.github.com/users/locationtech/events{/privacy}","received_events_url":"https://api.github.com/users/locationtech/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/locationtech/geomesa","description":"","fork":false,"url":"https://api.github.com/repos/locationtech/geomesa","forks_url":"https://api.github.com/repos/locationtech/geomesa/forks","keys_url":"https://api.github.com/repos/locationtech/geomesa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/locationtech/geomesa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/locationtech/geomesa/teams","hooks_url":"https://api.github.com/repos/locationtech/geomesa/hooks","issue_events_url":"https://api.github.com/repos/locationtech/geomesa/issues/events{/number}","events_url":"https://api.github.com/repos/locationtech/geomesa/events","assignees_url":"https://api.github.com/repos/locationtech/geomesa/assignees{/user}","branches_url":"https://api.github.com/repos/locationtech/geomesa/branches{/branch}","tags_url":"https://api.github.com/repos/locationtech/geomesa/tags","blobs_url":"https://api.github.com/repos/locationtech/geomesa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/locationtech/geomesa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/locationtech/geomesa/git/refs{/sha}","trees_url":"https://api.github.com/repos/locationtech/geomesa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/locationtech/geomesa/statuses/{sha}","languages_url":"https://api.github.com/repos/locationtech/geomesa/languages","stargazers_url":"https://api.github.com/repos/locationtech/geomesa/stargazers","contributors_url":"https://api.github.com/repos/locationtech/geomesa/contributors","subscribers_url":"https://api.github.com/repos/locationtech/geomesa/subscribers","subscription_url":"https://api.github.com/repos/locationtech/geomesa/subscription","commits_url":"https://api.github.com/repos/locationtech/geomesa/commits{/sha}","git_commits_url":"https://api.github.com/repos/locationtech/geomesa/git/commits{/sha}","comments_url":"https://api.github.com/repos/locationtech/geomesa/comments{/number}","issue_comment_url":"https://api.github.com/repos/locationtech/geomesa/issues/comments{/number}","contents_url":"https://api.github.com/repos/locationtech/geomesa/contents/{+path}","compare_url":"https://api.github.com/repos/locationtech/geomesa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/locationtech/geomesa/merges","archive_url":"https://api.github.com/repos/locationtech/geomesa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/locationtech/geomesa/downloads","issues_url":"https://api.github.com/repos/locationtech/geomesa/issues{/number}","pulls_url":"https://api.github.com/repos/locationtech/geomesa/pulls{/number}","milestones_url":"https://api.github.com/repos/locationtech/geomesa/milestones{/number}","notifications_url":"https://api.github.com/repos/locationtech/geomesa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/locationtech/geomesa/labels{/name}","releases_url":"https://api.github.com/repos/locationtech/geomesa/releases{/id}","created_at":"2013-09-30T20:13:46Z","updated_at":"2015-06-11T02:02:05Z","pushed_at":"2015-06-11T16:32:10Z","git_url":"git://github.com/locationtech/geomesa.git","ssh_url":"git@github.com:locationtech/geomesa.git","clone_url":"https://github.com/locationtech/geomesa.git","svn_url":"https://github.com/locationtech/geomesa","homepage":null,"size":20672,"stargazers_count":80,"watchers_count":80,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":48,"mirror_url":null,"open_issues_count":18,"forks":48,"open_issues":18,"watchers":80,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/locationtech/geomesa/pulls/598"},"html":{"href":"https://github.com/locationtech/geomesa/pull/598"},"issue":{"href":"https://api.github.com/repos/locationtech/geomesa/issues/598"},"comments":{"href":"https://api.github.com/repos/locationtech/geomesa/issues/598/comments"},"review_comments":{"href":"https://api.github.com/repos/locationtech/geomesa/pulls/598/comments"},"review_comment":{"href":"https://api.github.com/repos/locationtech/geomesa/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/locationtech/geomesa/pulls/598/commits"},"statuses":{"href":"https://api.github.com/repos/locationtech/geomesa/statuses/e815040b22f87d7a3f178ce29a89b136b95d14ea"}}}}