GeoSpark入门-可视化
GeoSpark是一种用于大规模空间数据处理的集群计算。 GeoSpark通过一组out-of-the-box空间弹性分布式数据集( SRDDs ) 扩展 Apache Spark,它可以跨机器高效地加载。处理、分析、展示大规模空间数据。
准备工作
- Windows 和 spark
- IDEA
- GeoSpark支持Java、Scala两种,本次开发语言选择Java。
GeoSpark
参考https://github.com/jiayuasu/GeoSparkTemplateProject,下载项目到本地。
GeoSpark-Viz Java项目构建
cd ./geospark-viz/java
mvn clean install
由于项目中的数据生成图片不太满意,将map.shp数据解析成polygon.csv,修改下java代码
ConfFile= new FileInputStream(resourcePath+"babylon.polygon2.properties");
通过buildChoroplethMap统计面内得点数生成分级统计图,修改buildScatterPlot和
buildHeatMap输入数据为点数据生成散点图和热力图。
完整代码:
package example;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Polygon;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.serializer.KryoSerializer;
import org.apache.spark.storage.StorageLevel;
import org.datasyslab.geospark.enums.FileDataSplitter;
import org.datasyslab.geospark.enums.GridType;
import org.datasyslab.geospark.enums.IndexType;
import org.datasyslab.geospark.formatMapper.EarthdataHDFPointMapper;
import org.datasyslab.geospark.spatialOperator.JoinQuery;
import org.datasyslab.geospark.spatialRDD.PointRDD;
import org.datasyslab.geospark.spatialRDD.PolygonRDD;
import org.datasyslab.geospark.spatialRDD.RectangleRDD;
import org.datasyslab.geosparkviz.core.ImageGenerator;
import org.datasyslab.geosparkviz.core.ImageStitcher;
import org.datasyslab.geosparkviz.core.RasterOverlayOperator;
import org.datasyslab.geosparkviz.core.Serde.GeoSparkVizKryoRegistrator;
import org.datasyslab.geosparkviz.extension.visualizationEffect.ChoroplethMap;
import org.datasyslab.geosparkviz.extension.visualizationEffect.HeatMap;
import org.datasyslab.geosparkviz.extension.visualizationEffect.ScatterPlot;
import org.datasyslab.geosparkviz.utils.ColorizeOption;
import org.datasyslab.geosparkviz.utils.ImageType;
import java.awt.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
// TODO: Auto-generated Javadoc
/**
* The Class Example.
*/
public class Example2019 {
/** The spark context. */
static JavaSparkContext sparkContext;
/** The prop. */
static Properties prop;
/** The Point input location. */
static String PointInputLocation;
/** The Point offset. */
static Integer PointOffset;
/** The Point splitter. */
static FileDataSplitter PointSplitter;
/** The Point num partitions. */
static Integer PointNumPartitions;
/** The Rectangle input location. */
static String RectangleInputLocation;
/** The Rectangle offset. */
static Integer RectangleOffset;
/** The Rectangle splitter. */
static FileDataSplitter RectangleSplitter;
/** The Rectangle num partitions. */
static Integer RectangleNumPartitions;
/** The Polygon input location. */
static String PolygonInputLocation;
/** The Polygon offset. */
static Integer PolygonOffset;
/** The Polygon splitter. */
static FileDataSplitter PolygonSplitter;
/** The Polygon num partitions. */
static Integer PolygonNumPartitions;
/** The Line string input location. */
static String LineStringInputLocation;
/** The Line string offset. */
static Integer LineStringOffset;
/** The Line string splitter. */
static FileDataSplitter LineStringSplitter;
/** The Line string num partitions. */
static Integer LineStringNumPartitions;
/** The US main land boundary. */
static Envelope USMainLandBoundary;
/** The earthdata input location. */
static String earthdataInputLocation;
/** The earthdata num partitions. */
static Integer earthdataNumPartitions;
/** The HDF increment. */
static int HDFIncrement = 5;
/** The HDF offset. */
static int HDFOffset = 2;
/** The HDF root group name. */
static String HDFRootGroupName = "MOD_Swath_LST";
/** The HDF data variable name. */
static String HDFDataVariableName = "LST";
/** The HDF data variable list. */
static String[] HDFDataVariableList = {"LST","QC","Error_LST","Emis_31","Emis_32"};
/** The HD fswitch XY. */
static boolean HDFswitchXY = true;
/** The url prefix. */
static String urlPrefix = "";
/**
* Builds the scatter plot.
*
* @param outputPath the output path
* @return true, if successful
*/
public static boolean buildScatterPlot(String outputPath)
{
try{
PointRDD spatialRDD = new PointRDD(sparkContext, PointInputLocation, PointOffset, PointSplitter, false, PointNumPartitions, StorageLevel.MEMORY_ONLY());
//PolygonRDD spatialRDD = new PolygonRDD(sparkContext, PolygonInputLocation, PolygonSplitter, false, PolygonNumPartitions, StorageLevel.MEMORY_ONLY());
ScatterPlot visualizationOperator = new ScatterPlot(1000,600,USMainLandBoundary,false);
visualizationOperator.CustomizeColor(255, 255, 255, 255, Color.GREEN, true);
visualizationOperator.Visualize(sparkContext, spatialRDD);
ImageGenerator imageGenerator = new ImageGenerator();
imageGenerator.SaveRasterImageAsLocalFile(visualizationOperator.rasterImage, outputPath, ImageType.PNG);
// visualizationOperator = new ScatterPlot(1000,600,USMainLandBoundary,false,-1,-1,false,true);
// visualizationOperator.CustomizeColor(255, 255, 255, 255, Color.GREEN, true);
// visualizationOperator.Visualize(sparkContext, spatialRDD);
// imageGenerator = new ImageGenerator();
// imageGenerator.SaveVectorImageAsLocalFile(visualizationOperator.vectorImage, outputPath,ImageType.SVG);
//
// visualizationOperator = new ScatterPlot(1000,600,USMainLandBoundary,false,-1,-1,true,true);
// visualizationOperator.CustomizeColor(255, 255, 255, 255, Color.GREEN, true);
// visualizationOperator.Visualize(sparkContext, spatialRDD);
// imageGenerator = new ImageGenerator();
// imageGenerator.SaveVectorImageAsLocalFile(visualizationOperator.distributedVectorImage, outputPath+"-distributed",ImageType.SVG);
//
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
return true;
}
/**
* Builds the heat map.
*
* @param outputPath the output path
* @return true, if successful
*/
public static boolean buildHeatMap(String outputPath)
{
try{
PointRDD spatialRDD = new PointRDD(sparkContext, PointInputLocation, PointOffset, PointSplitter, false, PointNumPartitions, StorageLevel.MEMORY_ONLY());
HeatMap visualizationOperator = new HeatMap(1000,600,USMainLandBoundary,false,5);
visualizationOperator.Visualize(sparkContext, spatialRDD);
ImageGenerator imageGenerator = new ImageGenerator();
imageGenerator.SaveRasterImageAsLocalFile(visualizationOperator.rasterImage, outputPath,ImageType.PNG);
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
return true;
}
/**
* Builds the choropleth map.
*
* @param outputPath the output path
* @return true, if successful
*/
public static boolean buildChoroplethMap(String outputPath)
{
try{
PointRDD spatialRDD = new PointRDD(sparkContext, PointInputLocation, PointOffset, PointSplitter, false, PointNumPartitions, StorageLevel.MEMORY_ONLY());
PolygonRDD queryRDD = new PolygonRDD(sparkContext, PolygonInputLocation, PolygonSplitter, false, PolygonNumPartitions, StorageLevel.MEMORY_ONLY());
spatialRDD.spatialPartitioning(GridType.RTREE);
queryRDD.spatialPartitioning(spatialRDD.grids);
spatialRDD.buildIndex(IndexType.RTREE,true);
JavaPairRDD<Polygon,Long> joinResult = JoinQuery.SpatialJoinQueryCountByKey(spatialRDD,queryRDD,true,false);
long start = System.currentTimeMillis();
ChoroplethMap visualizationOperator = new ChoroplethMap(1000,600,USMainLandBoundary,false);
visualizationOperator.CustomizeColor(255, 255, 255, 255, Color.RED, true);
visualizationOperator.Visualize(sparkContext, joinResult);
ScatterPlot frontImage = new ScatterPlot(1000,600,USMainLandBoundary,false);
frontImage.CustomizeColor(0, 0, 0, 255, Color.GREEN, true);
frontImage.Visualize(sparkContext, queryRDD);
RasterOverlayOperator overlayOperator = new RasterOverlayOperator(visualizationOperator.rasterImage);
overlayOperator.JoinImage(frontImage.rasterImage);
ImageGenerator imageGenerator = new ImageGenerator();
//imageGenerator.SaveRasterImageAsLocalFile(frontImage.rasterImage, outputPath,ImageType.PNG);
imageGenerator.SaveRasterImageAsLocalFile(overlayOperator.backRasterImage, outputPath,ImageType.PNG);
//imageGenerator.SaveRasterImageAsLocalFile(visualizationOperator.distributedRasterImage, outputPath,ImageType.PNG);
//ImageStitcher.stitchImagePartitionsFromLocalFile(outputPath, 1000,600,0,4, 4);
System.out.println("散点图生成完成,共耗时" + (System.currentTimeMillis() - start) + "ms");
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
return true;
}
/**
* Parallel filter render no stitch.
*
* @param outputPath the output path
* @return true, if successful
*/
public static boolean parallelFilterRenderNoStitch(String outputPath)
{
try{
PointRDD spatialRDD = new PointRDD(sparkContext, PointInputLocation, PointOffset, PointSplitter, false, PointNumPartitions, StorageLevel.MEMORY_ONLY());
HeatMap visualizationOperator = new HeatMap(1000,600,USMainLandBoundary,false,2,4,4,true,true);
visualizationOperator.Visualize(sparkContext, spatialRDD);
ImageGenerator imageGenerator = new ImageGenerator();
imageGenerator.SaveRasterImageAsLocalFile(visualizationOperator.distributedRasterImage, outputPath,ImageType.PNG);
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
return true;
}
/**
* Parallel filter render stitch.
*
* @param outputPath the output path
* @return true, if successful
*/
public static boolean parallelFilterRenderStitch(String outputPath)
{
try{
PointRDD spatialRDD = new PointRDD(sparkContext, PointInputLocation, PointOffset, PointSplitter, false, PointNumPartitions, StorageLevel.MEMORY_ONLY());
HeatMap visualizationOperator = new HeatMap(1000,600,USMainLandBoundary,false,2,4,4,true,true);
visualizationOperator.Visualize(sparkContext, spatialRDD);
ImageGenerator imageGenerator = new ImageGenerator();
imageGenerator.SaveRasterImageAsLocalFile(visualizationOperator.distributedRasterImage, outputPath,ImageType.PNG);
ImageStitcher.stitchImagePartitionsFromLocalFile(outputPath, 1000,600,0,4, 4);
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
return true;
}
/**
* Earthdata visualization.
*
* @param outputPath the output path
* @return true, if successful
*/
public static boolean earthdataVisualization(String outputPath)
{
try {
EarthdataHDFPointMapper earthdataHDFPoint = new EarthdataHDFPointMapper(HDFIncrement,HDFOffset,HDFRootGroupName,
HDFDataVariableList,HDFDataVariableName,HDFswitchXY,urlPrefix);
PointRDD spatialRDD = new PointRDD(sparkContext, earthdataInputLocation, earthdataNumPartitions, earthdataHDFPoint,StorageLevel.MEMORY_ONLY());
ScatterPlot visualizationOperator = new ScatterPlot(1000,600,spatialRDD.boundaryEnvelope,ColorizeOption.EARTHOBSERVATION,false,false);
visualizationOperator.CustomizeColor(255, 255, 255, 255, Color.BLUE, true);
visualizationOperator.Visualize(sparkContext, spatialRDD);
ImageGenerator imageGenerator = new ImageGenerator();
imageGenerator.SaveRasterImageAsLocalFile(visualizationOperator.rasterImage, outputPath, ImageType.PNG);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
/**
* The main method.
*
* @param args the arguments
* @throws IOException Signals that an I/O exception has occurred.
*/
public static void main(String[] args) throws IOException {
long start = System.currentTimeMillis();
Logger.getLogger("org").setLevel(Level.WARN);
Logger.getLogger("akka").setLevel(Level.WARN);
SparkConf sparkConf = new SparkConf().setAppName("GeoSparkVizDemo").setMaster("local[*]").set("spark.serializer", KryoSerializer.class.getName())
.set("spark.kryo.registrator", GeoSparkVizKryoRegistrator.class.getName());
sparkContext = new JavaSparkContext(sparkConf);
prop = new Properties();
String resourcePath = "src/test/resources/";
String demoOutputPath = "target/demo";
FileInputStream ConfFile= new FileInputStream(resourcePath+"babylon.point.properties");
prop.load(ConfFile);
String scatterPlotOutputPath = System.getProperty("user.dir")+"/"+demoOutputPath + "/scatterplot";
String heatMapOutputPath = System.getProperty("user.dir")+"/"+demoOutputPath+"/heatmap";
String choroplethMapOutputPath = System.getProperty("user.dir")+"/"+demoOutputPath+"/choroplethmap";
String parallelFilterRenderStitchOutputPath = System.getProperty("user.dir")+"/"+demoOutputPath+"/parallelfilterrenderstitchheatmap";
String earthdataScatterPlotOutputPath = System.getProperty("user.dir")+"/"+demoOutputPath+"/earthdatascatterplot";
PointInputLocation = System.getProperty("user.dir")+"/"+resourcePath+prop.getProperty("inputLocation");
PointOffset = Integer.parseInt(prop.getProperty("offset"));;
PointSplitter = FileDataSplitter.getFileDataSplitter(prop.getProperty("splitter"));
PointNumPartitions = Integer.parseInt(prop.getProperty("numPartitions"));
ConfFile= new FileInputStream(resourcePath+"babylon.rectangle.properties");
prop.load(ConfFile);
RectangleInputLocation = System.getProperty("user.dir")+"/"+resourcePath+prop.getProperty("inputLocation");
RectangleOffset = Integer.parseInt(prop.getProperty("offset"));
RectangleSplitter = FileDataSplitter.getFileDataSplitter(prop.getProperty("splitter"));
RectangleNumPartitions = Integer.parseInt(prop.getProperty("numPartitions"));
ConfFile= new FileInputStream(resourcePath+"babylon.polygon2.properties");
prop.load(ConfFile);
PolygonInputLocation = System.getProperty("user.dir")+"/"+resourcePath+prop.getProperty("inputLocation");
PolygonOffset = Integer.parseInt(prop.getProperty("offset"));
PolygonSplitter = FileDataSplitter.getFileDataSplitter(prop.getProperty("splitter"));
PolygonNumPartitions = Integer.parseInt(prop.getProperty("numPartitions"));
ConfFile= new FileInputStream(resourcePath+"babylon.linestring.properties");
prop.load(ConfFile);
LineStringInputLocation = System.getProperty("user.dir")+"/"+resourcePath+prop.getProperty("inputLocation");
LineStringOffset = Integer.parseInt(prop.getProperty("offset"));
LineStringSplitter = FileDataSplitter.getFileDataSplitter(prop.getProperty("splitter"));
LineStringNumPartitions = Integer.parseInt(prop.getProperty("numPartitions"));
USMainLandBoundary = new Envelope(-126.790180,-64.630926,24.863836,50.000);
earthdataInputLocation = System.getProperty("user.dir")+"/src/test/resources/modis/modis.csv";
earthdataNumPartitions = 5;
HDFIncrement=5;
HDFOffset=2;
HDFRootGroupName = "MOD_Swath_LST";
HDFDataVariableName = "LST";
HDFswitchXY = true;
urlPrefix = System.getProperty("user.dir")+"/src/test/resources/modis/";
if(buildScatterPlot(scatterPlotOutputPath)&&buildHeatMap(heatMapOutputPath)
&&buildChoroplethMap(choroplethMapOutputPath)&¶llelFilterRenderStitch(parallelFilterRenderStitchOutputPath+"-stitched")
&¶llelFilterRenderNoStitch(parallelFilterRenderStitchOutputPath)&&earthdataVisualization(earthdataScatterPlotOutputPath))
{
System.out.println("散点图生成完成,共耗时" + (System.currentTimeMillis() - start) + "ms");
System.out.println("All GeoSparkViz Demos have passed.");
}
else
{
System.out.println("GeoSparkViz Demos failed.");
}
sparkContext.stop();
}
}
项目可视化一览
参考资料:
https://www.jianshu.com/p/1a531de087df
https://www.helplib.com/GitHub/article_127813
GeoSpark入门-可视化的更多相关文章
- (一)Superset 1.3图表篇——Table
本系列文章基于Superset 1.3.0版本.1.3.0版本目前支持分布,趋势,地理等等类型共59张图表.本次1.3版本的更新图表有了一些新的变化,而之前也一直没有做过非常细致的图表教程. 而且目前 ...
- 一起学微软Power BI系列-官方文档-入门指南(4)Power BI的可视化
在前面的系列文章中,我们介绍了官方有关获取数据,以及建模的原始文档和基本介绍.今天继续给大家介绍官方文档中,有关可视化的内容.实际上获获取数据和建模更注重业务关系的处理,而可视化则关注对数据的解读.这 ...
- d3.js:数据可视化利器之快速入门
hello,data! 在进入d3.js之前,我们先用一个小例子回顾一下将数据可视化的基本流程. 任务 用横向柱状图来直观显示以下数据: var data = [10,15,23,78,57,29,3 ...
- Roslyn 入门:使用 Visual Studio 的语法可视化窗格查看和了解代码的语法树
使用 Visual Studio 提供的 Syntax Visualizer,我们可以实时看到一个代码文件中的语法树.这对我们基于 Roslyn 编写静态分析和修改工具非常有帮助.本文将介绍如何安装它 ...
- 数据可视化入门之show me the numbers
数据的可视化一直是自己瞎玩着学,近来想系统的学数据可视化的东西,于是搜索资料时看到有人推荐<show me the numbers>作为入门. 由于搜不到具体的书籍内容,只能 ...
- 数据可视化-svg入门基础(二)
接上一篇:数据可视化-svg入门基础(一),基础一主要是介绍了svg概念,元素样式设置等. svg是(scalable vector graphic)伸缩矢量图像. 一.目录 (1)图形元素 (2)文 ...
- Seaborn数据可视化入门
在本节学习中,我们使用Seaborn作为数据可视化的入门工具 Seaborn的官方网址如下:http://seaborn.pydata.org 一:definition Seaborn is a Py ...
- Matplotlib数据可视化(1):入门介绍
1 matplot入门指南¶ matplotlib是Python科学计算中使用最多的一个可视化库,功能丰富,提供了非常多的可视化方案,基本能够满足各种场景下的数据可视化需求.但功能丰富从另一方面来 ...
- Keras入门(六)模型训练实时可视化
在北京做某个项目的时候,客户要求能够对数据进行训练.预测,同时能导出模型,还有在页面上显示训练的进度.前面的几个要求都不难实现,但在页面上显示训练进度当时笔者并没有实现. 本文将会分享如何在K ...
随机推荐
- 【Luogu P1048 Luogu P1016】采药/疯狂的采药
采药/疯狂的采药 两道模板题,分别是0-1背包和完全背包. 0-1背包 二维:dp[i][j]=max(dp[i-1][j-time[i]]+v[i],dp[i-1][j]); 由于i的状态由i-1的 ...
- .NET高级特性-Emit(2.2)属性
关于Emit的博客已经进入第四篇,在读本篇博文之前,我希望读者能先仔细回顾博主之前所编写的关于Emit的博文,从该篇博文开始,我们就可以真正的使用Emit,并把知识转化为实战,我也会把之前的博文链接放 ...
- Selenium+Java(六)Selenium 强制等待、显式等待、隐实等待
前言 在实际测试过程中,由于网速或性能方面的原因,打开相应的网页后或在网页上做了相应的操作,网页上的元素可能不会马上加载出来,这个时候需要在定位元素前等待一下,等元素加载出来后再进行定位,根据实际使用 ...
- PAT(甲级)2017年秋季考试
PAT(甲级)2017年秋季考试 D题红黑树待补21/30 大佬的代码,看着想哭,这才是艺术啊 A Cut Integer 模拟题 #include<bits/stdc++.h> usin ...
- 【并发技术16】线程同步工具Exchanger的使用
如果两个线程在运行过程中需要交换彼此的信息,比如一个数据或者使用的空间,就需要用到 Exchanger 这个类,Exchanger 为线程交换信息提供了非常方便的途径,它可以作为两个线程交换对象的同步 ...
- Web安全-之文件上传漏洞场景
1 上传漏洞危害介绍 上传是Web中最常见的功能,如果上传功能存在设计.编码缺陷,就容易形成上传漏洞,从而成为致命的安全问题,攻击者可以通过上传脚本木马,实现查看/篡改/删除源码和任意涂鸦网页,可 ...
- ceph分布式存储
存储分类: DAS:直连存储 ide线 sata线 usd线 sas线 NAS:网络附加存储 nfs samba ftp SAN:存储区域网络 issci SDS ...
- shell 解析 json
如果 想利用 shell 从 json 数据 中 解析出某个字段, 可以 利用 正则匹配, 比如 想 解析出 "spanId":"8461203268866670975& ...
- 小白探究UE4网络系列(一)、UE4网络基础类分析
转载请标明出处:http://www.cnblogs.com/zblade/ 一.概要 捣鼓UE4也有两个多月了,从这儿开始,逐步探究UE4中经典的值复制,RPC两种同步方式.想要弄到其复制和调用的原 ...
- React 事件总结
目录 一 绑定事件处理函数 1.1 鼠标类 1.2 拖拽事件: 1.3 触摸 1.4 键盘 1.5 剪切类 1.6 表单类 1.7 焦点事件 1.8 UI元素类 1.9 滚动 1.10 组成事件 1. ...