# Euclidean distance tiles #1552

Merged
merged 14 commits into from Jul 15, 2016

## Conversation

Projects
None yet
2 participants
Contributor

### jpolchlo commented Jun 15, 2016

 This pull request addresses issue #941 by creating a Euclidean distance field from a set of points. The operation creates a Voronoi diagram from the input points and rasterizes each resulting polygonal cell to an output DoubleArrayTile using a simple distance function from the point that generated the Voronoi cell. A note on complexity: this method builds a Delaunay triangulation in O(n log n) time, generates the Voronoi diagram in O(n) time, and the rasterization function applied to each pixel is O(1). Thus, the expectation is that the performance of this module ought to be fairly reasonable.

### jpolchlo added some commits Jun 15, 2016

``` Added EuclideanDistanceTile ```
``` 3a28034 ```
``` Added voronoiCellsWithPoints() as method to Voronoi ```
``` b3d1f01 ```

### lossyrob reviewed Jun 20, 2016

 import geotrellis.vector.voronoi._ import scala.math.sqrt object EuclideanDistanceTile {

#### lossyrob Jun 20, 2016

Member

This should be moved out of root package; `geotrellis.raster.distance` seems general enough to be a home for it.

Needs `MethodExtensions[Traversable[Point]]`, and the corresponding machinery.

### lossyrob reviewed Jun 20, 2016

 def fillFn(base: Point)(c: Int, r: Int): Unit = { val (x,y) = re.gridToMap(c,r) tile.setDouble(c,r,sqrt((x-base.x)*(x-base.x) + (y-base.y)*(y-base.y)))

#### lossyrob Jun 20, 2016

Member

Formatting: spaces after comma. Spaces between operands.
Everywhere else we give the argument the names `col` and `row`, should follow that pattern (and generally use the longer names for clarity, and to fit the rest of the library, e.g. "points" instead of "pts", "rasterExtent" instead of "re")

### lossyrob reviewed Jun 20, 2016

 def det3 (a11: Double, a12: Double, a13: Double, a21: Double, a22: Double, a23: Double, a31: Double, a32: Double, a33: Double): Double = { val m = MatrixUtils.createRealMatrix(Array(Array(a11,a12,a13),Array(a21,a22,a23),Array(a31,a32,a33)))

#### lossyrob Jun 20, 2016

Member

format: comma spacing

### lossyrob reviewed Jun 20, 2016

 // m.setEntry(0, 1, a12) // m.setEntry(0, 2, a13) // m.setEntry(1, 0, a21) // m.setEntry(1, 1, a22)

#### lossyrob Jun 20, 2016

Member

Shouldn't keep around debug comments in finished code.

### lossyrob reviewed Jun 20, 2016

 } //println(s"Inserting \$e as \$vs [using \$idx as key]") faceIncidentToVertex += (e.vert -> e, e.next.vert -> e.next, e.next.next.vert -> e.next.next) //println(s"Adding to faceIncidentToVertex: \${e.vert -> e}, \${e.next.vert -> e.next}, \${e.next.next.vert -> e.next.next}")

#### lossyrob Jun 20, 2016

Member

Debug printlns should be removed. If there's a specific reason for it to be around (e.g. this is always the information that is needed when this breaks, so kept for perpetuity) then it should be commented on and kept, but by default all debug lines and comments should be removed.

### lossyrob reviewed Jun 20, 2016

 case (Some(x),_,_,_) => (x,0) case (_,Some(x),_,_) => (x,1) case (_,_,Some(x),_) => (x,2) case (_,_,_,Some(x)) => (x,3)

#### lossyrob Jun 20, 2016

Member

These magic numbers probably deserve some comments explaining what they are

### jpolchlo added some commits Jun 15, 2016

``` Clean up, bug fixes, and documentation ```
``` f93a374 ```
``` Added geotrellis.util.Constants object ```
``` 8023651 ```
``` Added MethodExtensions and test suite ```
``` 8974699 ```
``` Made Voronoi more self-documenting ```
``` c38bf89 ```
``` Made constants private ```
``` 4c8cf97 ```
``` Added MethodExtensions and test suite ```
``` ed6577c ```
``` Merge remote-tracking branch 'upstream/master' into feature/Euclidean… ```
`…DistanceTile`
``` 79cab07 ```
``` Fixed raster package.scala ```
``` bcedfc6 ```

### lossyrob reviewed Jun 28, 2016

 @@ -0,0 +1,97 @@ package geotrellis.vector.voronoi class HalfEdge[V,F](val vert: V, var flip: HalfEdge[V,F], var next: HalfEdge[V,F], var face: Option[F]) {

Member

Polygon method?

### lossyrob reviewed Jun 28, 2016

 * A method to generate the Voronoi cell corresponding to the point in verts(i). Note that if * verts(i) is not distinct, this function may raise an exception. */ def mkVoronoiCell(i: Int): Polygon = {

#### lossyrob Jun 28, 2016

Member

can drop the `mk`

### jpolchlo added some commits Jul 13, 2016

``` Updated method extensions ```
``` 06c58aa ```
``` Updated Voronoi diagram code from feature/Voronoi ```
``` f0006b9 ```
``` Added to method extensions ```
``` 42b10b4 ```
Member

### lossyrob commented Jul 15, 2016

 @jpolchlo this cannot be merged. Please update it to master.
``` Merge remote-tracking branch 'upstream/master' into feature/Euclidean… ```
`…DistanceTile`
``` fb825a3 ```

### lossyrob merged commit `2a74a3b` into locationtech:master Jul 15, 2016 1 check failed

#### 1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details

Closed