Re: Gridded2DSet

Hi Ugo,

I tried to implement your hints:

This is where the array gets created:

    public void makeArray2() {
        double[][] coords = new double[2][east.length];
        coords[0] = new double[east.length];
        coords[1] = new double[north.length];
        for (int i=0;i<coords[0].length;i++) {

        for (int j=0;j<coords[0].length;j++) {
            System.out.println("e "+coords[0][j]);
        for (int j=0;j<coords[1].length;j++) {
            System.out.println("n "+coords[1][j]);

The arrays look similar to the one you mailed me, I even changed my north
and east values in the RealTupleType, because GISterm looked somehow
upside down (spiegelverkehrt?) in the screenshots to ArcView.

I am getting a VisAD Exception which sais, samples are null, is this the
coordinates array with the x and y values or the height array? And how do
I have to specify the height array, does it include the missing values or

Here is the VisAD stuff:

    public void makeSurface() {

        eastValues = RealType.getRealType("eastValues");
        northValues = RealType.getRealType("northValues");
        heightValues = RealType.getRealType("heightValues");
        try {
            //domain_tuple = new RealTupleType(northValues,eastValues);
            domain_tuple = new RealTupleType(eastValues,northValues);
            // Create a FunctionType (domain_tuple -> range_tuple);
            func_en_h = new FunctionType(domain_tuple, heightValues);
            domain_set = new

            // Get the Set samples to facilitate the calculations
            float[][] set_samples = domain_set.getSamples( true );
            // We create another array, with the same number of elements
            // altitude and temperature, but organized as 
            float[][] flat_samples = new float[1][nCols * nRows]; 

            // ...and then we fill our 'flat' array with the generated
            // by looping over NCOLS and NROWS     
            // specifiy height
            for(int c = 0; c < nCols; c++){
                for(int r = 0; r < nRows; r++){     
                    //flat_samples[0][c*nRows+r] = height[c*nRows+r]; 
                    flat_samples[0][c*nRows+r] = heightNaN[c*nRows+r];

            for (int n=0;n<height.length;n++) {
            for(int c = 0; c < nRows; c++){
                for(int r = 0; r < nCols; r++){    
                    // ursprüngliches quadratische x.y.z grid
                    flat_samples[0][c*nRows+r] = height[c*nRows+r]; 
                    // nicht quadratische gridvisadlayer grid
                    //flat_samples[0][c*nCols+r] = height[c*nCols+r];
            // Create a FlatField  
            // Use FlatField(FunctionType type, Set domain_set)    
            vals_ff = new FlatField( func_en_h, domain_set);
            // ...and put the values above into it
            // Note the argument false, meaning that the array won't be
            vals_ff.setSamples( flat_samples , false ); 

            // Create Display and its maps    
            // A 2D display    
            display = new DisplayImplJ3D("display1");    
            // Create the ScalarMaps: latitude to XAxis, longitude to
YAxis and
            // altitude to RGB and temperature to IsoContour
            // Use ScalarMap(ScalarType scalar, DisplayRealType
            eastMap = new ScalarMap( eastValues, Display.YAxis );
            northMap = new ScalarMap( northValues, Display.XAxis );    
            heightMap = new ScalarMap(heightValues,Display.ZAxis);

            eastMap.setRange(-1.0, 1.0);
            northMap.setRange(-1.0, 1.0);
            heightMap.setRange(-1.0, 1.0);

            // Add maps to display
            display.addMap( eastMap );
            display.addMap( northMap );    
            display.addMap( heightMap );

            // Create a data reference and set the FlatField as our data 
            data_ref = new DataReferenceImpl("data_ref");
            data_ref.setData( vals_ff );
            renderer = new DefaultRendererJ3D();
            // Add reference to display
            //display.addReference( data_ref );

        catch (VisADException ve) {
        catch (RemoteException re) {

Thanks for your help Desiree

Desiree Hilbring

Institut fuer Photogrammetrie und Fernerkundung  
Universitaet Karlsruhe, Germany
email: hilbring@xxxxxxxxxxxxxxxxxxxx             
# 0721 6083676                                   

On Thu, 5 Jul 2001, Ugo Taddei wrote:

> Hi Desiree,
> I'm not sure where your NullPointerExeption arises, but I want to make a
> point or 2 about your set, anyway.
> I see you're using a Gridded2DDoubleSet, but with "manifold dimension
> 1". That really means a line in 2D and samples in double precision. I
> know you have a DEM, and this means a surface in 2D (forget for a moment
> that it is 3D, i.e. that you might want to depict your data in 3D; the
> height values will be given by the FlatField, as you know).
> You should use a Gridded2DSet, with manifold dim = 2. That is, 
> Gridded2DSet(MathType type,  float[][] samples, int lengthX, int
> lengthY) 
>          a 2-D set whose topology is a lengthX x lengthY
>          grid, with null errors, CoordinateSystem and Units are
>          defaults from type
> (I'm supposing your x,y coords are floats; if not, stick to a
> Gridded2DDoubleSet, but use the constructor
> Gridded2DDoubleSet(MathType type, double[][] samples, int lengthX, int
> lengthY)
> and not 
> Gridded2DDoubleSet(MathType type, double[][] samples, int lengthX)
> )
> That is, your DEM is organized in a grid, but the interval between
> adjacent points is not necessarily constant (if it were, than you could
> use a Linear2DSet. Your grid has LengthX samples in the x direction and
> LengthY samples in the y direction, i.e., those are the dimensions of
> your grid (your "nCols 9 nRows 5", as one sees from your code).
> The MathType is composed of your eastValues and northValues; just make
> sure you've got them in the right order one constructing the 
> domain_tuple = new RealTupleType(northValues,eastValues);
> I'd personally do the other way around, first east (= x) then north (
> y) but this is arbitrary.
> The "tricky" bit comes in the definition of float[][] samples. In this
> case, it is a float[2][ nCols * nRows ] array. (Remember, when manifold
> dim = 1, you have float[2][ lengthX ], which gives you enough values for
> a line, i.e. a path in 2D space.)
> However, you want a DEM, a surface in 2d space. So you need to input
> LengthX * lengthY (= nRows * nCols) values. These are the
> (northValues,eastValues) coordinates of your DEM and are given by the
> array described above.
> The x-values are in samples[0] and the y-values are in samples[1];
> Let you DEM be
>       3.3   x                x   
> north   2.7       x
>       1.3   x          x     x 
>             0.2  0.3    1.1   1.2
>                    east
> Sampled points are represented bx "x".
> You've got lenX = 3, lenY = 2, and, thus, must input 6 pairs of
> coordinates.
> So, samples is (something like): samples[0]={0.2,1.1,1.2, 0.2,0.3,1.2};
> // east, or x values
>                           and  samples[1]={1.3,1.3,1.3, 3.3,2.7,3.3}; // 
> north, or y values
> Well, to be honest I might have got confused with the ordering of the
> coords. This has not only to do with choosing whether EastValues comes
> before northValues in the RealTupleType, but also to do with the way
> VisAD organises the samples (it is the Fortran way). I'd have to hack a
> bit to get it right (sorry, I'm a mere mortal and errare humanun est ;-)
> so i'll leave that for you to do :-)=)
> The basic ideas here are to choose a Gridded2DSet with lenX and lenY
> parameters, as this will construct the right topology (your DEM surface)
> and to get the samples[0] with the x-values and samples[1] with the
> y-values (or just the other way around ;-)
> Final point is, your gridded set must correspond with a valid grid. Not
> something like you'd find in triangulated irregular network (TIN). For
> that you'd use an Irregular2DSet (and all those Delaunay objects), but I
> reckon, from the list, you know that.
> I truly hope I managed help to clarify the issue a bit.
> Cheers,
> Ugo

  • 2001 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: