-
Notifications
You must be signed in to change notification settings - Fork 362
/
ProtobufGeom.scala
67 lines (62 loc) · 2.71 KB
/
ProtobufGeom.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* 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.internal
import geotrellis.vector.{ Geometry, Point }
// --- //
/** An isomorphism for any GeoTrellis geometry type that can convert
* between a collection of Command Integers. As of version 2.1 of
* the VectorTile spec, there is no explicit difference between single
* and multi geometries. When there eventually is, this trait will have to be
* split to provide separate instances for both the single and multi forms.
*
* Since we assume that all VectorTiles implicitely exist in some CRS,
* we ask for the top-left corner of the current Tile's extent, as well
* as its resolution in order to perform the transformation into CRS space.
*
* Instances of this trait can be found in the package object.
*
* Usage:
* {{{
* val topLeft: Point = ...
* val resolution: Double = ...
*
* implicitly[ProtobufGeom[Point, MultiPoint]].fromCommands(Command.commands(Seq(9,2,2)), topLeft, resolution)
* }}}
*/
private[vectortile] trait ProtobufGeom[G1 <: Geometry, G2 <: Geometry] extends Serializable {
/**
* Decode a sequence of VectorTile [[Command]]s into a GeoTrellis
* Geometry. Due to the reasons stated above, this may be either
* the single or the ''Multi'' variety of the Geometry.
*
* This forms an isomorphism with [[toCommands]].
*
* @param cmds The Commands.
* @param topLeft The location in the current CRS of the top-left corner of this Tile.
* @param resolution How much of the CRS's units are covered by a single VT grid coordinate..
*/
def fromCommands(cmds: Seq[Command], topLeft: Point, resolution: Double): Either[G1, G2]
/**
* Encode a GeoTrellis Geometry into a sequence of VectorTile [[Command]]s.
*
* This forms an isomorphism with [[fromCommands]].
*
* @param g A GeoTrellis Geometry, either a `Left(Single)` or a `Right(Multi)`.
* @param topLeft The location in the current CRS of the top-left corner of this Tile.
* @param resolution How much of the CRS's units are covered by a single VT grid coordinate..
*/
def toCommands(g: Either[G1, G2], topLeft: Point, resolution: Double): Seq[Command]
}