Skip to content

Commit

Permalink
Merge pull request #408 from s22s/fix/407
Browse files Browse the repository at this point in the history
Added forced truncation of WKT types in Markdown/HTML rendering.
  • Loading branch information
metasim authored Nov 8, 2019
2 parents 45ab397 + 4c398bb commit b6c1ce0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ package org.locationtech.rasterframes.util
import geotrellis.raster.render.ColorRamps
import org.apache.spark.sql.Dataset
import org.apache.spark.sql.functions.{base64, concat, concat_ws, length, lit, substring, when}
import org.apache.spark.sql.jts.JTSTypes
import org.apache.spark.sql.types.{StringType, StructField}
import org.locationtech.rasterframes.expressions.DynamicExtractors
import org.locationtech.rasterframes.{rfConfig, rf_render_png, rf_resample}
import org.apache.spark.sql.rf.WithTypeConformity

/**
* DataFrame extensiosn for rendering sample content in a number of ways
* DataFrame extension for rendering sample content in a number of ways
*/
trait DataFrameRenderers {
private val truncateWidth = rfConfig.getInt("max-truncate-row-element-length")
Expand All @@ -47,8 +49,9 @@ trait DataFrameRenderers {
lit("\"></img>")
)
else {
val isGeom = WithTypeConformity(c.dataType).conformsTo(JTSTypes.GeometryTypeInstance)
val str = resolved.cast(StringType)
if (truncate)
if (truncate || isGeom)
when(length(str) > lit(truncateWidth),
concat(substring(str, 1, truncateWidth), lit("..."))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import scala.xml.parsing.XhtmlParser
class ExtensionMethodSpec extends TestEnvironment with TestData with SubdivideSupport {
lazy val rf = sampleTileLayerRDD.toLayer

describe("DataFrame exention methods") {
describe("DataFrame extension methods") {
it("should maintain original type") {
val df = rf.withPrefixedColumnNames("_foo_")
"val rf2: RasterFrameLayer = df" should compile
Expand All @@ -49,7 +49,7 @@ class ExtensionMethodSpec extends TestEnvironment with TestData with SubdivideSu
"val Some(col) = df.spatialKeyColumn" should compile
}
}
describe("RasterFrameLayer exention methods") {
describe("RasterFrameLayer extension methods") {
it("should provide spatial key column") {
noException should be thrownBy {
rf.spatialKeyColumn
Expand Down Expand Up @@ -124,6 +124,10 @@ class ExtensionMethodSpec extends TestEnvironment with TestData with SubdivideSu

val md3 = rf.toMarkdown(truncate=true, renderTiles = false)
md3 shouldNot include("<img")

// Should truncate JTS types even when we don't ask for it.
val md4 = rf.withGeometry().select("geometry").toMarkdown(truncate = false)
md4 should include ("...")
}

it("should render HTML") {
Expand Down

0 comments on commit b6c1ce0

Please sign in to comment.