private static void validateIndices(GridCoordSystem coordSystem, double lat, double lon, int[] expectedIndices, boolean bounded) throws Exception { int[] indices = (bounded) ? coordSystem.findXYindexFromLatLonBounded(lat, lon, null) : coordSystem.findXYindexFromLatLon(lat, lon, null); if (indices[0] != expectedIndices[0]) { throw new Exception("(latitude " + lat + ", longitude " + lon + ") expected index[0]==" + expectedIndices[0] + "; received index[0]==" + indices[0]); } if (indices[1] != expectedIndices[1]) { throw new Exception("(latitude " + lat + ", longitude " + lon + ") expected index[1]==" + expectedIndices[1] + "; received index[1]==" + indices[1]); } }
int[] xy = gcs.findXYindexFromLatLonBounded(location.getLatitude(), location.getLongitude(), null);
int[] xy = gcs.findXYindexFromLatLonBounded(location.getLatitude(), location.getLongitude(), null);
/** * Test GridCoordSystem.findXYindexFromLatLonBounded() * @throws IOException */ @Test public void checkGridCoordSystem_findXYindexFromLatLonBounded() throws IOException { GridDataset gd = GridDataset.open( datasetLocation ); GridDatatype hsGrid = gd.findGridDatatype( "hs" ); GridCoordSystem coordSys = hsGrid.getCoordinateSystem(); CalendarDate date = coordSys.getTimeAxis1D().getCalendarDate(0); int[] xy = coordSys.findXYindexFromLatLonBounded( lat, lon, null ); assertEquals( i, xy[0] ); assertEquals( j, xy[1] ); GridAsPointDataset hsGridAsPoint = new GridAsPointDataset( Collections.singletonList( hsGrid )); GridAsPointDataset.Point point = hsGridAsPoint.readData( hsGrid, date, lat, lon ); assertEquals( lat, point.lat, 0.001 ); assertEquals( lon, point.lon, 0.001 ); } }
int[] xy = gcs.findXYindexFromLatLonBounded(location.getLatitude(), location.getLongitude(), null);