Skip to content

Commit

Permalink
Separate monoidal part of strict layers (#3330)
Browse files Browse the repository at this point in the history
* separate monoidal part of strict layers

Signed-off-by: James Santucci <[email protected]>
  • Loading branch information
jisantuc authored Jan 28, 2021
1 parent 2f8348a commit 431e8a6
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Remove explicit unused Scaffeine dependency from projects [#3314](https://github.com/locationtech/geotrellis/pull/3314)
- Remove an excessive close after the abort call in S3RangeReader [#3324](https://github.com/locationtech/geotrellis/pull/3324)
- Fix sigmoidal contrast calculation [#3328](https://github.com/locationtech/geotrellis/pull/3328)
- Separated monoidal component of `vectortile.StrictLayer` [#3330](https://github.com/locationtech/geotrellis/pull/3330)

## [3.5.1] - 2020-11-23

Expand Down
55 changes: 42 additions & 13 deletions vectortile/src/main/scala/geotrellis/vectortile/Layer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,40 @@ ${sortedMeta.map({ case (k,v) => s" ${k}: ${v}"}).mkString("\n")}
tileWidth: Int,
version: Int,
tileExtent: Extent,
points: Seq[MVTFeature[Point]],
multiPoints: Seq[MVTFeature[MultiPoint]],
lines: Seq[MVTFeature[LineString]],
multiLines: Seq[MVTFeature[MultiLineString]],
polygons: Seq[MVTFeature[Polygon]],
multiPolygons: Seq[MVTFeature[MultiPolygon]]
) extends Layer
mvtFeatures: MVTFeatures
) extends Layer {
def points = mvtFeatures.points
def multiPoints = mvtFeatures.multiPoints
def lines = mvtFeatures.lines
def multiLines = mvtFeatures.multiLines
def polygons = mvtFeatures.polygons
def multiPolygons = mvtFeatures.multiPolygons
}

object StrictLayer {
def apply(
name: String,
tileWidth: Int,
version: Int,
tileExtent: Extent,
points: Seq[MVTFeature[Point]],
multiPoints: Seq[MVTFeature[MultiPoint]],
lines: Seq[MVTFeature[LineString]],
multiLines: Seq[MVTFeature[MultiLineString]],
polygons: Seq[MVTFeature[Polygon]],
multiPolygons: Seq[MVTFeature[MultiPolygon]]
): StrictLayer = StrictLayer(
name, tileWidth, version, tileExtent,
MVTFeatures(
points,
multiPoints,
lines,
multiLines,
polygons,
multiPolygons
)
)
}

/**
* A [[Layer]] decoded from Protobuf data. All of its Features are decoded
Expand Down Expand Up @@ -374,12 +401,14 @@ ${sortedMeta.map({ case (k,v) => s" ${k}: ${v}"}).mkString("\n")}
tileWidth,
version,
tileExtent,
points,
multiPoints,
lines,
multiLines,
polygons,
multiPolygons
MVTFeatures(
points,
multiPoints,
lines,
multiLines,
polygons,
multiPolygons
)
)
}
}
64 changes: 64 additions & 0 deletions vectortile/src/main/scala/geotrellis/vectortile/MVTFeatures.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2019 Azavea
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package geotrellis.vectortile

import geotrellis.vector.{
Point,
MultiPoint,
LineString,
MultiLineString,
Polygon,
MultiPolygon
}
import cats.Monoid

/** Container case class for collections of [[MVTFeature]]s
*
* This is separated for ease of use when reading geometries from
* places. With the `Monoid` instance for `MVTFeatures`, each geometry
* can be lifted into a seq in the relevant attribute, and then
* the separate `MVTFeatures` case classes can all be combined.
*/
final case class MVTFeatures(
/** Every Point Feature in this Layer. */
points: Seq[MVTFeature[Point]],
/** Every MultiPoint Feature in this Layer. */
multiPoints: Seq[MVTFeature[MultiPoint]],
/** Every Line Feature in this Layer. */
lines: Seq[MVTFeature[LineString]],
/** Every MultiLine Feature in this Layer. */
multiLines: Seq[MVTFeature[MultiLineString]],
/** Every Polygon Feature in this Layer. */
polygons: Seq[MVTFeature[Polygon]],
/** Every MultiPolygon Feature in this Layer. */
multiPolygons: Seq[MVTFeature[MultiPolygon]]
)

object MVTFeatures {
implicit val monoidMVTFeatures: Monoid[MVTFeatures] = new Monoid[MVTFeatures] {
def empty: MVTFeatures = MVTFeatures(Nil, Nil, Nil, Nil, Nil, Nil)

def combine(x: MVTFeatures, y: MVTFeatures): MVTFeatures = MVTFeatures(
x.points ++ y.points,
x.multiPoints ++ y.multiPoints,
x.lines ++ y.lines,
x.multiLines ++ y.multiLines,
x.polygons ++ y.polygons,
x.multiPolygons ++ y.multiPolygons
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ class ProjectionSpec extends AnyFunSpec {
tileWidth = 128,
version = 2,
tileExtent = tileExtent,
points = Seq(f),
multiPoints = Seq.empty,
lines = Seq.empty,
multiLines = Seq.empty,
polygons = Seq.empty,
multiPolygons = Seq.empty
MVTFeatures(
points = Seq(f),
multiPoints = Seq.empty,
lines = Seq.empty,
multiLines = Seq.empty,
polygons = Seq.empty,
multiPolygons = Seq.empty
)
)

val vt = VectorTile(Map("test" -> layer), tileExtent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ProtobufTileSpec extends AnyFunSpec with Matchers {
val layerId = "x"
val mvtFeature = MVTFeature(Some(1), Point(10, 10), Map.empty)
val layer = StrictLayer(layerId, 4096, 2, tileExtent,
Seq(mvtFeature), Seq(), Seq(), Seq(), Seq(), Seq())
MVTFeatures(Seq(mvtFeature), Nil, Nil, Nil, Nil, Nil))
val tile = VectorTile(Map(layerId -> layer), tileExtent)
val tile2 = VectorTile.fromBytes(tile.toBytes, tileExtent)
val tileId = tile.layers(layerId).points.head.id
Expand All @@ -62,7 +62,7 @@ class ProtobufTileSpec extends AnyFunSpec with Matchers {
"population" -> VInt64(6)
))
val layer = StrictLayer(layerId, 4096, 2, tileExtent,
Seq(mvtFeature), Seq(), Seq(), Seq(), Seq(), Seq())
MVTFeatures(Seq(mvtFeature), Nil, Nil, Nil, Nil, Nil))
val tile = VectorTile(Map(layerId -> layer), tileExtent)
val tile2 = VectorTile.fromBytes(tile.toBytes, tileExtent)
val tileId = tile.layers(layerId).points.head.data.toList.foreach {
Expand Down

0 comments on commit 431e8a6

Please sign in to comment.