Re: shifting a unionSet or DataReferenceImpl

  • Subject: Re: shifting a unionSet or DataReferenceImpl
  • From: ncubukcu <ncubukcu@xxxxxxxxx>
  • Date: Wed, 23 Aug 2006 13:34:52 -0400
Hi Bill
I thought about your suggestion below but I couldn't proceed without any example. So if you have an example please send me a snippet. Most of the field variables associated with unionSet are package protected so it's not simple to play with ranges. I shifted my data for now untill I figure out some other way. Also I post part of my code below.. Please all send me any comment/suggestions you might have.. This code display precipitation data covering North America but it has a global base map to goes with it. As you see in the code, I use BufferedImage.subimage method to get North America out of global image. Why do I do this? ..because given a global base map, I couldn't get a sub region using available methods of BaseMapAdapter or ShapefileAdapter classes. With 4 months of visad exploration this is all I have :-)

//setting tuple properties
CoordinateSystem cs = RealTupleType.LatitudeLongitudeTuple.getCoordinateSystem();
latitude = RealType.getRealType(yLabel);
longitude = RealType.getRealType(xLabel);
RealTupleType domainTuple = new RealTupleType(RealType.Longitude,RealType.Latitude,cs,null);

//domainSet is created for the data to be displayed. latlon holds lat/lon of data grids visad.Set domainSet = new Gridded2DSet((RealTupleType)domainTuple,latlon,nlon,nlat);

FunctionType contourFunction = new FunctionType(domainTuple,contourField);
FunctionType shadedFunction = new FunctionType(domainTuple,shadedField);

FlatField contourFlatField = new FlatField(contourFunction,domainSet);

FlatField shadedFlatField = new FlatField(shadedFunction,domainSet);

//use either a shapefile or a McIDAS file for map..
//ShapefileAdapter bma = new ShapefileAdapter("/xstor1/ShapeFiles/World/world.shp"); //ShapefileAdapter bma = new ShapefileAdapter("/xstor1/ShapeFiles/World/admin98/admin98.shp");
 BaseMapAdapter bma =  new BaseMapAdapter("/home/fcst/mcidas/OUTLSUPW");

// Create the ScalarMaps: column to XAxis, row to YAxis and pixel to RGB
// Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar)
pixMap = new ScalarMap( shadedField,  Display.RGB );
contMap = new ScalarMap( contourField, Display.IsoContour );
colMap = new ScalarMap( longitude, Display.XAxis);
rowMap = new ScalarMap( latitude,  Display.YAxis);

//Add scalar maps to display
display.addMap( colMap );
display.addMap( rowMap );
display.addMap( contMap );
display.addMap( pixMap );

// The ContourControl
// Note that we get the control from the IsoContour map
ContourControl isoControl = (ContourControl) contMap.getControl();
if(base != -99 || highValue != -999 || lowValue != -999 || interval != -999){
   // ...and set the lines with the method
   isoControl.setContourInterval(interval, lowValue, highValue, base);

// Create a data reference and set the FlatField as our data
DataReferenceImpl contourDataRef = new DataReferenceImpl("contour");
DataReferenceImpl shadedDataRef = new DataReferenceImpl("shaded");
DataReferenceImpl atlasDataRef = new DataReferenceImpl("map");

shadedDataRef.setData(shadedFlatField );
UnionSet bma1= bma.getData();

// Add references to display

//Set the aspect ratio.. xSize ySize are the display window dimensions. magFactor =3 seem to cover entire display area ProjectionControlJ2D projectionControl = (ProjectionControlJ2D)display.getProjectionControl();
double xRange =magFactor*(double) ((double)xSize/Math.max(xSize,ySize));
double yRange= magFactor*(double) ((double)ySize/Math.max(xSize,ySize));
projectionControl.setAspect(new double[] {xRange,yRange});

//these vars get me the sub region I want out of a global image. The numbers 20 and 60 are there to get some padding around the image // this works only if I use magFactor =3 and the basemap is global. Otherwise get the entire image
int xx1 = (int)(xlow*(xSize/2)+xSize/2);
int xx2 = (int)(xhigh*(xSize/2)+xSize/2)+20;
int yy1 = ySize-(int)(ylow*(ySize/2)+ySize/2);
int yy2 = ySize-(int)(yhigh*(ySize/2)+ySize/2)-60;
//finally get subimage
BufferedImage dd = display.getImage(true).getSubimage(xx1,yy2,(xx2-xx1),(yy1-yy2));

Bill Hibbard wrote:
Hi Nihat,

Someone else may come up with an easier answer, but
I'd write a method to essentially clone the UnionSet
except for the numerical adjustment to longitude
values. In the time it would take to dream up
something clever, you could write this little method
(assuming the Sets in your UnionSet are all of the
same class).

Good luck,

On Mon, 21 Aug 2006, ncubukcu wrote:

What is the easiest way to shift a base map? I read in a shapefile which
takes 180deg longitude as starting point whereas all my data starts from
0deg longitude. So I need to shift either my data fields or the base
map. (I would prefer the basemap) This is what I get otherwise: Thanks a
lot in advance...

To unsubscribe visad, visit: