How to find lat/lon bounding box for a single specific CELL in a NetCDF GridDatatype?

369 Views Asked by At

I'm attempting to render the data in a NetCDF GridDatatype (specifically, GOES16-ABI-L2-ACMC) to accurately scaled and cropped bitmaps suitable for use by Google Maps as TileOverlays.

Somehow, I need to find the lat/lon bounds (say, the coordinates of its northwest and southeast edges, its southwest and northeast edges, or even just the north, south, east, and west lat/lon extents) for individual cells in the Grid.

For example, let's suppose that the Grid has 1500x2500 cells, that "gcs" is its GridCoordSystem object, and calling gcs.getLatLon(1528,853) returns the LatLonPoint of the cell's center: (27.6659, -80.8470)

Now... let's suppose the same cell represents a rectangular area bounded by (27.66594, -80.84704) to (27.66586, -80.84696) [those values are completely made up]. How would I go about obtaining those coordinates for a specific cell?

At first, I assumed there might be a function in GridCoordSystem like getLatLonBoundingBox(x,y)... but as far as I can tell, none of the methods in GridCoordSystem that return something like a bounding box allow you to specify a particular cell.


Background Info

You don't necessarily have to read the remainder of this to answer the question, but it might be helpful in case I'm going about solving the problem in completely the wrong way.

My present strategy for rendering the tiles is something like this:

  1. When Google Maps asks me to prepare a Tile for (x,y,zoom), determine the (lat,lon) extents of the tile at that zoomlevel
  2. Determine the width and height of the tile in degrees. At zoomlevel=9, I consistently get a width of 0.703125 degrees, but inexplicably seem to end up with one of three possible heights that vary from Tile to Tile: 0.6172505994585009, 0.6208525991750236, and 0.6135982805271851.
  3. Create a bitmap that's 10000 times the degree-width/height. Using #2 as an example, this might mean creating a bitmap that's 7031x6173 pixels.
  4. Determine the range of cells whose center points allegedly fall within the bounds of the Tile, then expand the range by 1 in all directions.
  5. Foreach cell within the range, determine its extents, subtract the coordinates of the Tile's northwest corner from both, and render a rectangle (with clipping) to the bitmap.
  6. Resize the bitmap down to 256x256, wrap it into a Tile, and return it to Google Maps.

Since this strategy maintains a 1:1 mapping between (lon,lat) coordinates in the grid to (x,y) coordinates in the bitmap (shifting the Tile's geographic origin to match the bitmap's (0,0) origin), my scaling problem is basically solved.

Note that I'm using NetCDF-java with Android, so any library functionality in NetCDF that requires Java AWT won't work. I'm not necessarily averse to contributing to NetCDF-java's Android functionality by adding support for working with Android graphics, just because I personally have longer-term interests in using NetCDF with Android for a large variety of future apps, but I'd probably need some closer guidance from someone already involved with its development to get me started and pointed in the right direction that would be better provided by some other means than SO if I were to do that.

0

There are 0 best solutions below