Last active
January 15, 2017 07:01
-
-
Save jiayuasu/d66a7bc13c5e63b2cf8bd11cdd4d83bb to your computer and use it in GitHub Desktop.
Babylon scala example
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
import com.vividsolutions.jts.geom.Envelope; | |
import java.awt.Color; | |
import org.datasyslab.geospark.spatialRDD.LineStringRDD; | |
import org.datasyslab.geospark.spatialRDD.PointRDD; | |
import org.datasyslab.geospark.spatialRDD.PolygonRDD; | |
import org.datasyslab.geospark.spatialRDD.RectangleRDD; | |
import org.datasyslab.geospark.enums.FileDataSplitter; | |
import org.datasyslab.geospark.enums.GridType; | |
import org.datasyslab.geospark.enums.IndexType; | |
import org.datasyslab.geospark.spatialOperator.JoinQuery; | |
import org.datasyslab.geospark.visualizationOperator.ScatterPlot; | |
import org.datasyslab.geospark.visualizationOperator.HeatMap; | |
import org.datasyslab.geospark.visualizationOperator.ChoroplethMap; | |
import org.datasyslab.geospark.visualizationOperator.UserSuppliedRectangleMapper; | |
val USMainLandBoundary = new Envelope(-126.790180,-64.630926,24.863836,50.000); | |
val userSuppliedRectangleMapper = new UserSuppliedRectangleMapper(); | |
// Scatter plot | |
val county = new RectangleRDD(sc, "file:///Users/jiayu/VM_Share/resources/county.csv", 4, userSuppliedRectangleMapper); | |
val scatterPlot = new ScatterPlot(800,500,USMainLandBoundary,false); | |
scatterPlot.CustomizeColor(0, 0, 0, 255, Color.GREEN, true); | |
scatterPlot.Visualize(sc, county, "./babylon/currentEffect.png"); | |
//Heat map | |
val zipcodearea = new RectangleRDD(sc, "file:///Users/jiayu/VM_Share/resources/zcta510.csv", 0, FileDataSplitter.CSV, false, 4); | |
val heatMap = new HeatMap(800,500,USMainLandBoundary,false,5); | |
heatMap.Visualize(sc, zipcodearea, "./babylon/currentEffect.png"); | |
heatMap.JoinImages(heatMap.pixelImage, scatterPlot.pixelImage, "./babylon/currentEffect.png"); | |
//Choropleth map | |
//First, do spatial join | |
val landmark = new PointRDD(sc, "file:///Users/jiayu/VM_Share/resources/arealm.csv", 0, FileDataSplitter.CSV, false, 4); | |
landmark.spatialPartitioning(GridType.RTREE); | |
county.spatialPartitioning(landmark.grids); | |
landmark.buildIndex(IndexType.RTREE,true); | |
val joinResult = JoinQuery.SpatialJoinQueryCountByKey(landmark,county,true); | |
joinResult.count(); | |
//Second, do the map | |
val choroplethMap = new ChoroplethMap(800,500,USMainLandBoundary,false); | |
choroplethMap.CustomizeColor(255, 255, 255, 255, Color.RED, true); | |
choroplethMap.Visualize(sc, joinResult, "./babylon/currentEffect.png"); | |
choroplethMap.JoinImages(choroplethMap.pixelImage, scatterPlot.pixelImage, "./babylon/currentEffect.png"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment