Last active
April 7, 2017 20:19
-
-
Save jiayuasu/667c466f313dd4f2fc1b to your computer and use it in GitHub Desktop.
Use Choropleth Map to Visualize Spatial Join Query (GeoSpark + Babylon)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*---------------------------- Step 0: Create GeoSpark Spatial RDDs ----------------------------*/ | |
PointRDD spatialRDD = new PointRDD(sparkContext, PointInputLocation, PointOffset, FileDataSplitter.CSV, false, PointNumPartitions, StorageLevel.MEMORY_ONLY()); | |
PolygonRDD queryRDD = new PolygonRDD(sparkContext, PolygonInputLocation, FileDataSplitter.CSV, false, PolygonNumPartitions, StorageLevel.MEMORY_ONLY()); | |
/*---------------------------- Step 1: Issue GeoSpark Spatial Join Query with Index ----------------------------*/ | |
spatialRDD.spatialPartitioning(GridType.RTREE); | |
queryRDD.spatialPartitioning(spatialRDD.grids); | |
spatialRDD.buildIndex(IndexType.RTREE,true); | |
JavaPairRDD<Polygon,Long> joinResult = JoinQuery.SpatialJoinQueryCountByKey(spatialRDD,queryRDD,true, true); | |
/*---------------------------- Step 2: Create Babylon Choropleth Map using Twitter dataset ----------------------------*/ | |
ChoroplethMap visualizationOperator = new ChoroplethMap(1000,600,USMainLandBoundary,false); | |
visualizationOperator.CustomizeColor(255, 255, 255, 255, Color.RED, true); | |
visualizationOperator.Visualize(sparkContext, joinResult); | |
/*---------------------------- Step 3: Create Babylon Scatteer Plot using USA county boundaries ----------------------------*/ | |
ScatterPlot frontImage = new ScatterPlot(1000,600,USMainLandBoundary,false); | |
frontImage.CustomizeColor(0, 0, 0, 255, Color.GREEN, true); | |
frontImage.Visualize(sparkContext, queryRDD); | |
/*---------------------------- Step 4: Use Babylon Overlay Operator: Choropleth Map (back) and Scatter Plot (front) ----------------------------*/ | |
OverlayOperator overlayOperator = new OverlayOperator(visualizationOperator.pixelImage); | |
overlayOperator.JoinImage(frontImage.pixelImage); | |
/*---------------------------- Step 5: Generate final image ----------------------------*/ | |
NativeJavaImageGenerator imageGenerator = new NativeJavaImageGenerator(); | |
imageGenerator.SaveAsFile(overlayOperator.backImage, outputPath, ImageType.PNG); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment