20000811: Simple way to plot a Number?

>From: John F Moses <jfmoses@xxxxxxxxxxxxxxxxxxxx>
>Organization: Computer Sciences Corp.
>Keywords: 200008112003.e7BK3tN11187

Hi John-

>i'm trying to simple way to plot a real number at a given lat, lon location
>in the display.  i've look at the text plot example, but can't find my way
>through the data types.  can someone help me by pointing to an example, or
>code snipet?

Basically, you need to map the MathType of your Real or Text object
to Display.Text.

If you have a RealTuple like (lat, lon, altitude) where the MathTypes
of each are RealType.Latitude, RealType.Longitude, RealType.Altitude,
you could just map lat->Display.YAxis, lon->Display.XAxis and 
altitude->Display.Text, add the tuple to your datareference and the
value for altitude should plot at the lat/lon point in your display.

I've attached a file TextPlot.java which will plot a station elevation
at a given lat/lon point. If you pass an arguement to the command line
(any old argument will do), it will plot the station name instead. This
uses NamedLocationTuple in visad.georef which is a tuple of (name, lat,
lon, alt) and is useful for encapsulating a station location.

>being stuck on a friday afternoon, any help would be much appriciated,

My first advice would be to quit and go drink beer, but try out
TextPlot instead as a second option.

Don Murray                               UCAR Unidata Program
dmurray@xxxxxxxxxxxxxxxx                        P.O. Box 3000
(303) 497-8628                              Boulder, CO 80307
Unidata WWW Server               http://www.unidata.ucar.edu/
McIDAS Demonstration Machine  http://mcdemo.unidata.ucar.edu/
import visad.*;
import visad.georef.*;
import visad.java3d.*;
import visad.data.mcidas.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.URL;

public class TextPlot
    public static void main(String[] args)
        throws Exception
        DisplayImpl display = 
            new DisplayImplJ3D("Station Name Plots", 
                new TwoDDisplayRendererJ3D());
        // turn the box off so it won't be confused with the map lines

        // create the stations
        NamedLocationTuple point1 = 
            new NamedLocationTuple("Denver", 39.8, -104.6, 1656);
        NamedLocationTuple point2 = 
            new NamedLocationTuple("Pueblo", 38.3, -104.5, 1439);
        NamedLocationTuple point3 = 
            new NamedLocationTuple("Grand Junction", 39.2, -108.5, 1439);

        // create the ScalarMaps (lat-Y, lon-X, alt/name -> text)
        ScalarMap latMap = new ScalarMap(RealType.Latitude, Display.YAxis);
        ScalarMap lonMap = new ScalarMap(RealType.Longitude, Display.XAxis);
        // zoom in over colorado
        latMap.setRange(37, 42);
        lonMap.setRange(-109, -104);
        // set up the mapping to text - use Altitude if no args, otherwise name
        ScalarMap textMap;
        if (args.length == 0)
            textMap = new ScalarMap(RealType.Altitude, Display.Text);
            textMap = 
                new ScalarMap(NamedLocationTuple.IDENTIFIER_TYPE, Display.Text);

        // set some attributes of the displayed text
        TextControl textControl = (TextControl) textMap.getControl();
        textControl.setSize(1.5);       // set the text size
        textControl.setCenter(true);    // center on the LatLonPoint
        textControl.setFont(new Font("SansSerif", Font.PLAIN, 18));

        // Create a station table with one record for each station
        RealType record = new RealType("record");  // Domain type
        FunctionType tableType
            new FunctionType(record, point1.getType());  
        Integer1DSet recordSet = 
            new Integer1DSet(record, 3); // domain the size of the # of stations
        FieldImpl stationTable = 
            new FieldImpl(tableType, recordSet);  //make the table
        // set the stations in the table
        stationTable.setSample(0, point1);
        stationTable.setSample(1, point2);
        stationTable.setSample(2, point3);

        // add the stations to the display
        DataReference tableRef = new DataReferenceImpl("stations");

        // add a map
        DataReference mapRef = new DataReferenceImpl("maplines");
            BaseMapAdapter bma = 
                new BaseMapAdapter(
                    new URL("ftp://www.ssec.wisc.edu/pub/visad-2.0/OUTLUSAM";));
        catch (Exception exp) {}  // don't add to display if we can't get map

        // something to display it with
        JFrame frame = new JFrame("Text Display");
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e)
            { System.exit(0); }