World Wind Java开发之十——AnalyticSurface栅格渲染(转)
http://blog.csdn.net/giser_whu/article/details/43017881
1、AnalyticSurfaceDemo
ArcGIS下对栅格的各种分级渲染效果是非常好的,可以做出很漂亮的图,现在在WW下也可以做出同样的效果了,看到这里是不是有点小兴奋呢。先看下WW自带的AnalyticSurfaceDemo的运行效果图:

通过看源代码可以知道给出了三种渲染示例,其中两种是动态的,这里我需要的是对dem数据或者是单波段影像的渲染,也就是左上方的渲染效果。
2、AnalyticSurface类
下面来看下主要用到的类:

主要用到的方法:
- // 创建AnalyticSurface并设置其属性
- final AnalyticSurface surface = new AnalyticSurface();
- surface.setSector(raster.getSector());
- surface.setDimensions(raster.getWidth(), raster.getHeight());
- surface.setValues(AnalyticSurface.createColorGradientValues(
- raster.getBuffer(), raster.getTransparentValue(), extremes[0],
- extremes[1], minHue, maxHue));
- // surface.setVerticalScale(5e3);
- // 设置表面渲染方式为 CLAMP_TO_GROUND
- surface.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
根据自己的需要可以查阅开发文档设置其他属性。
3、DEM渲染实例


可以看到WW下渲染的效果丝毫不逊色,图是不是很漂亮呢。
4、洪涝模拟渲染



