Re: orthophoto over dem

Thanks for the answer Bill,

> > 1) what is the actual development status of visad? The update status on
> > the webpage says Wed Feb 15 14:21:41 CST 2006, so I'm full of hope.
> 
> VisAD is very actively developed, and is the
> basis of a number of other systems such as
> Unidata's IDV, SSEC's McIDAS V and UW's VisBio.

Please first of all let me apologize for the rather stupid seeming question,
there was some problem with my email and I got one single message from the
list in two weeks. Then I saw the archives... and I'm very very glad
about what I saw there :-)
Now I browsed throught three years of posts and solved a lot of doubts.
 
> > 2) The real question: I'm trying to overlay a orthophoto over a dem, but
> > after a lot of struggling around and no luck I need some help. I'm
> > talking about maps in metric units and not degree.
> > Is there an example I possibly couldn't find to see how it is done
> > properly?
> > I browsed throught the documentation and the mailinglists, but wasn't
> > able to understand properly, also most of the posts are from 1999, so
> > I found some classes not to be there any more.
> > My last try was that to modify the ShadowImageFunctionTypeJ3D, but that
> > doesn't seem to be the right approach.
> 
> That isn't the right approach. You need to define
> an extension class of visad/CoordinateSystem.java
> that defines the mappings of your photo coordinates
> to and from earth reference coordinates (assuming
> the domain of your dem is in earth coordinates),
> and use this class in the domain Set of your image
> FlatField.
>
> Then you need to put your dem FlatField and your
> image FlatField in a Field[] array, and pass this
> to the FieldImpl.combine() method. This will remap
> them to a common domain (the domain of the first
> FlatField in the array) and return a FlatField
> with range components for both image and dem. Then
> display this with the dem component ScalarMap'ed to
> ZAxis and the image component ScalarMap'ed to RGB.
>
> See Section 4.1 of the VisAD tutorial for an example
> of displaying color over a topography.

Yes, my domain is metric and the resolutions are different. Dem could be
10 meters and photo 1 meter.
So I should define a coordinatesystem for metric and than combine the
fields. I can't find where to use the coordinate system.

In the code below I read the image and gain a flatField, which is
already read in the wrong position (the imageposition 0-2000,0-2000).
I do a resampling which obviously does not what I need, but I assume it
is there that something should happen.

       Set domainSet2 = new Linear2DSet(domain, 1632840.5, 1634840.5,
                (int) (1634840.5 - 1632840.5), 5097079.5, 5099079.5,
                (int) (5099079.5 - 5097079.5));
        imageField.resample(domainSet2);

I have the boundaries, but the field has no translate method.

I'm on the best way of confusion, probably because I'm not enough in it
yet. Can someone please make some order in my thoughts?

Best regards,
Andrea



__________________________________________________________________
public class ImageOverElevation2 {

    private RealType x, y;

    private RealType redType, greenType, blueType;

    private DisplayImpl display;

    private ScalarMap redMap, greenMap, blueMap;

    private RealType easting;

    private RealType northing;

    private RealType elevation;

    private ScalarMap rowMap;

    private ScalarMap colMap;

    private ScalarMap elevationMap;

