Skip to content

Commit

Permalink
Changed normalized flag name, optimized the code, removed unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin committed Apr 26, 2019
1 parent 2ed7bf3 commit 6b96493
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
20 changes: 13 additions & 7 deletions vectortile/src/main/scala/geotrellis/vectortile/Layer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import scala.collection.mutable.ListBuffer
}

/** Encode this ProtobufLayer a mid-level Layer ready to be encoded as protobuf bytes. */
private[vectortile] def toProtobuf(normalize: Boolean = true): PBLayer = {
private[vectortile] def toProtobuf(forceWindClockwise: Boolean = true): PBLayer = {
val pgp = implicitly[ProtobufGeom[Point, MultiPoint]]
val pgl = implicitly[ProtobufGeom[Line, MultiLine]]
val pgy = implicitly[ProtobufGeom[Polygon, MultiPolygon]]
Expand All @@ -102,12 +102,18 @@ import scala.collection.mutable.ListBuffer
* points.map(f => unfeature(keys, values, f))
*/
val features = Seq(
points.map(f => unfeature(keyMap, valMap, POINT, pgp.toCommands(Left(f.geom.normalize(normalize)), tileExtent.northWest, resolution), f.data)),
multiPoints.map(f => unfeature(keyMap, valMap, POINT, pgp.toCommands(Right(f.geom.normalize(normalize)), tileExtent.northWest, resolution), f.data)),
lines.map(f => unfeature(keyMap, valMap, LINESTRING, pgl.toCommands(Left(f.geom.normalize(normalize)), tileExtent.northWest, resolution), f.data)),
multiLines.map(f => unfeature(keyMap, valMap, LINESTRING, pgl.toCommands(Right(f.geom.normalize(normalize)), tileExtent.northWest, resolution), f.data)),
polygons.map(f => unfeature(keyMap, valMap, POLYGON, pgy.toCommands(Left(f.geom.normalize(normalize)), tileExtent.northWest, resolution), f.data)),
multiPolygons.map(f => unfeature(keyMap, valMap, POLYGON, pgy.toCommands(Right(f.geom.normalize(normalize)), tileExtent.northWest, resolution), f.data))
points.map(f => unfeature(keyMap, valMap, POINT, pgp.toCommands(Left(f.geom), tileExtent.northWest, resolution), f.data)),
multiPoints.map(f => unfeature(keyMap, valMap, POINT, pgp.toCommands(Right(f.geom), tileExtent.northWest, resolution), f.data)),
lines.map(f => unfeature(keyMap, valMap, LINESTRING, pgl.toCommands(Left(f.geom), tileExtent.northWest, resolution), f.data)),
multiLines.map(f => unfeature(keyMap, valMap, LINESTRING, pgl.toCommands(Right(f.geom), tileExtent.northWest, resolution), f.data)),
polygons.map { f =>
val geom = if(forceWindClockwise) f.geom.normalized else f.geom
unfeature(keyMap, valMap, POLYGON, pgy.toCommands(Left(geom), tileExtent.northWest, resolution), f.data)
},
multiPolygons.map { f =>
val geom = if(forceWindClockwise) f.geom.normalized else f.geom
unfeature(keyMap, valMap, POLYGON, pgy.toCommands(Right(geom), tileExtent.northWest, resolution), f.data)
}
).flatten

PBLayer(version, name, features, keys, values.map(_.toProtobuf), Some(tileWidth))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ import geotrellis.util.annotations.experimental
* @constructor This is not meant to be called directly - see this class's
* companion object for the available helper methods.
*/
@experimental case class VectorTile(layers: Map[String, Layer], tileExtent: Extent, normalize: Boolean = true) {
@experimental case class VectorTile(layers: Map[String, Layer], tileExtent: Extent, forceWindClockwise: Boolean = true) {
/** Encode this VectorTile back into a mid-level Protobuf object. */
private def toProtobuf: PBTile = PBTile(layers = layers.values.map(_.toProtobuf(normalize)).toSeq)
private def toProtobuf: PBTile = PBTile(layers = layers.values.map(_.toProtobuf(forceWindClockwise)).toSeq)

/** Encode this VectorTile back into its original form of Protobuf bytes. */
def toBytes: Array[Byte] = toProtobuf.toByteArray
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,4 @@ package geotrellis
* @version 2.1
*/

import geotrellis.vector.Geometry

package object vectortile {
implicit class withGeometryMethods[G <: Geometry](val self: G) extends AnyVal {
private[vectortile] def normalize(enabled: Boolean = true): G = { if(enabled) { self.jtsGeom.normalize() }; self }
}
}
package object vectortile { }

0 comments on commit 6b96493

Please sign in to comment.