World Wind Java Development's ten--analyticsurface grid rendering

Source: Internet
Author: User

1, Analyticsurfacedemo

The various hierarchical rendering effects of rasters under ArcGIS are very good, can make a very beautiful picture, now can also do the same effect under WW, see here is not a little excited about it. Let's take a look at the run of the Analyticsurfacedemo from WW:


By looking at the source code can be known to give three rendering examples, two of which are dynamic, what I need here is the DEM data or a single-band image rendering, that is, the top left rendering effect.

2, Analyticsurface class

Here's a look at the main classes used:


The main method to use:

Create a Analyticsurface and set its properties 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);//Set the surface rendering mode to Clamp_to_groundsurface.setaltitudemode ( Worldwind.clamp_to_ground);
You can review the development documentation to set additional properties, depending on your needs.

3, Dem rendering instance will be a little modification of the code in the demo encapsulated as the Analyticsurfaceutil class for all subsequent raster data rendering use, now relatively simple, followed by the expansion of the class. WW Rendering Effect:
Rendering results in ArcMap:

Can see WW under the effect of the rendering of silk no less, the picture is not very beautiful it.

4, flood simulation renderingThis is an improvement to the previous flood simulation, rendering the range and depth maps of the flood simulation output. (1) Scope chart
(2) Depth map
This rendering of the depth of the image is not a volcanic eruption of the feeling, very artistic beauty, very much like the effect of this rendering. Change the color and look at another rendering effect:
5, source code. The following is the package of their own Analyticsurfaceutil class, for your reference:
/** * @Copyright 2014-2020 @ Liu Shuo **/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 /** * @ Project Name: Smartscope * Class Name: Analyticsurfaceutil * @ class Description: * @ Creator: Liu Shuo * @ created: 2015-1-21 3:40:54 * @ Edit NOTE: * @ Version: */public Class analyticsurfaceutil{/** * Create a new instance analyticsurfaceutil. * */public Analyticsurfaceutil () {//TODO auto-generated Co Nstructor 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;//get cell maximum and minimum double[] extremes = Wwbufferutil.computeextremevalues (Raster.getbuffer (), Raster.gettransparentvalue ()), if (extremes = = null) return;/ /Create Analyticsurface and set its properties 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);//Set surface rendering method is Clamp_to_groundsurface.setaltitudemode (Worldwind.clamp_to_ground); Analyticsurfaceattributes attr = new Analyticsurfaceattributes (); Attr.setdrawoutline (false); Attr.setdrawshadow ( FALSE); attr.setinterioropacity (0.6); Surface.setsurfaceattributes (attr);//Set legend Style format Legendlabelformat = new DecimalFormat ("# m") {public stringbuffer format (double number, StringBuffer result,fieldposition fieldposition) { Double Valueinfeet = Number;return Super.format (valueinfeet, result, fieldposition);}};/ /create legend 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); o Utlayer.addrenderable (surface); Outlayer.addrenderable (createlegendrenderable (surface, 600,legend);});}  /** * @ Method Name: loadrasterelevations; * @ Method Description: Read data (single band); * @ parameter: @param path * @ parameter: @return * @ return type: Bufferwrapperraster ; * @ Creator: Liu Shuo; * @ Created: 2015-1-22 a.m. 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 Typ E.datarasterreaderfactory readerfactory = (datarasterreaderfactory) worldwind.createconfigurationcomponent ( Avkey.data_raster_reader_factory_class_name);D Atarasterreader 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. Thisstep//is//necessary because only sub-rasters//is reprojected (if necessary); Primary rasters is not.int width = rasters[0].getwidth (); int height = rasters[0].getheight ();D ataraster subraster = Raste Rs[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;}} /** * @ Method Name: createlegendrenderable; * @ Method Description: Create legend; * @ parameter: @param surface * @ parameter: @param surfaceminscreensize * @ parameter: @ PARAM legend * @ parameter: @return * @ return type: renderable; * Creator: Liu Shuo; * @ creation time: 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);}};}

It's not perfect at the moment, so if you want to do a sort of arcgis-like rendering tool, you can easily render data such as the amount of rainfall evapotranspiration.

World Wind Java Development's ten--analyticsurface grid rendering

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.