First, take a look at this blog post to achieve:
The following steps through the loading of images and elevation files.
1, WorldWind Java Import packet found in the SRC source file DataImport package, the sample code inside the package shows how to load the image and elevation files to ww. You can see the import and install two ways, import is simply loaded as a layer into WW; install means that when the file is large, the file is loaded locally, and the image and elevation files are imported in the first import mode. Source code is relatively simple, here is no longer too much analysis.
2, WWJ loading image files directly to the source code, comments are clear, no longer repeat
/** * @ Method Name: importimagery; * @ Method Description: Import image file; * @ parameter: @param imagefilepath: Image file path * @ parameter: @param worlglcanvas:worldwin D Canvas Object * @ return type: void; * @ Creator: running chicken silk; * @ creation Time: 2014-12-2 pm 3:12:30; * @throws */private void importimagery (String imagefilepath,final Worldwindowglcanvas Worlglcanvas) {try{//reads the data and saves it in a cache folder file SourceFile = Exampleutil.saveresourcetotempfile (Imagefilepath, ". tif") ;/** * First create a raster reader to read the raster file. Raster reader reads the workspace from the current raster data to create */datarasterreaderfactory readerfactory = (datarasterreaderfactory) Worldwind.createconfigurationcomponent (avkey.data_raster_reader_factory_class_name);D Atarasterreader READER = Readerfactory.findreaderfor (sourcefile,null);//Before reading raster data, verify that the file contains imageryavlist metadata = Reader.readmetadata ( SourceFile, NULL); if (metadata = = null| |! AVKey.IMAGE.equals (Metadata.getstringvalue (Avkey.pixel_format))) throw new Exception ("Not a IMAGE file."); * * * to read files into Dataraster, if the read source file contains multiple file types, read may return multiple raster * But in this case use the first element in the returned raster array */dataraster[] Rasters = reader.read (sourcefile, NULL); if (rasters = = NULL | | rasters.length = = 0) throw new Exception ("Can ' t read the image fi Le. ");D Ataraster Raster = rasters[0];/** * Get the latitude and longitude range of the image, change the information in the GeoTiff file or its attached file */final Sector Sector = (Sector) raster.getvalue (avke Y.sector); if (SECTOR = = null) throw new Exception ("No location specified with image."); * * Gets a sub-grid containing an entire image. This step is necessary because only the sub-raster image can be re-projected; */int width = raster.getwidth (); int height = raster.getheight ();/** * Getsubraster () The */dataraster method returns a raster image of a specific range; The image size can be customized by the Subraster = Raster.getsubraster (width, height, sector,null);/** * Delete original raster data */ Raster.dispose ();/** * Verify that the sub-grid can create a cached image, or you can create a cached raster image */if (!) ( Subraster instanceof Bufferedimageraster)) throw new Exception ("Cannot get bufferedimage."); BufferedImage image = ((Bufferedimageraster) subraster). Getbufferedimage ();/** * Delete sub-raster image */subraster.dispose ();/** * Creates a surface image to display the image within the specified latitude and longitude range */final surfaceimage surfaceimage = new Surfaceimage (image, Sector);/** * Import the image data in a newly opened thread, As a surfacelayer */swingutilities.invokElater (New Runnable () {public void run () {//Add surfacelayersurfaceimagelayer Surfaceimagelayer = new Surfaceimagelayer () ; Surfaceimagelayer.setname ("Imported Surface Image"); surfaceimagelayer.setpickenabled (false); Surfaceimagelayer.addrenderable (surfaceimage);//Add the layer to the Globe Worldwindowglcanvas.getmodel (). Getlayers (). Add ( Surfaceimagelayer);//fly to the current image view Exampleutil.goto (Worlglcanvas, Sector);});} catch (Exception e) {e.printstacktrace ();}}
The reading of the raster data here is similar to the concept of a workspace in Arcengine, and it is also important to note that the sector class is a representation of the range contained by latitude and longitude. 3. WWJ Loading elevation file
/** * @ Method Name: importelevation; * @ Method Description: Import elevation data; * @ parameter: @param elevationfilepath: Elevation file path * @ parameter: @param wglcanvas:ww canvas Pair Like * @ return type: void; * @ Creator: running chicken silk; * @ creation Time: 2014-12-2 pm 4:42:26; * @throws */private void importelevation (String Elevationfilepath,worldwindowglcanvas Wglcanvas) {Try{file sourcefile = Exampleutil.saveresourcetotempfile (Elevationfilepath, ". tif");// Create an elevation model from the data source: localelevationmodelfinal Localelevationmodel Elevationmodel = new Localelevationmodel (); Elevationmodel.addelevations (sourcefile); Swingutilities.invokelater (New Runnable () {public void run () {//Get WW Current Elevation model globe globe = Worldwindowglcanvas.getmodel ( ). Getglobe (); Elevationmodel Currentelevationmodel = Globe.getelevationmodel ();//Add the newly created elevation model to the globe (or replace the current elevation model) if ( Currentelevationmodel instanceof Compoundelevationmodel) ((Compoundelevationmodel) CurrentElevationModel). Addelevationmodel (Elevationmodel); Elseglobe.setelevationmodel (Elevationmodel);//fly to Current view sector Modelsector = Elevationmodel.getsector (); Exampleutil.gotO (Worldwindowglcanvas, modelsector);});} catch (Exception e) {e.printstacktrace ();}}
Once run, the image and the corresponding Dem file can be loaded to build a three-dimensional scene. Welcome to Message exchange, please leave the mailbox!
World Wind Java Development VII-read the local raster file (image + elevation) to build a three-dimensional scene