5、源码。
- /**
- * @Copyright 2014-2020 @刘硕
- **/
- package edu.whu.vge.util;
- import gov.nasa.worldwind.WorldWind;
- import gov.nasa.worldwind.avlist.AVKey;
- import gov.nasa.worldwind.avlist.AVList;
- import gov.nasa.worldwind.data.BufferWrapperRaster;
- import gov.nasa.worldwind.data.DataRaster;
- import gov.nasa.worldwind.data.DataRasterReader;
- import gov.nasa.worldwind.data.DataRasterReaderFactory;
- import gov.nasa.worldwind.exception.WWRuntimeException;
- import gov.nasa.worldwind.geom.Extent;
- import gov.nasa.worldwind.geom.Sector;
- import gov.nasa.worldwind.layers.RenderableLayer;
- import gov.nasa.worldwind.render.DrawContext;
- import gov.nasa.worldwind.render.Renderable;
- import gov.nasa.worldwind.util.Logging;
- import gov.nasa.worldwind.util.WWBufferUtil;
- import gov.nasa.worldwind.util.WWIO;
- import gov.nasa.worldwind.util.WWMath;
- import gov.nasa.worldwindx.examples.analytics.AnalyticSurface;
- import gov.nasa.worldwindx.examples.analytics.AnalyticSurfaceAttributes;
- import gov.nasa.worldwindx.examples.analytics.AnalyticSurfaceLegend;
- import gov.nasa.worldwindx.examples.util.ExampleUtil;
- import java.awt.Point;
- import java.io.File;
- import java.text.DecimalFormat;
- import java.text.FieldPosition;
- import java.text.Format;
- import javax.swing.SwingUtilities;
- /**
- * @项目名称:SmartScope
- * @类名称:AnalyticSurfaceUtil
- * @类描述:
- * @创建人:刘硕
- * @创建时间:2015-1-21 下午3:40:54
- * @修改备注:
- * @版本:
- */
- public class AnalyticSurfaceUtil
- {
- /**
- * 创建一个新的实例 AnalyticSurfaceUtil.
- *
- */
- public AnalyticSurfaceUtil()
- {
- // TODO Auto-generated constructor stub
- }
- public static void createPrecipitationSurface(double minHue, double maxHue,
- final RenderableLayer outLayer)
- {
- String DATA_PATH = "J:/data/wwj/FloodDepth.tif";
- BufferWrapperRaster raster = loadRasterElevations(DATA_PATH);
- if (raster == null)
- return;
- // 获取像元最大值与最小值
- double[] extremes = WWBufferUtil.computeExtremeValues(
- raster.getBuffer(), raster.getTransparentValue());
- if (extremes == null)
- return;
- // 创建AnalyticSurface并设置其属性
- final AnalyticSurface surface = new AnalyticSurface();
- surface.setSector(raster.getSector());
- surface.setDimensions(raster.getWidth(), raster.getHeight());
- surface.setValues(AnalyticSurface.createColorGradientValues(
- raster.getBuffer(), raster.getTransparentValue(), extremes[0],
- extremes[1], minHue, maxHue));
- // surface.setVerticalScale(5e3);
- // 设置表面渲染方式为 CLAMP_TO_GROUND
- surface.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
- AnalyticSurfaceAttributes attr = new AnalyticSurfaceAttributes();
- attr.setDrawOutline(false);
- attr.setDrawShadow(false);
- attr.setInteriorOpacity(0.6);
- surface.setSurfaceAttributes(attr);
- // 设置图例样式
- Format legendLabelFormat = new DecimalFormat("# m")
- {
- public StringBuffer format(double number, StringBuffer result,
- FieldPosition fieldPosition)
- {
- double valueInFeet = number;
- return super.format(valueInFeet, result, fieldPosition);
- }
- };
- // 创建图例
- final AnalyticSurfaceLegend legend = AnalyticSurfaceLegend.fromColorGradient(
- extremes[0], extremes[1], minHue, maxHue,
- AnalyticSurfaceLegend.createDefaultColorGradientLabels(
- extremes[0], extremes[1], legendLabelFormat),
- AnalyticSurfaceLegend.createDefaultTitle("Legend"));
- legend.setOpacity(0.8);
- legend.setScreenLocation(new Point(100, 300));
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- surface.setClientLayer(outLayer);
- outLayer.addRenderable(surface);
- outLayer.addRenderable(createLegendRenderable(surface, 600,
- legend));
- }
- });
- }
- /**
- *
- * @方法名称: loadRasterElevations ;
- * @方法描述: 读取数据(单波段) ;
- * @参数 :@param path
- * @参数 :@return
- * @返回类型: BufferWrapperRaster ;
- * @创建人:刘硕;
- * @创建时间:2015-1-22 上午11:25:40;
- * @throws
- */
- public static BufferWrapperRaster loadRasterElevations(String path)
- {
- // Download the data and save it in a temp file.
- File file = ExampleUtil.saveResourceToTempFile(path,
- "." + WWIO.getSuffix(path));
- // Create a raster reader for the file type.
- DataRasterReaderFactory readerFactory = (DataRasterReaderFactory) WorldWind.createConfigurationComponent(AVKey.DATA_RASTER_READER_FACTORY_CLASS_NAME);
- DataRasterReader reader = readerFactory.findReaderFor(file, null);
- try
- {
- // Before reading the raster, verify that the file contains
- // elevations.
- AVList metadata = reader.readMetadata(file, null);
- if (metadata == null
- || !AVKey.ELEVATION.equals(metadata.getStringValue(AVKey.PIXEL_FORMAT)))
- {
- String msg = Logging.getMessage(
- "ElevationModel.SourceNotElevations",
- file.getAbsolutePath());
- Logging.logger().severe(msg);
- throw new IllegalArgumentException(msg);
- }
- // Read the file into the raster.
- DataRaster[] rasters = reader.read(file, null);
- if (rasters == null || rasters.length == 0)
- {
- String msg = Logging.getMessage(
- "ElevationModel.CannotReadElevations",
- file.getAbsolutePath());
- Logging.logger().severe(msg);
- throw new WWRuntimeException(msg);
- }
- // Determine the sector covered by the elevations. This
- // information
- // is in the GeoTIFF file or auxiliary
- // files associated with the elevations file.
- Sector sector = (Sector) rasters[0].getValue(AVKey.SECTOR);
- if (sector == null)
- {
- String msg = Logging.getMessage("DataRaster.MissingMetadata",
- AVKey.SECTOR);
- Logging.logger().severe(msg);
- throw new IllegalArgumentException(msg);
- }
- // Request a sub-raster that contains the whole file. This step
- // is
- // necessary because only sub-rasters
- // are reprojected (if necessary); primary rasters are not.
- int width = rasters[0].getWidth();
- int height = rasters[0].getHeight();
- DataRaster subRaster = rasters[0].getSubRaster(width, height,
- sector, rasters[0]);
- // Verify that the sub-raster can create a ByteBuffer, then
- // create
- // one.
- if (!(subRaster instanceof BufferWrapperRaster))
- {
- String msg = Logging.getMessage(
- "ElevationModel.CannotCreateElevationBuffer", path);
- Logging.logger().severe(msg);
- throw new WWRuntimeException(msg);
- }
- return (BufferWrapperRaster) subRaster;
- }
- catch (Exception e)
- {
- e.printStackTrace();
- return null;
- }
- }
- /**
- *
- * @方法名称: createLegendRenderable ;
- * @方法描述: 创建图例 ;
- * @参数 :@param surface
- * @参数 :@param surfaceMinScreenSize
- * @参数 :@param legend
- * @参数 :@return
- * @返回类型: Renderable ;
- * @创建人:刘硕;
- * @创建时间:2015-1-22 上午11:26:07;
- * @throws
- */
- protected static Renderable createLegendRenderable(
- final AnalyticSurface surface, final double surfaceMinScreenSize,
- final AnalyticSurfaceLegend legend)
- {
- return new Renderable()
- {
- public void render(DrawContext dc)
- {
- Extent extent = surface.getExtent(dc);
- if (!extent.intersects(dc.getView().getFrustumInModelCoordinates()))
- return;
- if (WWMath.computeSizeInWindowCoordinates(dc, extent) < surfaceMinScreenSize)
- return;
- legend.render(dc);
- }
- };
- }
- }
目前还很不完善,后面有需要的话打算做一个类似于ArcGIS的分级渲染工具,对于降雨量蒸散发量等数据都可以很方便的进行渲染。
World Wind Java开发之十——AnalyticSurface栅格渲染(转)的更多相关文章
- World Wind Java开发之十五——载入三维模型
之前的一篇博客是关于载入粗三维模型的,见http://blog.csdn.net/giser_whu/article/details/43452703,这个地方还存在着不能载入纹理的问题,一直没呢解决 ...
- World Wind Java开发之十五——加载三维模型(转)
之前的一篇博客是关于加载粗三维模型的,见http://blog.csdn.net/giser_whu/article/details/43452703,这个地方还存在着不能加载纹理的问题,一直没呢解决 ...
- World Wind Java开发之十四——添加WMS地图服务资源(转)
数据是GIS的核心,没有数据一切无从谈起,Internet上有很多在线WMS地图服务资源,我们可以好好利用这些数据资源,比如天地图.必应地图.NASA.OGC数据服务等等. 在我们国家常用的还是天地图 ...
- World Wind Java开发之七——读取本地栅格文件(影像+高程)构建三维场景(转)
http://blog.csdn.net/giser_whu/article/details/41679515 首先,看下本篇博客要达到的效果图: 下面逐步分析如何加载影像及高程文件. 1.World ...
- World Wind Java开发之十二——加载粗制三维模型(ExtrudedPolygon)(转)
ww可以根据DLG图批量生成假三维模型,这对于小区等特征相似的建筑物模型的构建是非常有用的.下面来看如何一步步实现假三维模型的加载: 1.Shp文件的制作 首先在arcmap下数字化几个建筑物,并新建 ...
- [转]World Wind Java开发之四——搭建本地WMS服务器
在提供地理信息系统客户端时,NASA还为用户提供了开源的WMS Server 服务器应用:World Wind WMS Server.利用这个应用,我们可以架设自己的WMS服务并使用自己的数据(也支持 ...
- World Wind Java开发之六——解析shape文件(转)
http://blog.csdn.net/giser_whu/article/details/41647117 最近一直忙于导师项目的事情了,几天没更新了,昨天和今天研究了下WWJ解析shp文件的源代 ...
- World Wind Java开发之一(转)
http://blog.csdn.net/giser_whu/article/details/40477235 参照<World wind Java三维地理信息系统开发指南随书光盘>以及官 ...
- [转]World Wind Java开发之五——读取本地shp文件
World Wind Java 使用IconLayer图层类表现点和多点数据,使用RenderableLayer图层表现线和面数据,一个图层只能对应一组shape文件.World Wind Java首 ...
随机推荐
- python的virtualenv环境与使用
1.安装virtualenv 在安装virtualenv之前,我们需要安装至少有一个版本的Python:因为virtualenv是python的一个第三方模块,必须基于python环境才能安装: 如果 ...
- 【BZOJ4144】[AMPPZ2014]Petrol(最短路+最小生成树+并查集)
Description 给定一个n个点.m条边的带权无向图,其中有s个点是加油站. 每辆车都有一个油量上限b,即每次行走距离不能超过b,但在加油站可以补满. q次询问,每次给出x,y,b,表示出发点是 ...
- 洛谷P3006 [USACO11JAN]瓶颈Bottleneck(堆模拟)
传送门 感觉这题的思路还是挺不错的.然而为啥全网就一个题解而且只有代码……然后我只好看着代码理解了好久…… 题意就是有一棵树,每一个节点向他父亲节点连边,且有一个容量表示每一秒可以经过的牛的数量,每一 ...
- 阿里、腾讯热门面试题:聊聊Unix与Java的IO模型?(含详细解析)
众所周知 如果去百度.腾讯等一线大厂面试,一定会深入考候选人的基础技术功底,其中尤为关键和重视的就是IO相关的技术和知识. 而要搞明白IO相关的概念,首先就得弄清楚同步与异步,阻塞与非阻塞到底是什么意 ...
- vue中点击空白处隐藏弹框(用指令优雅地实现)
在写vue的项目的时候,弹框经常性出现,并要求点击弹框外面,关闭弹框,那么如何实现呢?且听我一一...不了,能实现效果就好 <template> <div> <div c ...
- 0、ubuntu16.04安装部署kvm
ubuntu16.04安装部署kvm1.查看CPU是否支持KVM egrep "(svm|vmx)" /proc/cpuinfo 2.安装相关kvm包 sudo apt-get i ...
- lintcode-dfs实现二叉树的层序遍历
class Solution { /** * @param root: The root of binary tree. * @return: Level order a list of lists ...
- 将GPT转换成MBR
准备一个pe启动盘 1.单击”运行“在弹出来的窗口输入cmd回车 2.在输入“diskpart”回车 3.在输入“list disk”显示硬盘信息,查看那个盘是gpt分区类型 4.输入“select ...
- ros indigo install
http://wiki.ros.org/cn/indigo/Installation/Ubuntu
- Linux Bash 命令行快捷键小结
编辑命令 光标移动 剪切.删除 Ctrl ...