    public ImageOverElevation2() throws RemoteException,
            VisADException {

        // get the jpg file
        FlatField imageField = null;
        try {
            imageField = (FlatField) new DefaultFamily("dflt").open(new URL(
                    "file:/home/moovida/microsuap/059130_2_1.jpg"));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        // compute ScalarMaps from type components
        FunctionType functionType = (FunctionType) imageField.getType();
        RealTupleType domain = functionType.getDomain();
        RealTupleType range = (RealTupleType) functionType.getRange();

        /*
         * 
********************************************************************************
         *  resample to the right geographic location
         *  
         *  WHERE DO I SET THE COORDINATESYSTEM?
         *  
         * 
********************************************************************************
         */
        Set domainSet2 = new Linear2DSet(domain, 1632840.5, 1634840.5,
                (int) (1634840.5 - 1632840.5), 5097079.5, 5099079.5,
                (int) (5099079.5 - 5097079.5));
        imageField.resample(domainSet2);

        x = (RealType) domain.getComponent(0);
        y = (RealType) domain.getComponent(1);

        redType = (RealType) range.getComponent(0);
        greenType = (RealType) range.getComponent(1);
        blueType = (RealType) range.getComponent(2);

        rowMap = new ScalarMap(x, Display.XAxis);
        colMap = new ScalarMap(y, Display.YAxis);
        redMap = new ScalarMap(redType, Display.Red);
        greenMap = new ScalarMap(greenType, Display.Green);
        blueMap = new ScalarMap(blueType, Display.Blue);

        /*
         * ask for grass raster map path
         */
        String cellFilePath = "/home/moovida/microsuap/trentino/cell/microdem";
        /*
         * create the grasslocation object. It holds the needed info about where
         * everything lives in the GRASS database structure.
         */
        GrassLocation location = new GrassLocation(cellFilePath);
        /*
         * create the reader. It will be able to read the raster row, by row
         */
        GrassRasterByRowReader reader = new GrassRasterByRowReader(location,
                null, new Float(Float.NaN), FloatBuffer.class);
        /*
         * open the reader. Everything is checked and the allocation table of
         * the file is read
         */
        reader.open();

        /*
         * get the read region
         */
        Window dataWindow = reader.getDataWindow();

        int NCOLS = dataWindow.getCols();
        int NROWS = dataWindow.getRows();

        /*
         * get the elevation map
         */
        easting = RealType.getRealType("easting", SI.meter, null);
        northing = RealType.getRealType("northing", SI.meter, null);
        RealTupleType domainTuple = new RealTupleType(easting, northing);
        elevation = RealType.getRealType("elevation", SI.meter, null);
        FunctionType funcDomainElevation = new FunctionType(domainTuple,
                elevation);

        Set domainSet = new Linear2DSet(domainTuple, dataWindow.getWest(),
                dataWindow.getEast(), NCOLS, dataWindow.getSouth(), dataWindow
                        .getNorth(), NROWS);

        float[][] flatSamples = new float[1][NCOLS * NROWS];
        FloatBuffer buf = null;
        int index = NCOLS * NROWS;
        while (reader.hasMoreRows()) {
            buf = (FloatBuffer) reader.getNextRow();
            index = index - NCOLS;
            buf.get(flatSamples[0], index, NCOLS);
        }
        FlatField demField = new FlatField(funcDomainElevation, domainSet);
        demField.setSamples(flatSamples);

        // resample this also to the same set
        demField.resample(domainSet2);

        double[] elevRange = reader.getRange();
        elevationMap = new ScalarMap(elevation, Display.ZAxis);

        display = new DisplayImplJ3D("display");

        // The display
        display.addMap(rowMap);
        display.addMap(colMap);
        display.addMap(elevationMap);
        display.addMap(redMap);
        display.addMap(greenMap);
        display.addMap(blueMap);

        /*
         * set the scale to get a non distroted map
         */
        double xInterval = dataWindow.getEast() - dataWindow.getWest();
        double yInterval = dataWindow.getNorth() - dataWindow.getSouth();
        double zInterval = elevRange[1] - elevRange[0];

        double usedInterval = xInterval;
        if (yInterval > usedInterval)
            usedInterval = yInterval;
        if (zInterval > usedInterval)
            usedInterval = zInterval;

        rowMap.setRange(dataWindow.getWest(), dataWindow.getWest()
                + usedInterval);
        colMap.setRange(dataWindow.getSouth(), dataWindow.getSouth()
                + usedInterval);
        elevationMap.setRange(elevRange[0], elevRange[0] + usedInterval);

        /*
         *  Create Display and its maps
         */
        // Get display's graphics mode control draw scales
        GraphicsModeControl dispGMC = (GraphicsModeControl) display
                .getGraphicsModeControl();

        dispGMC.setScaleEnable(true);

        /*
         * now create the merged flatfield
         */
        Field endField = FieldImpl
                .combine(new Field[] { demField, imageField });

        DataReferenceImpl dataReference = new DataReferenceImpl("dataref");
        dataReference.setData(endField);
        display.addReference(dataReference);

        JFrame jframe = new JFrame("VisAD Tutorial example 5_09");
        jframe.getContentPane().setLayout(new BorderLayout());
        jframe.getContentPane()
                .add(display.getComponent(), BorderLayout.CENTER);

        // Set window size and make it visible

        jframe.setSize(800, 800);
        jframe.setVisible(true);

    }

    public static void main(String[] args) throws RemoteException,
            VisADException {
        new ImageOverElevation2();
    }

} 


==============================================================================
To unsubscribe visad, visit:
http://www.unidata.ucar.edu/mailing-list-delete-form.html
==============================================================================


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