World Wind Java development Eight-load local cache file to build a large-scale three-dimensional scene

Source: Internet
Author: User
Tags xpath

The previous blog is mainly for small files directly into the WW display, however, when the file is particularly large, this approach is not feasible. So to slice large files and generate a local cache, WW can load the local cache file, guaranteeing the smoothness of browsing the scene.

1. Use global Mapper to generate WW cache tiles the steps to generate WW cache tiles using Global mapper have been uploaded to generate WW cache tiles using Globalmapper, which is not mentioned here. The resulting slices can be placed under any folder, currently referencing the example of WWJ.Installimageryandelevationsdemo,temporarily place the data in the C:\ProgramData\WorldWindInstalled directory, as shown in.
The resulting XML file is modified as follows:
2. ReferenceInstallimageryandelevationsdemo Example implementing initialization loading of a cache filewithout much modification, write a class loadcachedata that loads the cached data, as shown in the code below.
/** * @Copyright 2014-2020 @ run of shredded chicken **/package edu.whu.vge.util;import Edu.whu.vge.util.javacheckboxtree.checkboxtreenode;import Gov.nasa.worldwind.factory;import Gov.nasa.worldwind.worldwind;import Gov.nasa.worldwind.avlist.avkey;import gov.nasa.worldwind.avlist.AVList; Import Gov.nasa.worldwind.avlist.avlistimpl;import Gov.nasa.worldwind.awt.worldwindowglcanvas;import Gov.nasa.worldwind.cache.filestore;import Gov.nasa.worldwind.exception.wwruntimeexception;import Gov.nasa.worldwind.geom.sector;import Gov.nasa.worldwind.globes.earth;import Gov.nasa.worldwind.globes.elevationmodel;import Gov.nasa.worldwind.layers.layer;import Gov.nasa.worldwind.terrain.compoundelevationmodel;import Gov.nasa.worldwind.util.dataconfigurationfilter;import Gov.nasa.worldwind.util.dataconfigurationutils;import Gov.nasa.worldwind.util.logging;import Gov.nasa.worldwind.util.wwio;import Gov.nasa.worldwind.util.wwxml;import Java.awt.component;import Java.io.File; Import Javax.swing.jtree;import Javax.swing.SwingUtiLities;import Javax.swing.tree.defaultmutabletreenode;import Javax.xml.xpath.xpath;import org.w3c.dom.Document; Import org.w3c.dom.element;/** * @ Project Name: GF_ZHJCYPG * Class Name: Loadcachedata * @ class Description: Load Cached Data * @ Creator: Run of chicken silk * @ Created: 2014-12-19 pm 4: 30:49 * @ Revision NOTES: * @ Version: */public class Loadcachedata{private static Worldwindowglcanvas worldwindowglcanvas;private static J Tree layerjtree;/** * * Create a new instance of Loadcachedata. * * @param worwindowglcanvas */public loadcachedata (Worldwindowglcanvas Worwindowglcanvas, JTree JTree) { Loadcachedata.setworldwindowglcanvas (Worwindowglcanvas); Loadcachedata.setlayerjtree (JTree);} /** * @ Method Name: loadpreviouslyinstalleddata; * @ Method Description: Load the existing cache file; * @ parameter: * @ return type: void; * @ Creator: running chicken silk; * @ creation Time: 2014-12-19 pm 7:06:09; * @throws */public void Loadpreviouslyinstalleddata () {Thread thread = new Thread (New RUNNABL E () {@Overridepublic void Run () {//TODO auto-generated method Stubloadinstalleddatafromfilestore ( Worldwind.getdatafilestore ());}); Thread.Start ();} /** * @ Method Name: LoadinstaLleddatafromfilestore; * @ method Description: TODO; * @ parameter: @param filestore * @ return type: void; * @ Creator: running chicken silk; * @ creation Time: 2014-12-19 pm 7:06:42; * @throws */protected void Loadinstalleddatafromfilestore (Filestore filestore) {// Facilitates existing cache file for (file File:fileStore.getLocations ()) {//file exists and is a cache file directory if (file.exists () && Filestore.isinstalllocation (File.getpath ())) {System.out.println (File.getpath ()); loadinstalleddatafromdirectory (file);}}} /** * @ Method Name: loadinstalleddatafromdirectory; * @ Method Description: Load cached data from the file directory; * @ parameter: @param dir * @ return type: void; * @ Creator: running chicken silk; * @ creation Time: 2014-12-19 pm 7:43:36; * @throws */private void loadinstalleddatafromdirectory (File dir) {/** * Gets the relative directory of the cache file XML configuration file in the cache file directory, such as Landsat\landsat.xml */string[] names = Wwio.listdescendantfilenames (dir,new  Dataconfigurationfilter (), false); if (names = = NULL | | names.length = = 0) return;for (String filename:names) {Document doc = null;try{//Creates a Document object based on the cached file XML description file Dataconfigfile = new file (dir, filename);d oc = Wwxml.opendocument ( Dataconfigfile);doc = Dataconfigurationutils.converttostandarddataconfigdocument (doc);} catch (Wwruntimeexception e) {e.printstacktrace ();} if (doc = = null) continue;//because the data configuration file is from an existing file, it is not guaranteed to be generated by the current version of WW ' s installer//. may have been generated by a previous version or other application, so set an alternate value for the parameters that might be missing (these parameters need to be used to build a layer or elevation simulation) avlist params = new Avlistimpl (); Setfallbackparams (Doc, filename, params);//Add Data Addinstalleddata (doc, params);}} /** * @ Method Name: setfallbackparams; * @ Method Description: Set alternate parameter values; * @ parameter: @param dataconfig: Data Configuration XML file * @ parameter: @param filename: file name * @ Parameters: @param params: Parameter list * @ return type: void; * @ Creator: running chicken silk; * @ creation Time: 2014-12-20 pm 12:21:03; * @throws */private void Setfallbackparams (Document dataconfig, String filename,avlist par AMS) {XPath XPath = Wwxml.makexpath (); Element domelement = Dataconfig.getdocumentelement ();/If The data configuration document doesn ' t define a cache name, th en//compute one using the file ' s path//relative to its file cache directory. String s = wwxml.gettext (DomElement, "Datacachename", XPath); if (s = = NULL | | s.length () = = 0) DataConfigurationutils.getdataconfigcachename (filename, params);/If The data configuration document doesn ' t define the Data ' s extreme//elevations, provide default values using//the minimum and maximum elevations of earth.string type = data Configurationutils.getdataconfigtype (DomElement), if (Type.equalsignorecase ("Elevationmodel")) {if ( Wwxml.getdouble (DomElement, "extremeelevations/@min", xpath) = = null) params.setvalue (Avkey.elevation_min, Earth.elevation_min); if (Wwxml.getdouble (DomElement, "extremeelevations/@max", xpath) = = null) Params.setvalue ( Avkey.elevation_max, Earth.elevation_max);}} /** * @ Method Name: addinstalleddata; * @ Method Description: Add cached data; * @ parameter: @param dataconfig * @ parameter: @param params * @ return type: void; * @ Creator: Run the chicken silk; * @ creation Time: 2014-12-20 pm 12:22:29; * @throws */private void Addinstalleddata (Final Document dataconfig, final avlist params) {i F (! Swingutilities.iseventdispatchthread ()) {Swingutilities.invokelater (new Runnable () {public void run () { Addinstalleddata (dataconfig, params);});} else{Addinstalledcachedata (Dataconfig.getdocumentelement (), params);}}  /** * @ Method Name: addinstalledcachedata; * @ Method Description: Add existing cached data; * @ parameter: @param domelement: Data XML Profile * @ parameter: @param params: Parameter list * @ return type: void; * @ Creator: running chicken silk; * @ creation Time: 2014-12-19 pm 8:02:21; * @throws */public void Addinstalledcachedata (final Element domelement,final avlist params) {if (domelement = = null) {String message = Logging.getmessage ("Nullvalue.documentisnull"); Logging.logger (). severe (message); throw new illegalargumentexception (message); String Description = GetDescription (domelement); Layer name Sector sector = Getsector (domelement); Layer range System.out.println (description); SYSTEM.OUT.PRINTLN (sector); Addtoworldwindow (domelement, params);} /** * @ Method Name: Addtoworldwindow; * @ Method Description: Add the cache file to WW; * @ parameter: @param domelement * @ parameter: @param params * @ return type: void; * @ gen Jian people: run of chicken silk; * @ creation Time: 2014-12-19 pm 4:44:08; * @throws */private void Addtoworldwindow (Element domelement, avlist params) {String type = D Ataconfigurationutils.getdataconfigtype(DomElement), if (type = = null) return;if (Type.equalsignorecase ("Layer")) {Addlayertoworldwindow (domelement, params);} else if (type.equalsignorecase ("Elevationmodel")) {Addelevationmodeltoworldwindow (domelement, params);}} /** * @ Method Name: Addlayertoworldwindow; * @ Method Description: Add layer to WW; * @ parameter: @param domelement * @ parameter: @param params * @ return type: void; * @ Creator: The running of the shredded chicken; * @ creation Time: 2014-12-19 pm 4:45:06; * @throws */private void Addlayertoworldwindow (Element domelement, avlist params) {Layer Lay The layer created by ER = null;try{//Factory is not visible by default factory factory = (Factory) worldwind.createconfigurationcomponent (avkey.layer_ FACTORY); layer = (layer) Factory.createfromconfigsource (domelement, params);} catch (Exception e) {String message = Logging.getmessage ("Generic. Creationfromconfigurationfailed ", Dataconfigurationutils.getdataconfigdisplayname (domElement)); Logging.logger (). log (Java.util.logging.Level.SEVERE, message, e);} if (layer = = null) return;layer.setenabled (TRUE); Set layer visible//Add to Wwif (!getworldwindowglcanvas (). Getmodel (). Getlayers (). Contains (layer)) {Getworldwindowglcanvas (). Getmodel (). Getlayers (). Add (layer);//System.out.println ( Playertree.getmodel (). Getroot (). toString ()), Object rootobject = Layerjtree.getmodel (). Getroot (); if (! Layerjtree.getmodel (). IsLeaf (Rootobject)) {int count = Layerjtree.getmodel (). Getchildcount (Rootobject); for (int i = 0; I < count; i++) {String childnodenamestring = Layerjtree.getmodel (). Getchild (Rootobject, i). toString (); if ( Childnodenamestring.equals ("Imagery layer")) {((Defaultmutabletreenode) Layerjtree.getmodel (). Getchild (RootObject, I)). Add (New Checkboxtreenode (Layer.getname ())); Layerjtree.updateui ();}}}} /** * @ Method Name: Addelevationmodeltoworldwindow; * @ Method Description: Add elevation layer; * @ parameter: @param domelement * @ parameter: @param params * @ return type: void; * Creator: Running chicken silk; * @ creation Time: 2014-12-19 pm 4:51:37; * @throws */private void Addelevationmodeltoworldwindow (Element domelement,avlist params) {Elevationmodel em = null;try{factory Factory = (Factory) worldwind.createconfigurationcomponent (avkey.elevation_ Model_FACTORY); em = (Elevationmodel) factory.createfromconfigsource (domelement,params);} catch (Exception e) {String message = Logging.getmessage ("Generic. Creationfromconfigurationfailed ", Dataconfigurationutils.getdataconfigdisplayname (domElement)); Logging.logger (). log (Java.util.logging.Level.SEVERE, message, e);} if (em = = null) return; Elevationmodel Defaultelevationmodel = Getworldwindowglcanvas (). Getmodel (). Getglobe (). Getelevationmodel (); if ( Defaultelevationmodel instanceof Compoundelevationmodel) {if (!) ( (Compoundelevationmodel) Defaultelevationmodel). Containselevationmodel (EM)) ((Compoundelevationmodel) Defaultelevationmodel). Addelevationmodel (EM);} Else{compoundelevationmodel cm = new Compoundelevationmodel (); Cm.addelevationmodel (Defaultelevationmodel); Cm.addelevationmodel (EM); Getworldwindowglcanvas (). Getmodel (). Getglobe (). Setelevationmodel (cm);}} /** * Get cache file type Get Cache Profile Description: Is layer or elevation * * @ Method Name: getdescription; * @ method Description: TODO; * @ parameter: @param domelement * @ parameter: @return * @ return type: String; * @ Creator: Run the chicken silk; * @ creation Time: 2014-12-19 pm 4:53:26; * @throws */private string getdescription (Element domelement) {string displayName = dataconf Igurationutils.getdataconfigdisplayname (DomElement); String type = Dataconfigurationutils.getdataconfigtype (domelement); StringBuilder sb = new StringBuilder (displayName), if (Type.equalsignorecase ("layer")) {Sb.append ("layer");} else if (type.equalsignorecase ("Elevationmodel")) {Sb.append ("(elevations)");} return sb.tostring ();} /** * Get Layer Range * @ Method Name: getsector; * @ method Description: TODO; * @ parameter: @param domelement * @ parameter: @return * @ return type: Sector; * Creator: Chicken running Silk * @ creation Time: 2014-12-19 pm 4:54:17; * @throws */protected static Sector getsector (Element domelement) {return Wwxml.getsector ( DomElement, "Sector", null);} public static Worldwindowglcanvas Getworldwindowglcanvas () {return worldwindowglcanvas;} public static void Setworldwindowglcanvas (Worldwindowglcanvas worldwindowglcanvas) { Loadcachedata.worldwindowglcanvas = Worldwindowglcanvas;} Public JTree Getlayerjtree () {returnLayerjtree;} public static void Setlayerjtree (JTree layerjtree) {loadcachedata.layerjtree = Layerjtree;}}
3, elevation data loading elevation data using NASA's 30m public DEM data, using the World Wind Server release, see the previous building of the local World Wind severe server. The final implementation is as shown.
PS: Year-end various busy Ah, project finally knot, tomorrow Group annual meeting, wish all smooth! Welcome to the message exchange, sharing their own study notes. World Wind Java data is too little, intermittent finally built a three-dimensional framework, followed by the addition of functions, planning to do a flood simulation based on the Xin ' an river Model simulation module, the previous flood simulation and parameter rate set, runoff simulation all integrated into their own platform.

World Wind Java development Eight-load local cache file to build a large-scale three-dimensional scene

Related Article

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.