Reputation: 1
I want to generate an image to show statistics on crime situations in different areas of a city,I chose to use zip code to represent different areas and use PBSM spatial join with Contains Predicate.
However I ran into some other problems, I tried to use countByKey to create zip code-crime pair, then I found that this is not an RDD, thus can't produce the spatial file, so I used reduceByKey, then created an RDD[(String, int)]. Now, I'm struggling with how to convert RDD[(String, int)] to RDD[IFeature] so that I can produce a shapefile and visualize it. I tried to use Feature.append() and Feature.create(), but I can't use it well without some documentation. I'm not sure if I'm in the right direction.
try {
// Import Beast features
import edu.ucr.cs.bdlab.beast._
// TODO Insert your code here
val zipCodeBound = sparkContext.shapefile("/Users/galacy/beast-start-up/beast-project/src/Boundaries - ZIP Codes.zip")
val crimePoint = sparkContext.readCSVPoint("/Users/galacy/beast-start-up/beast-project/src/Crimes_-_2001_to_Present.csv", "Longitude", "Latitude",',', skipHeader = true)
val sjResult = zipCodeBound.spatialJoin(crimePoint, ESJPredicate.Contains, ESJDistributedAlgorithm.PBSM)
val mapRes = sjResult.map(f => (f._1.getAs[String]("zip"), 1)).reduceByKey(_ + _)
val finalRes = mapRes.map(f => (Feature.create()))
}
Upvotes: 0
Views: 11