This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hi Shawn: This is, as they say, non-trivial. Abstractly you are working with two invertible transformations: latLon <- T1 -> Image Coords <- T2 -> screen coordinates The Image coordinates are either Lat/Lon or projection coordinates. In the latter case, T1 is a complicated highly non-linear function, eg Lambert conformal. In our source jar, you will find implementations in ucar.unidata.geoloc.projection package. T2 is always affine, and we use java.awt.geom.AffineTransform, which works well with the java.awt.Graphics2D stuff that does the actual screen drawing. By setting the correct AffineTransform on the graphics object, you can basically work in Image Coordinates, aka "User Coordinates" when you draw the Image. You only need the Lat/Lon when you want to display the coordinates based on the mouse position. The ucar.nc2.ui.grid package is a Swing implementation that does all this. Its pretty complicated, and of course, not well documented. Have a look at GridRenderer if you're brave. Shawn Hampton wrote:
John, I am hoping that you can give me a leg up on dealing with lat/lon coordinate conversions. What I'm trying to do is this: show an image on the screen, say a map of the US showing radar data. I'd like to be able to be able to view the lat/lon of the position under the cursor as the mouse passes over it. So, I need to convert (x,y) to (lat,lon) for a fixed image. I have the code from the netcdf viewer, and I'm puzzling through the various classes. I have an example working using LatLonProjection, but the data makes no sense (lat is almost always 90 no matter where the mouse moves). I'm sure that I'm missing some steps, for one I'm not setting the lat/lon coordinates of the map I'm using. I'm also fairly sure that there are many steps that I'm missing that I have no idea about. Thanks for your time, Shawn ------------------------------------------------------------------------