Skip to content

Commit 431e8a6

Browse files
authored
Separate monoidal part of strict layers (#3330)
* separate monoidal part of strict layers Signed-off-by: James Santucci <james.santucci@gmail.com>
1 parent 2f8348a commit 431e8a6

File tree

5 files changed

+117
-21
lines changed

5 files changed

+117
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Remove explicit unused Scaffeine dependency from projects [#3314](https://github.com/locationtech/geotrellis/pull/3314)
1515
- Remove an excessive close after the abort call in S3RangeReader [#3324](https://github.com/locationtech/geotrellis/pull/3324)
1616
- Fix sigmoidal contrast calculation [#3328](https://github.com/locationtech/geotrellis/pull/3328)
17+
- Separated monoidal component of `vectortile.StrictLayer` [#3330](https://github.com/locationtech/geotrellis/pull/3330)
1718

1819
## [3.5.1] - 2020-11-23
1920

vectortile/src/main/scala/geotrellis/vectortile/Layer.scala

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,40 @@ ${sortedMeta.map({ case (k,v) => s" ${k}: ${v}"}).mkString("\n")}
215215
tileWidth: Int,
216216
version: Int,
217217
tileExtent: Extent,
218-
points: Seq[MVTFeature[Point]],
219-
multiPoints: Seq[MVTFeature[MultiPoint]],
220-
lines: Seq[MVTFeature[LineString]],
221-
multiLines: Seq[MVTFeature[MultiLineString]],
222-
polygons: Seq[MVTFeature[Polygon]],
223-
multiPolygons: Seq[MVTFeature[MultiPolygon]]
224-
) extends Layer
218+
mvtFeatures: MVTFeatures
219+
) extends Layer {
220+
def points = mvtFeatures.points
221+
def multiPoints = mvtFeatures.multiPoints
222+
def lines = mvtFeatures.lines
223+
def multiLines = mvtFeatures.multiLines
224+
def polygons = mvtFeatures.polygons
225+
def multiPolygons = mvtFeatures.multiPolygons
226+
}
227+
228+
object StrictLayer {
229+
def apply(
230+
name: String,
231+
tileWidth: Int,
232+
version: Int,
233+
tileExtent: Extent,
234+
points: Seq[MVTFeature[Point]],
235+
multiPoints: Seq[MVTFeature[MultiPoint]],
236+
lines: Seq[MVTFeature[LineString]],
237+
multiLines: Seq[MVTFeature[MultiLineString]],
238+
polygons: Seq[MVTFeature[Polygon]],
239+
multiPolygons: Seq[MVTFeature[MultiPolygon]]
240+
): StrictLayer = StrictLayer(
241+
name, tileWidth, version, tileExtent,
242+
MVTFeatures(
243+
points,
244+
multiPoints,
245+
lines,
246+
multiLines,
247+
polygons,
248+
multiPolygons
249+
)
250+
)
251+
}
225252

226253
/**
227254
* A [[Layer]] decoded from Protobuf data. All of its Features are decoded
@@ -374,12 +401,14 @@ ${sortedMeta.map({ case (k,v) => s" ${k}: ${v}"}).mkString("\n")}
374401
tileWidth,
375402
version,
376403
tileExtent,
377-
points,
378-
multiPoints,
379-
lines,
380-
multiLines,
381-
polygons,
382-
multiPolygons
404+
MVTFeatures(
405+
points,
406+
multiPoints,
407+
lines,
408+
multiLines,
409+
polygons,
410+
multiPolygons
411+
)
383412
)
384413
}
385414
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2019 Azavea
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package geotrellis.vectortile
18+
19+
import geotrellis.vector.{
20+
Point,
21+
MultiPoint,
22+
LineString,
23+
MultiLineString,
24+
Polygon,
25+
MultiPolygon
26+
}
27+
import cats.Monoid
28+
29+
/** Container case class for collections of [[MVTFeature]]s
30+
*
31+
* This is separated for ease of use when reading geometries from
32+
* places. With the `Monoid` instance for `MVTFeatures`, each geometry
33+
* can be lifted into a seq in the relevant attribute, and then
34+
* the separate `MVTFeatures` case classes can all be combined.
35+
*/
36+
final case class MVTFeatures(
37+
/** Every Point Feature in this Layer. */
38+
points: Seq[MVTFeature[Point]],
39+
/** Every MultiPoint Feature in this Layer. */
40+
multiPoints: Seq[MVTFeature[MultiPoint]],
41+
/** Every Line Feature in this Layer. */
42+
lines: Seq[MVTFeature[LineString]],
43+
/** Every MultiLine Feature in this Layer. */
44+
multiLines: Seq[MVTFeature[MultiLineString]],
45+
/** Every Polygon Feature in this Layer. */
46+
polygons: Seq[MVTFeature[Polygon]],
47+
/** Every MultiPolygon Feature in this Layer. */
48+
multiPolygons: Seq[MVTFeature[MultiPolygon]]
49+
)
50+
51+
object MVTFeatures {
52+
implicit val monoidMVTFeatures: Monoid[MVTFeatures] = new Monoid[MVTFeatures] {
53+
def empty: MVTFeatures = MVTFeatures(Nil, Nil, Nil, Nil, Nil, Nil)
54+
55+
def combine(x: MVTFeatures, y: MVTFeatures): MVTFeatures = MVTFeatures(
56+
x.points ++ y.points,
57+
x.multiPoints ++ y.multiPoints,
58+
x.lines ++ y.lines,
59+
x.multiLines ++ y.multiLines,
60+
x.polygons ++ y.polygons,
61+
x.multiPolygons ++ y.multiPolygons
62+
)
63+
}
64+
}

vectortile/src/test/scala/geotrellis/vectortile/ProjectionSpec.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ class ProjectionSpec extends AnyFunSpec {
3535
tileWidth = 128,
3636
version = 2,
3737
tileExtent = tileExtent,
38-
points = Seq(f),
39-
multiPoints = Seq.empty,
40-
lines = Seq.empty,
41-
multiLines = Seq.empty,
42-
polygons = Seq.empty,
43-
multiPolygons = Seq.empty
38+
MVTFeatures(
39+
points = Seq(f),
40+
multiPoints = Seq.empty,
41+
lines = Seq.empty,
42+
multiLines = Seq.empty,
43+
polygons = Seq.empty,
44+
multiPolygons = Seq.empty
45+
)
4446
)
4547

4648
val vt = VectorTile(Map("test" -> layer), tileExtent)

vectortile/src/test/scala/geotrellis/vectortile/ProtobufTileSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ProtobufTileSpec extends AnyFunSpec with Matchers {
4545
val layerId = "x"
4646
val mvtFeature = MVTFeature(Some(1), Point(10, 10), Map.empty)
4747
val layer = StrictLayer(layerId, 4096, 2, tileExtent,
48-
Seq(mvtFeature), Seq(), Seq(), Seq(), Seq(), Seq())
48+
MVTFeatures(Seq(mvtFeature), Nil, Nil, Nil, Nil, Nil))
4949
val tile = VectorTile(Map(layerId -> layer), tileExtent)
5050
val tile2 = VectorTile.fromBytes(tile.toBytes, tileExtent)
5151
val tileId = tile.layers(layerId).points.head.id
@@ -62,7 +62,7 @@ class ProtobufTileSpec extends AnyFunSpec with Matchers {
6262
"population" -> VInt64(6)
6363
))
6464
val layer = StrictLayer(layerId, 4096, 2, tileExtent,
65-
Seq(mvtFeature), Seq(), Seq(), Seq(), Seq(), Seq())
65+
MVTFeatures(Seq(mvtFeature), Nil, Nil, Nil, Nil, Nil))
6666
val tile = VectorTile(Map(layerId -> layer), tileExtent)
6767
val tile2 = VectorTile.fromBytes(tile.toBytes, tileExtent)
6868
val tileId = tile.layers(layerId).points.head.data.toList.foreach {

0 commit comments

Comments
 (0)