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]); } }
public static void main(String[] args) throws IOException { GridDataset gds = ucar.nc2.dt.grid.GridDataset.open("Q:/cdmUnitTest/transforms/Eumetsat.VerticalPerspective.grb"); GridDatatype grid = gds.findGridDatatype( "Pixel_scene_type"); GridCoordSystem gcs = grid.getCoordinateSystem(); double lat = 8.0; double lon = 21.0; // find the x,y point for a specific lat/lon position int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); // xy[0] = x, xy[1] = y // read the data at that lat, lon a specific t and z value Array data = grid.readDataSlice(0, 0, xy[1], xy[0]); // note t, z, y, x double val = data.getDouble(0); System.out.printf("Value at %f %f == %f%n", lat, lon, val); }
public static void main(String[] args) throws IOException { GridDataset gds = ucar.nc2.dt.grid.GridDataset.open("Q:/cdmUnitTest/transforms/Eumetsat.VerticalPerspective.grb"); GridDatatype grid = gds.findGridDatatype( "Pixel_scene_type"); GridCoordSystem gcs = grid.getCoordinateSystem(); double lat = 8.0; double lon = 21.0; // find the x,y point for a specific lat/lon position int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); // xy[0] = x, xy[1] = y // read the data at that lat, lon a specific t and z value Array data = grid.readDataSlice(0, 0, xy[1], xy[0]); // note t, z, y, x double val = data.getDouble(0); System.out.printf("Value at %f %f == %f%n", lat, lon, val); }
public static void main(String[] args) throws IOException { GridDataset gds = ucar.nc2.dt.grid.GridDataset.open("Q:/cdmUnitTest/transforms/Eumetsat.VerticalPerspective.grb"); GridDatatype grid = gds.findGridDatatype( "Pixel_scene_type"); GridCoordSystem gcs = grid.getCoordinateSystem(); double lat = 8.0; double lon = 21.0; // find the x,y point for a specific lat/lon position int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); // xy[0] = x, xy[1] = y // read the data at that lat, lon a specific t and z value Array data = grid.readDataSlice(0, 0, xy[1], xy[0]); // note t, z, y, x double val = data.getDouble(0); System.out.printf("Value at %f %f == %f%n", lat, lon, val); }
@Test @Category(NeedsCdmUnitTest.class) public void testCoordExtract() throws IOException { try (ucar.nc2.dt.grid.GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "formats/grib2/coordExtract/TestCoordExtract.grib2")) { System.out.printf("%s%n", dataset.getLocation()); GeoGrid grid = dataset.findGridByName("Convective_inhibition_surface"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 3; System.out.printf("%s%n", gcs); int result[] = gcs.findXYindexFromLatLon(41.3669944444, -91.140575, null); System.out.printf("%d %d %n", result[0], result[1]); assert result[0] == 538; assert result[1] == 97; } }
public Point readData(GridDatatype grid, CalendarDate date, double lat, double lon) throws java.io.IOException { GridCoordSystem gcs = grid.getCoordinateSystem(); //CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); //int tidx = timeAxis.findTimeIndexFromCalendarDate(date); int tidx =-1; //Date may be null if the grid does not have time axis if(date != null) tidx = findTimeIndexForCalendarDate(gcs, date); //int[] xy = gcs.findXYindexFromLatLonBounded(lat, lon, null); int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); Array data = grid.readDataSlice(tidx, -1, xy[1], xy[0]); // use actual grid midpoint LatLonPoint latlon = gcs.getLatLon(xy[0], xy[1]); Point p = new Point(); p.lat = latlon.getLatitude(); p.lon = latlon.getLongitude(); p.dataValue = data.getDouble( data.getIndex()); return p; }
public Point readData(GridDatatype grid, CalendarDate date, double lat, double lon) throws java.io.IOException { GridCoordSystem gcs = grid.getCoordinateSystem(); //CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); //int tidx = timeAxis.findTimeIndexFromCalendarDate(date); int tidx =-1; //Date may be null if the grid does not have time axis if(date != null) tidx = findTimeIndexForCalendarDate(gcs, date); //int[] xy = gcs.findXYindexFromLatLonBounded(lat, lon, null); int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); Array data = grid.readDataSlice(tidx, -1, xy[1], xy[0]); // use actual grid midpoint LatLonPoint latlon = gcs.getLatLon(xy[0], xy[1]); Point p = new Point(); p.lat = latlon.getLatitude(); p.lon = latlon.getLongitude(); p.dataValue = data.getDouble( data.getIndex()); return p; }
public Point readData(GridDatatype grid, CalendarDate date, double lat, double lon) throws java.io.IOException { GridCoordSystem gcs = grid.getCoordinateSystem(); //CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); //int tidx = timeAxis.findTimeIndexFromCalendarDate(date); int tidx =-1; //Date may be null if the grid does not have time axis if(date != null) tidx = findTimeIndexForCalendarDate(gcs, date); //int[] xy = gcs.findXYindexFromLatLonBounded(lat, lon, null); int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); Array data = grid.readDataSlice(tidx, -1, xy[1], xy[0]); // use actual grid midpoint LatLonPoint latlon = gcs.getLatLon(xy[0], xy[1]); Point p = new Point(); p.lat = latlon.getLatitude(); p.lon = latlon.getLongitude(); p.dataValue = data.getDouble( data.getIndex()); return p; }
public Point readData(GridDatatype grid, CalendarDate date, double zCoord, double lat, double lon) throws java.io.IOException { GridCoordSystem gcs = grid.getCoordinateSystem(); //CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); //int tidx = timeAxis.findTimeIndexFromCalendarDate(date); int tidx = -1; //Date may be null if the grid does not have time axis if(date != null) tidx= findTimeIndexForCalendarDate(gcs, date); CoordinateAxis1D zAxis = gcs.getVerticalAxis(); int zidx = zAxis.findCoordElement( zCoord); int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); Array data = grid.readDataSlice(tidx, zidx, xy[1], xy[0]); // use actual grid midpoint LatLonPoint latlon = gcs.getLatLon(xy[0], xy[1]); Point p = new Point(); p.lat = latlon.getLatitude(); p.lon = latlon.getLongitude(); p.z = zAxis.getCoordValue( zidx); p.dataValue = data.getDouble( data.getIndex()); return p; }
public Point readData(GridDatatype grid, CalendarDate date, double zCoord, double lat, double lon) throws java.io.IOException { GridCoordSystem gcs = grid.getCoordinateSystem(); //CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); //int tidx = timeAxis.findTimeIndexFromCalendarDate(date); int tidx = -1; //Date may be null if the grid does not have time axis if(date != null) tidx= findTimeIndexForCalendarDate(gcs, date); CoordinateAxis1D zAxis = gcs.getVerticalAxis(); int zidx = zAxis.findCoordElement( zCoord); int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); Array data = grid.readDataSlice(tidx, zidx, xy[1], xy[0]); // use actual grid midpoint LatLonPoint latlon = gcs.getLatLon(xy[0], xy[1]); Point p = new Point(); p.lat = latlon.getLatitude(); p.lon = latlon.getLongitude(); p.z = zAxis.getCoordValue( zidx); p.dataValue = data.getDouble( data.getIndex()); return p; }
public Point readData(GridDatatype grid, CalendarDate date, double zCoord, double lat, double lon) throws java.io.IOException { GridCoordSystem gcs = grid.getCoordinateSystem(); //CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); //int tidx = timeAxis.findTimeIndexFromCalendarDate(date); int tidx = -1; //Date may be null if the grid does not have time axis if(date != null) tidx= findTimeIndexForCalendarDate(gcs, date); CoordinateAxis1D zAxis = gcs.getVerticalAxis(); int zidx = zAxis.findCoordElement( zCoord); int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); Array data = grid.readDataSlice(tidx, zidx, xy[1], xy[0]); // use actual grid midpoint LatLonPoint latlon = gcs.getLatLon(xy[0], xy[1]); Point p = new Point(); p.lat = latlon.getLatitude(); p.lon = latlon.getLongitude(); p.z = zAxis.getCoordValue( zidx); p.dataValue = data.getDouble( data.getIndex()); return p; }
int[] xy = gcs.findXYindexFromLatLon(p.getLatitude(), p.getLongitude(), null); System.out.println("index= (" + xy[0] + ", " + xy[1] + ")"); Assert.assertEquals(xy[0], 1); xy = gcs2.findXYindexFromLatLon(p.getLatitude(), p.getLongitude(), null); System.out.println("index= (" + xy[0] + ", " + xy[1] + ")"); Assert.assertEquals(xy[0], 1);
int[] xy = gcs.findXYindexFromLatLon(lat, lon, null);
int[] xy = gcs.findXYindexFromLatLon(lat, lon, null);
int[] xy = gcs.findXYindexFromLatLon(lat, lon, null);