-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #568 from jbouffard/feature/partitioners
Expose Partitioners in the API
- Loading branch information
Showing
14 changed files
with
196 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
geopyspark-backend/geotrellis/src/main/scala/geopyspark/geotrellis/SpatialPartitioner.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package geopyspark.geotrellis | ||
|
||
import geotrellis.spark._ | ||
import geotrellis.spark.io.index._ | ||
import geotrellis.spark.io.index.zcurve._ | ||
import geotrellis.util._ | ||
|
||
import org.apache.spark._ | ||
|
||
import scala.reflect._ | ||
|
||
|
||
class SpatialPartitioner[K: SpatialComponent](partitions: Int, bits: Int) extends Partitioner { | ||
def numPartitions: Int = partitions | ||
|
||
def getPartition(key: Any): Int = { | ||
val k = key.asInstanceOf[K] | ||
val SpatialKey(col, row) = k.getComponent[SpatialKey] | ||
((Z2(col, row).z >> bits) % partitions).toInt | ||
} | ||
} | ||
|
||
object SpatialPartitioner { | ||
def apply[K: SpatialComponent](partitions: Int, bits: Int): SpatialPartitioner[K] = | ||
new SpatialPartitioner[K](partitions, bits) | ||
|
||
def apply[K: SpatialComponent](partitions: Int): SpatialPartitioner[K] = | ||
new SpatialPartitioner[K](partitions, 8) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.