Skip to content

Commit b6c1ce0

Browse files
authored
Merge pull request #408 from s22s/fix/407
Added forced truncation of WKT types in Markdown/HTML rendering.
2 parents 45ab397 + 4c398bb commit b6c1ce0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

core/src/main/scala/org/locationtech/rasterframes/util/DataFrameRenderers.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ package org.locationtech.rasterframes.util
2424
import geotrellis.raster.render.ColorRamps
2525
import org.apache.spark.sql.Dataset
2626
import org.apache.spark.sql.functions.{base64, concat, concat_ws, length, lit, substring, when}
27+
import org.apache.spark.sql.jts.JTSTypes
2728
import org.apache.spark.sql.types.{StringType, StructField}
2829
import org.locationtech.rasterframes.expressions.DynamicExtractors
2930
import org.locationtech.rasterframes.{rfConfig, rf_render_png, rf_resample}
31+
import org.apache.spark.sql.rf.WithTypeConformity
3032

3133
/**
32-
* DataFrame extensiosn for rendering sample content in a number of ways
34+
* DataFrame extension for rendering sample content in a number of ways
3335
*/
3436
trait DataFrameRenderers {
3537
private val truncateWidth = rfConfig.getInt("max-truncate-row-element-length")
@@ -47,8 +49,9 @@ trait DataFrameRenderers {
4749
lit("\"></img>")
4850
)
4951
else {
52+
val isGeom = WithTypeConformity(c.dataType).conformsTo(JTSTypes.GeometryTypeInstance)
5053
val str = resolved.cast(StringType)
51-
if (truncate)
54+
if (truncate || isGeom)
5255
when(length(str) > lit(truncateWidth),
5356
concat(substring(str, 1, truncateWidth), lit("..."))
5457
)

core/src/test/scala/org/locationtech/rasterframes/ExtensionMethodSpec.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import scala.xml.parsing.XhtmlParser
3939
class ExtensionMethodSpec extends TestEnvironment with TestData with SubdivideSupport {
4040
lazy val rf = sampleTileLayerRDD.toLayer
4141

42-
describe("DataFrame exention methods") {
42+
describe("DataFrame extension methods") {
4343
it("should maintain original type") {
4444
val df = rf.withPrefixedColumnNames("_foo_")
4545
"val rf2: RasterFrameLayer = df" should compile
@@ -49,7 +49,7 @@ class ExtensionMethodSpec extends TestEnvironment with TestData with SubdivideSu
4949
"val Some(col) = df.spatialKeyColumn" should compile
5050
}
5151
}
52-
describe("RasterFrameLayer exention methods") {
52+
describe("RasterFrameLayer extension methods") {
5353
it("should provide spatial key column") {
5454
noException should be thrownBy {
5555
rf.spatialKeyColumn
@@ -124,6 +124,10 @@ class ExtensionMethodSpec extends TestEnvironment with TestData with SubdivideSu
124124

125125
val md3 = rf.toMarkdown(truncate=true, renderTiles = false)
126126
md3 shouldNot include("<img")
127+
128+
// Should truncate JTS types even when we don't ask for it.
129+
val md4 = rf.withGeometry().select("geometry").toMarkdown(truncate = false)
130+
md4 should include ("...")
127131
}
128132

129133
it("should render HTML") {

0 commit comments

Comments
 (0)