Re: Coloring Data using MetApps ShapefileAdapter

Hi Bill/Luke-

Bill Hibbard wrote:

In visad/DelaunayCustom.java the method:

  public static Irregular2DSet fill(Gridded2DSet set)

produces an Irregular2DSet for the interior of the boundary
defined by the argument 'Gridded2DSet set', which must have
manifold dimension = 1. If the ShapefileAdapter returns a
UnionSet of many Gridded2DSets, then you must extract the
one for the boundary of interest, or even combine multiple
Gridded2DSets into one for the entire boundary.

I was going to suggest the same thing.  However, many
of the Gridded2DSets that you get are labeled as
"self intersecting" so you cannot just easily fill all
the boundaries.  The Austrailian Bureau of Meteorology
has generated some nice maps of the Australian region
using a similar technique.  Perhaps they have suggestions
on how best to approach this.

I've attached a small program that shows how this could
be done (but doesn't do the job).  It uses the ucar.visad.MapFamily
class, but you could substitute the ShapefileAdapter for
testing.  I used the Countries.zip Shapefile in the
auxdata.jar JAR file distributed with the IDV.

Don
*************************************************************
Don Murray                               UCAR Unidata Program
dmurray@xxxxxxxxxxxxxxxx                        P.O. Box 3000
(303) 497-8628                              Boulder, CO 80307
http://www.unidata.ucar.edu/staff/donm
*************************************************************

import visad.*;
import javax.swing.*;
import java.awt.event.*;
import visad.data.mcidas.*;
import ucar.visad.MapFamily;
import visad.java2d.*;
import visad.java3d.*;
import java.util.Hashtable;
import java.util.Vector;
import java.net.URL;

public class MapTest extends JFrame
{
    public static void main(String[] args)
        throws Exception
    {
        MapTest test = 
            new MapTest((args.length > 0) ? args[0] : null);
        test.pack();
        test.setVisible(true);
    }

    public MapTest(String source)
        throws Exception
    {
        super("Sample Map Display");
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) { System.exit(0); }
        });

        DisplayImpl display = 
            //new DisplayImplJ2D("display");
            new DisplayImplJ3D("display", new TwoDDisplayRendererJ3D());
        display.getGraphicsModeControl().setScaleEnable(true);
        display.getProjectionControl().setAspectCartesian(
            new double[] {1.0, .5, 1.0} );
        ScalarMap latMap = new ScalarMap(RealType.Latitude, Display.YAxis);
        latMap.setRange(-90, 90);
        AxisScale latAxis = latMap.getAxisScale();
        latAxis.setMajorTickSpacing(30);
        latAxis.setMinorTickSpacing(10);
        latAxis.setTitle("");
        Hashtable latTable = new Hashtable();
        latTable.put(new Double(-90), "90S");
        latTable.put(new Double(-60), "60S");
        latTable.put(new Double(-30), "30S");
        latTable.put(new Double(0), "Eq");
        latTable.put(new Double(90), "90N");
        latTable.put(new Double(60), "60N");
        latTable.put(new Double(30), "30N");
        latAxis.setLabelTable(latTable);
        latAxis.setTickOrientation(latAxis.SECONDARY);
        latAxis.setSnapToBox(true);
        ScalarMap lonMap = new ScalarMap(RealType.Longitude, Display.XAxis);
        lonMap.setRange(-180, 180);
        AxisScale lonAxis = lonMap.getAxisScale();
        lonAxis.setMajorTickSpacing(45);
        lonAxis.setMinorTickSpacing(15);
        Hashtable lonTable = new Hashtable();
        lonTable.put(new Double(-180), "180W");
        lonTable.put(new Double(-135), "135W");
        lonTable.put(new Double(-90), "90W");
        lonTable.put(new Double(-45), "45W");
        lonTable.put(new Double(0), "0");
        lonTable.put(new Double(180), "180E");
        lonTable.put(new Double(135), "135E");
        lonTable.put(new Double(90), "90E");
        lonTable.put(new Double(45), "45E");
        lonAxis.setLabelTable(lonTable);
        lonAxis.setTickOrientation(lonAxis.SECONDARY);
        lonAxis.setSnapToBox(true);
        lonAxis.setTitle("");
        display.addMap(latMap);
        display.addMap(lonMap);
        MapFamily mf = new MapFamily("Maps");
        UnionSet mapLines = 
            (UnionSet) mf.open( (source == null) 
                                     ? "OUTLSUPW"
                                     : source);
        DataReferenceImpl ref = new DataReferenceImpl("mapRef");
        DataReferenceImpl ref2 = new DataReferenceImpl("mapRef2");
        ref2.setData(mapLines);
        display.addReference(ref2);
        SampledSet[] sets = mapLines.getSets();
        System.out.println("map has " + sets.length + "segments");
        Vector v = new Vector();
        for (int i = 0; i < sets.length; i++) {
          try {
            Irregular2DSet fill = DelaunayCustom.fill((Gridded2DSet) sets[i]);
            if (!(fill == null)) v.add(fill);
          } catch (Exception e) {
            System.out.println("Couldn't compute fill for set " + i);
            continue;
          }
        }
        UnionSet newSet = 
           new UnionSet(
               (Irregular2DSet[]) v.toArray(new Irregular2DSet[v.size()]));
        ref.setData(newSet);
        display.addReference(ref, new ConstantMap[] {
                                  new ConstantMap(.5, Display.Red),
                                  new ConstantMap(0, Display.Blue),
                                  new ConstantMap(0, Display.Green)});
        getContentPane().add(display.getComponent());
    }
}