toolkits for geoscience visualization dave nadeau, john moreland sdsc
TRANSCRIPT
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
Tools for custom visualization
• Lots of great GeoVis tools out there
• What if you need something custom?
– Convert to/from a custom file format
– Analyze and filter data
– Custom visualization and interaction
• Let’s look at some toolkits for building tools
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
Tools for custom visualization
• Java Image I/O
• GeoTIFF
• Java OpenGL
• GeoTools
• WorldWind
• NetCDF
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
Java Image I/O
• Sun Java toolkit for image file read/write
– Many formats
• BMP, GIF, PNG, JPEG, JPEG2000, TIFF
– Also use advanced imaging toolkit for filtering
– Standard part of Java
http://java.sun.com/
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
Java Image I/O example
1. Get an image reader:ImageInputStream stream =
ImageIO.createImageInputStream(file);
Iterator<ImageReader> it =
ImageIO.getImageReaders(stream);
ImageReader reader = it.next();
reader.setInput(stream);
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
Java Image I/O example
2. Read the image:
3. Display the image:
BufferedImage image = reader.read(0);
ImageIcon icon = new ImageIcon(image);Jlabel label = new Jlabel(icon);frame.add(label,BorderLayout.CENTER);
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
Java Image I/O example
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
GeoTIFF
• TIFF image format with Geo tags
– Coordinate space, position, extent
– Readable by TIFF tools (Java Image I/O)
– GeoTIFF metadata adapter understands tags
• Open Source
http://remotesensing.org/geotiff/
http://gelbin.org/code/
• TIFF image format with Geo tags
– Coordinate space, position, extent
– Readable by TIFF tools (Java Image I/O)
– GeoTIFF metadata adapter understands tags
• Open Source
http://remotesensing.org/geotiff/
http://gelbin.org/code/
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
GeoTIFF example
1. Get a TIFF image reader (same!):ImageInputStream stream =
ImageIO.createImageInputStream(file);
Iterator<ImageReader> it =
ImageIO.getImageReaders(stream);
ImageReader reader = it.next();
reader.setInput(stream);
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
GeoTIFF example
2. Read the image (same!): :
3. Display the image (same!): :
BufferedImage image = reader.read(0);
ImageIcon icon = new ImageIcon(image);Jlabel label = new Jlabel(icon);frame.add(label,BorderLayout.CENTER);
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
GeoTIFF example
4. Get the GeoTIFF metadata:IIOMetadata meta = reader.getImageMetadata(0);
GeoTiffIIOMetadataAdapter ameta =
new GeoTiffIIOMetadataAdapter(meta);
String value = ameta.getGeoKey(key);
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
GeoTIFF example
• Available keys:– GTModelTypeGeoKey
– GTRasterTypeGeoKey
– GTCitationGeoKey
– GeographicTypeGeoKey
– GeogCitationGeoKey
– GeogGeodeticDatumGeoKey
– GeogPrimeMeridianGeoKey
– GeogPrimeMeridianLongGeoKey
– GeogLinearUnitsGeoKey
– GeogLinearUnitSizeGeoKey
– GeogAngularUnitsGeoKey
– GeogAngularUnitsSizeGeoKey
– GeogEllipsoidGeoKey
– GeogSemiMajorAxisGeoKey
– GeogSemiMinorAxisGeoKey
– GeogInvFlatteningGeoKey
– GeogAzimuthUnitsGeoKey
– ProjCenterLongGeoKey
– ProjCenterLatGeoKey
– ProjCenterEastingGeoKey
– ProjCenterNorthingGeoKey
– ProjScaleAtNatOriginGeoKey
– ProjScaleAtCenterGeoKey
– ProjAzimuthAngleGeoKey
– ProjStraightVertPoleLongGeoKey
– VerticalCSTypeGeoKey
– VerticalCitationGeoKey
– VerticalDatumGeoKey
– VerticalUnitsGeoKey
– ProjectedCSTypeGeoKey
– PCSCitationGeoKey
– ProjectionGeoKey
– ProjCoordTransGeoKey
– ProjLinearUnitsGeoKey
– ProjLinearUnitSizeGeoKey
– ProjStdParallel1GeoKey
– ProjStdParallel2GeoKey
– ProjNatOriginLongGeoKey
– ProjNatOriginLatGeoKey
– ProjFalseEastingGeoKey
– ProjFalseNorthingGeoKey
– ProjFalseOriginLongGeoKey
– ProjFalseOriginLatGeoKey
– ProjFalseOriginEastingGeoKey
– ProjFalseOriginNorthingGeoKey
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
GeoTIFF example
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
Java OpenGL (JOGL)
• Sun Java toolkit for OpenGL 3D drawing
– Uses native OpenGL to 3D graphics hardware
– Integrates with rest of Java toolkit
– Not part of Java distribution, but easily added
https://jogl.dev.java.net/
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
Java OpenGL (JOGL)
• Draw points, lines, polygons
• Control point & line size, line patterns,
polygon fill, color, texture
• Control 3D lighting
• All done at hardware speeds
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
JOGL example: polygons
1. Set a drawing color:
2. Draw a polygon:
gl.glColor3f(r,g,b);
gl.glBegin(GL.GL_POLYGON);
gl.glVertex3f(x,y,z);
...
gl.glEnd();
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
JOGL example: polygons
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
1. Create texture from graphics context:
2. Draw shape using texture:gl.glTexCoord2f(s,t);
gl.glVertex3f(x,y,z);
Texture tex= TextureIO.newTexture(file,false);
gl.glEnable(GL.GL_TEXTURE_2D);
tex.bind();
tex.enable();
JOGL example: images
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
JOGL example: images
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
GeoTools
• Toolkit implementing OGC GeoAPI
– Read/write many file formats
– Features, images, geometry, coord spaces
– WMS, WFS
– Open source
http://geotools.codehaus.org/
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
GeoTools example: Shapefile
1. Create a data store to read a file:
2. Get the first feature source:
DataStore dataStore =
FileDataStoreFinder.getDataStore(url);
String[] names = dataStore.getTypeNames();
FeatureSource source =
dataStore.getFeatureSource(names[0]);
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
GeoTools example: Shapefile
3. Create a map context:
4. Add feature source to context:
CoordinateReferenceSystem crs =
CRS.decode(“EPSG:4326”);
DefaultMapContext context =
new DefaultMapContext(crs);
context.addLayer(source,new BasicLineStyle());
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
GeoTools example: Shapefile
5. Draw the map context:MapContextPanel panel = new MapContextPanel();
panel.setContext(context);
frame.add(panel,BorderLayout.CENTER);
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
GeoTools example: Shapefile
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
NetCDF
• Network Common Data Form
– File format & toolkit to read/write multidimensional data (eg: Volumes)
• Support for many programming languages (such as Java)
– University Corporation for Atmospheric Research (UCAR) / UNAVCO
http://www.unidata.ucar.edu/software/netcdf/
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
NetCDF
• Variables hold multidimensional data values
– char, byte, short, int, float, double
• Attributes hold meta-data
– Units, names, scale factors, etc.
– Attributes can be global or associated with each
variable
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
NetcdfFile ncfile = NetcdfFile.open(file);
List variables = ncfile.getVariables();
Variable var = (Variable)variables.get(i);
Array array = var.read();
NetCDF example
1. Open a NetCDF file:
2. Get data variables:
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
NetCDF example
3. Get variable dimensions:
4. Get voxels:
int rank = var.getRank();
int[] shape = array.getShape();
double voxel =
((ArrayDouble.D3)array).get(i,j,k);
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
NetCDF example
5. Get global or variable attributes:
6. Get attribute type and value:
List glist = ncfile.getGlobalAttributes();
List vlist = var.getAttributes();
Attribute attrib = vlist.get(i);
DataType type = attrib.getDataType();
Number num = attrib.getNumericValue(i);
String str = attrib.getStringValue(i);
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
NetCDF example
7. Build an image:BufferedImage image = new BufferedImage(w,h);
int gray = (int)(voxel * 255);
int rgba = (gray<<24) | (gray<<16) ...;
image.setRGB(row,col,rgba);
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
NetCDF example
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
NASA World Wind (NWW)
• “Open-Source Google Earth”
– Toolkit (modular library for building applications)
• Versions for .NET (Windows) and Java (Mac, Windows, UNIX)
– Tiled Terrain and Images, WMS, Plug-in Layers, 3D Rendering
(JOGL)
– NASA / ARC (Ames Research Center)
http://worldwind.arc.nasa.gov/
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
1. Create a canvas:
2. Set a data model:
3. Add canvas to your application interface:
WorldWindGLCanvas c = new WorldWindGLCanvas();
c.setModel( new BasicModel() );
NWW HelloWorldWind example
frame.add( c );
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
NWW HelloWorldWind output
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
1. Create a surface image:
2. Make it semi-transparent:
3. Add the image to a renderable layer:
SurfaceImage si = new SurfaceImage( “Map.png”, Sector.fromDegrees(35, 45, -115, -95) );
si.setOpacity( 0.7 );
NWW LayerDemo example
RenderableLayer rl = new RenderableLayer();
rl.addRenderable( si );
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
4. Get the LayerList from the model:
5. Add our image layer:
LayerList layers = model.getLayers( );
layers.add( layers.size(), rl );
NWW LayerDemo example
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
NWW LayerDemo output
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
1. Create a WMS Layer:
2. Get the LayerList from the model:
3. Add the WMS layer:
OpenStreetMapLayer os=newOpenStreetMapLayer();
LayerList layers = model.getLayers( );
NWW WmsDemo example
layers.add( layers.size(), os );
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
NWW WmsDemo output
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
Conclusions
• Lot’s of good Java toolkits available…– Image I/O Sun Java Image I/O
– Image filtering Sun Java Advanced Imaging
– GeoTIFF GeoTools, WorldWind, GeoTIFF adapter
– Movie I/O Sun Java Media Framework
– Shapefile I/O GeoTools
– Volume I/O NetCDF, HDF
– Metadata Sun Java Metadata Interface
– GUIs Sun JDK, SwingX
– 3D Sun JOGL, Sun Java3D
– Projections GeoTools, SRI GeoTransform
– GML, WFS GeoTools
– WMS GeoTools, WorldWind
– Net protocols Sun JDK, Apache Commons net, Apache HTTP components
– Web protocols Sun Metro, Apache Web Services
– … lots more …
Cyberinfrastructure Summer Institute for GeoscientistsCyberinfrastructure Summer Institute for Geoscientists
Open Earth Framework
• Services architecture
– Server-side data management, filtering, pre-processing
– Client-side presentation, interaction
– Java toolkit
• Integrates other toolkits
• Adds missing GeoVis functionality
• In development…