0

I am trying to map the attached h3index dataset in kepler.gl. I've used the following scala function to generate these at a resolution index of 8.

val geoToH3 = udf{ (latitude: Double, longitude: Double, resolution: Int) => 
  H3.instance.geoToH3(latitude, longitude, resolution) 

https://drive.google.com/file/d/1Wffsi1GoRGox8r3s_HYWRqFTtKKP_s8B/view?usp=sharing

When I use h3 in the terminal for the same latitude-longitude values, it gives me a different hex_index:

Example:

./bin/geoToH3 --resolution 8 --latitude 46.81355 --longitude -71.22968

which return 882bac516bfffff

Are both of these hex_indexes correct?

Also, when I try to map either in kepler.gl, I'm not able to see anything.

2 Answers2

0

An H3 index is a 64-bit integer, which is generally encoded as a hexidecimal string. It looks like your Scala code is outputting the integer in base-10 format instead, which may be fine in memory (for languages that support 64-bit integers) but generally isn't used as a data interchange format. Javascript, in particular, can't support 64-bit integers, and requires the hexidecimal string.

So the CLI output, 882bac516bfffff, is correct. You may need to update your Scala code to print its output in hexidecimal.

As for Kepler, are you using the H3 layer? You'll need to specify the H3 layer and the column in your data that contains H3 indexes.

nrabinowitz
  • 55,314
  • 10
  • 149
  • 165
  • Thanks a lot. I converted the h3 indexes to hexadecimal and everything worked great, even the kepler.gl part. I'm not sure why it was not working earlier when I tried replacing the hexadecimal values manually. Must be an error at my end. – Dhruv Chaudhary Jan 23 '20 at 02:24
0

I'm sharing my final code below in case someone might find it useful. This was executed in a databricks notebook.

%scala
import org.locationtech.jts.geom._
import org.locationtech.geomesa.spark.jts._

import org.apache.spark.sql.types._
import org.apache.spark.sql.functions._
import spark.implicits._

spark.withJTS

object H3 extends Serializable {   val instance = H3Core.newInstance()
}

val geoToH3 = udf{ (latitude: Double, longitude: Double, resolution:
Int) =>    H3.instance.geoToH3(latitude, longitude, resolution)  }

val res = 8 //the resolution of the H3 index, 0.461354684 km edge length
val dfH3 = df_scala.withColumn(
  "hex_id",
  hex(geoToH3(col("latitude"), col("longitude"), lit(res)))
)