Skip to content

Commit d9bf501

Browse files
elahrvivazanthonyccri
authored andcommitted
GEOMESA-428 checking for SRS when determining axis order in binary output format
* adding default dtg from schema if not specified in request * ensuring 24 byte encodings all are 24 bytes
1 parent 65eaf58 commit d9bf501

File tree

4 files changed

+242
-50
lines changed

4 files changed

+242
-50
lines changed

geomesa-filter/src/main/scala/org/locationtech/geomesa/filter/function/Convert2ViewerFunction.scala

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Convert2ViewerFunction
4141
val id = getExpression(0).evaluate(obj).asInstanceOf[String]
4242
val geom = getExpression(1).evaluate(obj).asInstanceOf[Point]
4343
val dtg = dtg2Long(getExpression(2).evaluate(obj))
44-
Base64.encodeBytes(encode(EncodedValues(geom.getY.toFloat, geom.getX.toFloat, dtg, None, Some(id))))
44+
Base64.encodeBytes(encode(ExtendedValues(geom.getY.toFloat, geom.getX.toFloat, dtg, None, Some(id))))
4545
}
4646

4747
private def dtg2Long(d: Any): Long = d match {
@@ -69,15 +69,33 @@ object Convert2ViewerFunction {
6969
* @param values
7070
* @return
7171
*/
72-
def encode(values: EncodedValues): Array[Byte] = {
73-
val numBytes = if (values.label.isDefined) 24 else 16
74-
val buf = ByteBuffer.allocate(numBytes).order(ByteOrder.LITTLE_ENDIAN)
75-
putOption(buf, values.trackId, 4)
76-
buf.putInt((values.dtg / 1000).toInt)
77-
buf.putFloat(values.lat)
78-
buf.putFloat(values.lon)
79-
values.label.foreach(_ => putOption(buf, values.label, 8))
80-
buf.array()
72+
def encode(values: EncodedValues): Array[Byte] =
73+
values match {
74+
case BasicValues(lat, lon, dtg, trackId) =>
75+
val buf = ByteBuffer.allocate(16).order(ByteOrder.LITTLE_ENDIAN)
76+
put(buf, lat, lon, dtg, trackId)
77+
buf.array()
78+
case ExtendedValues(lat, lon, dtg, trackId, label) =>
79+
val buf = ByteBuffer.allocate(24).order(ByteOrder.LITTLE_ENDIAN)
80+
put(buf, lat, lon, dtg, trackId)
81+
putOption(buf, label, 8)
82+
buf.array()
83+
}
84+
85+
/**
86+
* Fills in the basic values
87+
*
88+
* @param buffer
89+
* @param lat
90+
* @param lon
91+
* @param dtg
92+
* @param trackId
93+
*/
94+
private def put(buffer: ByteBuffer, lat: Float, lon: Float, dtg: Long, trackId: Option[String]): Unit = {
95+
putOption(buffer, trackId, 4)
96+
buffer.putInt((dtg / 1000).toInt)
97+
buffer.putFloat(lat)
98+
buffer.putFloat(lon)
8199
}
82100

83101
/**
@@ -131,13 +149,27 @@ object Convert2ViewerFunction {
131149
val time = buf.getInt * 1000L
132150
val lat = buf.getFloat
133151
val lon = buf.getFloat
134-
val label = if (encoded.length > 16) getOption(buf, 8) else None
135-
EncodedValues(lat, lon, time, trackId, label)
152+
if (encoded.length > 16) {
153+
val label = getOption(buf, 8)
154+
ExtendedValues(lat, lon, time, trackId, label)
155+
} else {
156+
BasicValues(lat, lon, time, trackId)
157+
}
136158
}
137159
}
138160

139-
case class EncodedValues(lat: Float,
140-
lon: Float,
141-
dtg: Long,
142-
trackId: Option[String] = None,
143-
label: Option[String] = None)
161+
sealed trait EncodedValues {
162+
def lat: Float
163+
def lon: Float
164+
def dtg: Long
165+
def trackId: Option[String]
166+
}
167+
168+
case class BasicValues(lat: Float, lon: Float, dtg: Long, trackId: Option[String] = None)
169+
extends EncodedValues
170+
171+
case class ExtendedValues(lat: Float,
172+
lon: Float,
173+
dtg: Long,
174+
trackId: Option[String] = None,
175+
label: Option[String] = None) extends EncodedValues

geomesa-filter/src/test/scala/org/locationtech/geomesa/filter/function/Convert2ViewerFunctionTest.scala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ class Convert2ViewerFunctionTest extends Specification {
2727
"Convert2ViewerFunction" should {
2828

2929
"encode and decode simple attributes" in {
30-
val initial = EncodedValues(45.0f, 49.0f,
31-
System.currentTimeMillis(),
32-
Some("1200"))
30+
val initial = BasicValues(45.0f, 49.0f, System.currentTimeMillis(), Some("1200"))
3331
val encoded = Convert2ViewerFunction.encode(initial)
3432
encoded must haveLength(16)
3533
val decoded = Convert2ViewerFunction.decode(encoded)
@@ -40,9 +38,7 @@ class Convert2ViewerFunctionTest extends Specification {
4038
}
4139

4240
"encode and decode optional simple attributes" in {
43-
val initial = EncodedValues(45.0f, 49.0f,
44-
System.currentTimeMillis(),
45-
None)
41+
val initial = BasicValues(45.0f, 49.0f, System.currentTimeMillis(), None)
4642
val encoded = Convert2ViewerFunction.encode(initial)
4743
encoded must haveLength(16)
4844
val decoded = Convert2ViewerFunction.decode(encoded)
@@ -53,32 +49,36 @@ class Convert2ViewerFunctionTest extends Specification {
5349
}
5450

5551
"encode and decode extended attributes" in {
56-
val initial = EncodedValues(45.0f, 49.0f,
57-
System.currentTimeMillis(),
58-
Some("1200"),
59-
Some("label"))
52+
val initial = ExtendedValues(45.0f,
53+
49.0f,
54+
System.currentTimeMillis(),
55+
Some("1200"),
56+
Some("label"))
6057
val encoded = Convert2ViewerFunction.encode(initial)
6158
encoded must haveLength(24)
6259
val decoded = Convert2ViewerFunction.decode(encoded)
60+
decoded must beAnInstanceOf[ExtendedValues]
6361
decoded.lat mustEqual(initial.lat)
6462
decoded.lon mustEqual(initial.lon)
6563
Math.abs(decoded.dtg - initial.dtg) must beLessThan(1000L) // dates get truncated to nearest second
6664
decoded.trackId mustEqual(initial.trackId)
67-
decoded.label mustEqual(initial.label)
65+
decoded.asInstanceOf[ExtendedValues].label mustEqual(initial.label)
6866
}
6967

7068
"truncate long labels" in {
71-
val initial = EncodedValues(45.0f, 49.0f,
72-
System.currentTimeMillis(),
73-
Some("track that is too long"),
74-
Some("label that is too long"))
69+
val initial = ExtendedValues(45.0f,
70+
49.0f,
71+
System.currentTimeMillis(),
72+
Some("track that is too long"),
73+
Some("label that is too long"))
7574
val encoded = Convert2ViewerFunction.encode(initial)
7675
val decoded = Convert2ViewerFunction.decode(encoded)
76+
decoded must beAnInstanceOf[ExtendedValues]
7777
decoded.lat mustEqual(initial.lat)
7878
decoded.lon mustEqual(initial.lon)
7979
Math.abs(decoded.dtg - initial.dtg) must beLessThan(1000L) // dates get truncated to nearest second
8080
decoded.trackId.get mustEqual(initial.trackId.get.substring(0, 4))
81-
decoded.label.get mustEqual(initial.label.get.substring(0, 8))
81+
decoded.asInstanceOf[ExtendedValues].label.get mustEqual(initial.label.get.substring(0, 8))
8282
}
8383
}
8484
}

geomesa-plugin/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@
128128
<artifactId>gt-process-feature</artifactId>
129129
<scope>provided</scope>
130130
</dependency>
131+
<dependency>
132+
<groupId>org.geotools.ogc</groupId>
133+
<artifactId>net.opengis.wfs</artifactId>
134+
<version>${gt.version}</version>
135+
<scope>provided</scope>
136+
</dependency>
131137
<dependency>
132138
<groupId>org.apache.accumulo</groupId>
133139
<artifactId>accumulo-core</artifactId>

0 commit comments

Comments
 (0)