From 6b9649334d4904c1efee147e3cd8a8069ec01744 Mon Sep 17 00:00:00 2001 From: Grigory Pomadchin Date: Fri, 26 Apr 2019 11:50:49 -0400 Subject: [PATCH] Changed normalized flag name, optimized the code, removed unused code --- .../scala/geotrellis/vectortile/Layer.scala | 20 ++++++++++++------- .../geotrellis/vectortile/VectorTile.scala | 4 ++-- .../scala/geotrellis/vectortile/package.scala | 8 +------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/vectortile/src/main/scala/geotrellis/vectortile/Layer.scala b/vectortile/src/main/scala/geotrellis/vectortile/Layer.scala index 01db4f400a..cb11d6c6f3 100644 --- a/vectortile/src/main/scala/geotrellis/vectortile/Layer.scala +++ b/vectortile/src/main/scala/geotrellis/vectortile/Layer.scala @@ -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]] @@ -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)) diff --git a/vectortile/src/main/scala/geotrellis/vectortile/VectorTile.scala b/vectortile/src/main/scala/geotrellis/vectortile/VectorTile.scala index e4992d4120..bf4938fa12 100644 --- a/vectortile/src/main/scala/geotrellis/vectortile/VectorTile.scala +++ b/vectortile/src/main/scala/geotrellis/vectortile/VectorTile.scala @@ -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 diff --git a/vectortile/src/main/scala/geotrellis/vectortile/package.scala b/vectortile/src/main/scala/geotrellis/vectortile/package.scala index 1be2f355f1..1d88b33a95 100644 --- a/vectortile/src/main/scala/geotrellis/vectortile/package.scala +++ b/vectortile/src/main/scala/geotrellis/vectortile/package.scala @@ -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 { }